PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.8
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 version-2-1-7.php 3 years ago version-2-1-8.php 3 years ago
base-migration.php
150 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
37 try {
38 $this->run_up();
39 } catch ( Migration_Exception $exception ) {
40 throw $exception->set_version( static::class );
41 }
42
43 $this->set_installed();
44 }
45
46 /**
47 * @throws Migration_Exception
48 */
49 final public function uninstall() {
50 if ( ! $this->is_installed() ) {
51 return;
52 }
53 $this->run_down();
54 $this->set_uninstalled();
55 }
56
57 final public function install_automatic() {
58 if ( $this->is_installed() ) {
59 return;
60 }
61
62 $this->save( 0 );
63 $this->set_installed();
64 }
65
66 /**
67 * @throws Migration_Exception
68 */
69 final protected function run_up() {
70 global $wpdb;
71
72 timer_start();
73 $this->up( $wpdb );
74
75 $timer_stop = timer_stop();
76 $time = $timer_stop * 1000;
77
78 $this->profiler->on_up_end( $this, $timer_stop );
79
80 if ( $wpdb->last_error ) {
81 throw new Migration_Exception( $wpdb->last_error );
82 }
83
84 $this->save( $time );
85 }
86
87 /**
88 * @throws Migration_Exception
89 */
90 final public function run_down() {
91 global $wpdb;
92
93 timer_start();
94 $this->down( $wpdb );
95 $timer_stop = timer_stop();
96
97 $this->profiler->on_down_end( $this, $timer_stop );
98
99 if ( $wpdb->last_error ) {
100 throw new Migration_Exception( $wpdb->last_error );
101 }
102
103 try {
104 $this->delete();
105 } catch ( Sql_Exception $exception ) {
106 throw new Migration_Exception( $exception->getMessage() );
107 }
108 }
109
110 public function save( int $time ) {
111 ( new Migration_Model() )->insert_soft(
112 array(
113 'version' => get_class( $this ),
114 'execution_time' => $time,
115 'executed_at' => current_time( 'mysql' ),
116 )
117 );
118 }
119
120 /**
121 * @throws Sql_Exception
122 */
123 public function delete() {
124 ( new Migration_Model() )->delete(
125 array(
126 'version' => get_class( $this ),
127 )
128 );
129 }
130
131 final public function set_installed() {
132 Migrator::instance()->set_installed( $this );
133 }
134
135 final public function set_uninstalled() {
136 Migrator::instance()->set_uninstalled( $this );
137 }
138
139 final public function is_installed(): bool {
140 return Migrator::instance()->is_installed( $this );
141 }
142
143 public function set_profiler( Base_Migration_Profiler $profiler = null ): Base_Migration {
144 $this->profiler = $profiler ?? new Base_Migration_Profiler();
145
146 return $this;
147 }
148
149 }
150