PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.4
JetFormBuilder — Dynamic Blocks Form Builder v2.1.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 / versions / base-migration.php
jetformbuilder / includes / migrations / versions Last commit date
base-migration.php 3 years ago version-2-1-0.php 3 years ago
base-migration.php
144 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Migrations\Versions;
5
6 use Jet_Form_Builder\Classes\Repository\Repository_Item_With_Class;
7 use Jet_Form_Builder\Classes\Repository\Repository_Static_Item_It;
8 use Jet_Form_Builder\Db_Queries\Exceptions\Sql_Exception;
9 use Jet_Form_Builder\Migrations\Migration_Exception;
10 use Jet_Form_Builder\Migrations\Migration_Model;
11 use Jet_Form_Builder\Migrations\Migrator;
12 use Jet_Form_Builder\Migrations\Profilers\Base_Migration_Profiler;
13
14 abstract class Base_Migration implements Repository_Static_Item_It {
15
16 use Repository_Item_With_Class;
17
18 /** @var Base_Migration_Profiler */
19 private $profiler;
20
21 abstract public function up( \wpdb $wpdb );
22
23 abstract public function down( \wpdb $wpdb );
24
25 public function __construct( Base_Migration_Profiler $profiler = null ) {
26 $this->set_profiler( $profiler );
27 }
28
29 /**
30 * @throws Migration_Exception
31 */
32 final public function install() {
33 if ( $this->is_installed() ) {
34 return;
35 }
36 $this->run_up();
37 $this->set_installed();
38 }
39
40 /**
41 * @throws Migration_Exception
42 */
43 final public function uninstall() {
44 if ( ! $this->is_installed() ) {
45 return;
46 }
47 $this->run_down();
48 $this->set_uninstalled();
49 }
50
51 final public function install_automatic() {
52 if ( $this->is_installed() ) {
53 return;
54 }
55
56 $this->save( 0 );
57 $this->set_installed();
58 }
59
60 /**
61 * @throws Migration_Exception
62 */
63 final protected function run_up() {
64 global $wpdb;
65
66 timer_start();
67 $this->up( $wpdb );
68
69 $timer_stop = timer_stop();
70 $time = $timer_stop * 1000;
71
72 $this->profiler->on_up_end( $this, $timer_stop );
73
74 if ( $wpdb->last_error ) {
75 throw new Migration_Exception( $wpdb->last_error );
76 }
77
78 $this->save( $time );
79 }
80
81 /**
82 * @throws Migration_Exception
83 */
84 final public function run_down() {
85 global $wpdb;
86
87 timer_start();
88 $this->down( $wpdb );
89 $timer_stop = timer_stop();
90
91 $this->profiler->on_down_end( $this, $timer_stop );
92
93 if ( $wpdb->last_error ) {
94 throw new Migration_Exception( $wpdb->last_error );
95 }
96
97 try {
98 $this->delete();
99 } catch ( Sql_Exception $exception ) {
100 throw new Migration_Exception( $exception->getMessage() );
101 }
102 }
103
104 public function save( int $time ) {
105 ( new Migration_Model() )->insert_soft(
106 array(
107 'version' => get_class( $this ),
108 'execution_time' => $time,
109 'executed_at' => current_time( 'mysql' ),
110 )
111 );
112 }
113
114 /**
115 * @throws Sql_Exception
116 */
117 public function delete() {
118 ( new Migration_Model() )->delete(
119 array(
120 'version' => get_class( $this ),
121 )
122 );
123 }
124
125 final public function set_installed() {
126 Migrator::instance()->set_installed( $this );
127 }
128
129 final public function set_uninstalled() {
130 Migrator::instance()->set_uninstalled( $this );
131 }
132
133 final public function is_installed(): bool {
134 return Migrator::instance()->is_installed( $this );
135 }
136
137 public function set_profiler( Base_Migration_Profiler $profiler = null ): Base_Migration {
138 $this->profiler = $profiler ?? new Base_Migration_Profiler();
139
140 return $this;
141 }
142
143 }
144