PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.4
JetFormBuilder — Dynamic Blocks Form Builder v3.6.4
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 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / migrations / migrator.php
migrator.php
131 lines 2.9 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
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