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