Creates_Reports.php
1 year ago
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
1 year 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_37.php
1 year ago
Migration_38.php
1 year ago
Migration_39.php
1 year ago
Migration_4.php
2 years ago
Migration_40.php
1 year ago
Migration_41.php
1 year ago
Migration_42.php
1 year ago
Migration_43.php
1 year 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
1 year ago
Migrations.php
1 year ago
Step_Migration.php
1 year ago
Step_Migration.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Migrations; |
| 4 | |
| 5 | use IAWP\Database; |
| 6 | use IAWP\Query; |
| 7 | use IAWP\Tables; |
| 8 | /** @internal */ |
| 9 | abstract class Step_Migration |
| 10 | { |
| 11 | protected $tables = Tables::class; |
| 12 | protected abstract function database_version() : int; |
| 13 | protected abstract function queries() : array; |
| 14 | public function migrate() : bool |
| 15 | { |
| 16 | $current_db_version = \get_option('iawp_db_version', '0'); |
| 17 | if (\version_compare($current_db_version, \strval($this->database_version()), '>=')) { |
| 18 | return \true; |
| 19 | } |
| 20 | \update_option('iawp_migration_started_at', \time(), \true); |
| 21 | try { |
| 22 | $completed = $this->run_queries(); |
| 23 | } catch (\Throwable $error) { |
| 24 | $completed = \false; |
| 25 | \update_option('iawp_migration_error_original_error_message', 'Unable to generate migration queries: ' . $error->getMessage(), \true); |
| 26 | \update_option('iawp_migration_error', 'Unable to generate migration queries.', \true); |
| 27 | \update_option('iawp_migration_error_query', $error->getMessage(), \true); |
| 28 | } |
| 29 | if ($completed) { |
| 30 | \update_option('iawp_db_version', $this->database_version(), \true); |
| 31 | \delete_option('iawp_migration_auto_fixed'); |
| 32 | } |
| 33 | return $completed; |
| 34 | } |
| 35 | public function character_set() : string |
| 36 | { |
| 37 | return Database::character_set(); |
| 38 | } |
| 39 | public function collation() : string |
| 40 | { |
| 41 | return Database::collation(); |
| 42 | } |
| 43 | protected function drop_table_if_exists(string $table_name) : string |
| 44 | { |
| 45 | return "\n DROP TABLE IF EXISTS {$table_name};\n "; |
| 46 | } |
| 47 | private function run_queries() : bool |
| 48 | { |
| 49 | global $wpdb; |
| 50 | $queries = $this->queries(); |
| 51 | foreach ($queries as $index => $query) { |
| 52 | // Skip the step if there is no query to run |
| 53 | if (\is_null($query)) { |
| 54 | \update_option('iawp_last_finished_migration_step', $index + 1, \true); |
| 55 | continue; |
| 56 | } |
| 57 | $initial_response = $wpdb->query($query); |
| 58 | if ($initial_response === \false) { |
| 59 | \sleep(1); |
| 60 | \update_option('iawp_migration_error_original_error_message', \trim($wpdb->last_error), \true); |
| 61 | $is_connected = $wpdb->check_connection(\false); |
| 62 | if (!$is_connected) { |
| 63 | // There is no database connection at this point, so options cannot be updated |
| 64 | return \false; |
| 65 | } |
| 66 | $retry_response = $wpdb->query($query); |
| 67 | if ($retry_response === \false) { |
| 68 | // You cannot take these variable values and inline them below. The calls to |
| 69 | // update_option use $wpdb, so last_error and last_query will be altered |
| 70 | $last_error = \trim($wpdb->last_error); |
| 71 | $last_query = \trim($wpdb->last_query); |
| 72 | \update_option('iawp_migration_error', $last_error, \true); |
| 73 | \update_option('iawp_migration_error_query', $last_query, \true); |
| 74 | return \false; |
| 75 | } |
| 76 | } |
| 77 | \update_option('iawp_last_finished_migration_step', $index + 1, \true); |
| 78 | } |
| 79 | return \true; |
| 80 | } |
| 81 | } |
| 82 |