Migration.php
1 year ago
Migration_10.php
2 years ago
Migration_11.php
2 years ago
Migration_12.php
1 year ago
Migration_13.php
2 years ago
Migration_14.php
2 years ago
Migration_15.php
2 years ago
Migration_16.php
2 years ago
Migration_17.php
1 year ago
Migration_18.php
2 years ago
Migration_19.php
2 years ago
Migration_1_0.php
2 years ago
Migration_1_6.php
2 years ago
Migration_1_8.php
2 years ago
Migration_1_9.php
2 years ago
Migration_2.php
2 years ago
Migration_20.php
2 years ago
Migration_21.php
2 years ago
Migration_22.php
2 years ago
Migration_23.php
2 years ago
Migration_24.php
2 years ago
Migration_25.php
2 years ago
Migration_26.php
2 years ago
Migration_27.php
2 years ago
Migration_28.php
2 years ago
Migration_29.php
2 years ago
Migration_3.php
2 years ago
Migration_30.php
2 years ago
Migration_31.php
2 years ago
Migration_32.php
2 years ago
Migration_33.php
2 years ago
Migration_34.php
1 year ago
Migration_35.php
1 year ago
Migration_36.php
1 year ago
Migration_4.php
2 years ago
Migration_5.php
2 years ago
Migration_6.php
2 years ago
Migration_7.php
1 year ago
Migration_8.php
2 years ago
Migration_9.php
2 years ago
Migration_Job.php
2 years ago
Migrations.php
1 year ago
Step_Migration.php
1 year ago
Step_Migration.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Migrations; |
| 4 | |
| 5 | use IAWP\Query; |
| 6 | /** @internal */ |
| 7 | abstract class Step_Migration |
| 8 | { |
| 9 | protected abstract function database_version() : int; |
| 10 | protected abstract function queries() : array; |
| 11 | public function migrate() : bool |
| 12 | { |
| 13 | $current_db_version = \get_option('iawp_db_version', '0'); |
| 14 | if (\version_compare($current_db_version, \strval($this->database_version()), '>=')) { |
| 15 | return \true; |
| 16 | } |
| 17 | $completed = $this->run_queries(); |
| 18 | if ($completed) { |
| 19 | \update_option('iawp_db_version', $this->database_version(), \true); |
| 20 | } |
| 21 | return $completed; |
| 22 | } |
| 23 | protected function drop_table_if_exists(string $table_name) : string |
| 24 | { |
| 25 | return "\n DROP TABLE IF EXISTS {$table_name};\n "; |
| 26 | } |
| 27 | private function run_queries() : bool |
| 28 | { |
| 29 | global $wpdb; |
| 30 | $queries = $this->queries(); |
| 31 | foreach ($queries as $index => $query) { |
| 32 | // Skip the step if there is no query to run |
| 33 | if (\is_null($query)) { |
| 34 | \update_option('iawp_last_finished_migration_step', $index + 1, \true); |
| 35 | continue; |
| 36 | } |
| 37 | $wpdb->query($query); |
| 38 | if ($wpdb->last_error !== '') { |
| 39 | \update_option('iawp_migration_error_original_error_message', \trim($wpdb->last_error), \true); |
| 40 | $is_connected = $wpdb->check_connection(\false); |
| 41 | if (!$is_connected) { |
| 42 | \IAWPSCOPED\iawp_log('Independent Analytics: Your database connection was temporarily lost'); |
| 43 | return \false; |
| 44 | } |
| 45 | $wpdb->query($query); |
| 46 | if ($wpdb->last_error !== '') { |
| 47 | $last_error = \trim($wpdb->last_error); |
| 48 | $last_query = \trim($wpdb->last_query); |
| 49 | // Must call update_option after store the last_error and last_query |
| 50 | \update_option('iawp_migration_error', $last_error, \true); |
| 51 | \update_option('iawp_migration_error_query', $last_query, \true); |
| 52 | return \false; |
| 53 | } |
| 54 | } |
| 55 | \update_option('iawp_last_finished_migration_step', $index + 1, \true); |
| 56 | } |
| 57 | return \true; |
| 58 | } |
| 59 | } |
| 60 |