PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
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.6, at includes/migrations/migrator.php

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