PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.7.1
Independent Analytics – WordPress Analytics Plugin v2.7.1
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / IAWP / Migrations / Step_Migration.php
Step_Migration.php
60 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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