PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
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 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / migrations / migrator.php
jetformbuilder / includes / migrations Last commit date
profilers 2 years ago versions 1 month ago migration-exception.php 2 years ago migration-model.php 2 years ago migrator.php 1 month ago view-migrations.php 2 years ago
migrator.php
131 lines
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
18 // If this file is called directly, abort.
19 if ( ! defined( 'WPINC' ) ) {
20 die;
21 }
22
23 /**
24 * @method static Migrator instance()
25 *
26 * Class Migrator
27 * @package Jet_Form_Builder\Migrations
28 */
29 class Migrator {
30
31 use Instance_Trait;
32 use Repository_Pattern_Trait;
33
34 private $installed_migrations = array();
35
36 public function __construct() {
37 $this->rep_install();
38 }
39
40 /**
41 * @return array
42 */
43 public function rep_instances(): array {
44 return array(
45 new Version_2_1_0(),
46 new Version_2_1_7(),
47 new Version_2_1_8(),
48 new Version_3_1_7(),
49 new Version_3_6_1(),
50 );
51 }
52
53 /**
54 * @param null|Base_Migration_Profiler $profiler
55 *
56 * @throws Migration_Exception
57 */
58 public function install( $profiler = null ) {
59 /** @var Base_Migration $migration */
60 foreach ( $this->rep_get_items() as $migration ) {
61 $migration->set_profiler( $profiler )->install();
62 }
63 }
64
65 /**
66 * @param null|Base_Migration_Profiler $profiler
67 *
68 * @throws Migration_Exception
69 */
70 public function uninstall( $profiler = null ) {
71 /** @var Base_Migration $migration */
72 foreach ( $this->rep_get_items() as $migration ) {
73 $migration->set_profiler( $profiler )->uninstall();
74 }
75 }
76
77 public function is_installed_all(): bool {
78 $items = $this->rep_get_items();
79
80 /** @var Base_Migration $item */
81 foreach ( $items as $item ) {
82 if ( ! $item->is_installed() ) {
83 return false;
84 }
85 }
86
87 return true;
88 }
89
90 public function is_installed( Base_Migration $migration ): bool {
91 $version = get_class( $migration );
92
93 if ( isset( $this->installed_migrations[ $version ] ) ) {
94 return $this->installed_migrations[ $version ];
95 }
96
97 $installed = true;
98
99 try {
100 View_Migrations::findOne(
101 array(
102 'version' => $version,
103 )
104 )->query()->query_one();
105 } catch ( Query_Builder_Exception $exception ) {
106 $exception->unset_log();
107 $installed = false;
108 }
109
110 $this->installed_migrations[ $version ] = $installed;
111
112 return $this->installed_migrations[ $version ];
113 }
114
115 public function set_installed( Base_Migration $migration ): Migrator {
116 $version = get_class( $migration );
117
118 $this->installed_migrations[ $version ] = true;
119
120 return $this;
121 }
122
123 public function set_uninstalled( Base_Migration $migration ): Migrator {
124 $version = get_class( $migration );
125
126 $this->installed_migrations[ $version ] = false;
127
128 return $this;
129 }
130 }
131