PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.4
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / includes / migrations / migrator.php

migrator.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.5.4, at includes/migrations/migrator.php

135 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Migrations;
5
6 use Jet_Form_Builder\Classes\Instance_Trait;
7 use Jet_Form_Builder\Migrations\Versions\Version_3_1_7;
8 use Jet_Form_Builder\Migrations\Versions\Version_3_6_1;
9 use JFB_Components\Repository\Repository_Pattern_Trait;
10 use Jet_Form_Builder\Db_Queries\Execution_Builder;
11 use Jet_Form_Builder\Exceptions\Query_Builder_Exception;
12 use Jet_Form_Builder\Migrations\Profilers\Base_Migration_Profiler;
13 use Jet_Form_Builder\Migrations\Versions\Base_Migration;
14 use Jet_Form_Builder\Migrations\Versions\Version_2_1_0;
15 use Jet_Form_Builder\Migrations\Versions\Version_2_1_7;
16 use Jet_Form_Builder\Migrations\Versions\Version_2_1_8;
17 use Jet_Form_Builder\Migrations\Versions\Version_3_6_5_2;
18 use Jet_Form_Builder\Migrations\Versions\Version_3_6_5_3;
19
20 // If this file is called directly, abort.
21 if ( ! defined( 'WPINC' ) ) {
22 die;
23 }
24
25 /**
26 * @method static Migrator instance()
27 *
28 * Class Migrator
29 * @package Jet_Form_Builder\Migrations
30 */
31 class Migrator {
32
33 use Instance_Trait;
34 use Repository_Pattern_Trait;
35
36 private $installed_migrations = array();
37
38 public function __construct() {
39 $this->rep_install();
40 }
41
42 /**
43 * @return array
44 */
45 public function rep_instances(): array {
46 return array(
47 new Version_2_1_0(),
48 new Version_2_1_7(),
49 new Version_2_1_8(),
50 new Version_3_1_7(),
51 new Version_3_6_1(),
52 new Version_3_6_5_2(),
53 new Version_3_6_5_3(),
54 );
55 }
56
57 /**
58 * @param null|Base_Migration_Profiler $profiler
59 *
60 * @throws Migration_Exception
61 */
62 public function install( $profiler = null ) {
63 /** @var Base_Migration $migration */
64 foreach ( $this->rep_get_items() as $migration ) {
65 $migration->set_profiler( $profiler )->install();
66 }
67 }
68
69 /**
70 * @param null|Base_Migration_Profiler $profiler
71 *
72 * @throws Migration_Exception
73 */
74 public function uninstall( $profiler = null ) {
75 /** @var Base_Migration $migration */
76 foreach ( $this->rep_get_items() as $migration ) {
77 $migration->set_profiler( $profiler )->uninstall();
78 }
79 }
80
81 public function is_installed_all(): bool {
82 $items = $this->rep_get_items();
83
84 /** @var Base_Migration $item */
85 foreach ( $items as $item ) {
86 if ( ! $item->is_installed() ) {
87 return false;
88 }
89 }
90
91 return true;
92 }
93
94 public function is_installed( Base_Migration $migration ): bool {
95 $version = get_class( $migration );
96
97 if ( isset( $this->installed_migrations[ $version ] ) ) {
98 return $this->installed_migrations[ $version ];
99 }
100
101 $installed = true;
102
103 try {
104 View_Migrations::findOne(
105 array(
106 'version' => $version,
107 )
108 )->query()->query_one();
109 } catch ( Query_Builder_Exception $exception ) {
110 $exception->unset_log();
111 $installed = false;
112 }
113
114 $this->installed_migrations[ $version ] = $installed;
115
116 return $this->installed_migrations[ $version ];
117 }
118
119 public function set_installed( Base_Migration $migration ): Migrator {
120 $version = get_class( $migration );
121
122 $this->installed_migrations[ $version ] = true;
123
124 return $this;
125 }
126
127 public function set_uninstalled( Base_Migration $migration ): Migrator {
128 $version = get_class( $migration );
129
130 $this->installed_migrations[ $version ] = false;
131
132 return $this;
133 }
134 }
135