| @@ -31,8 +31,17 @@ | ||
| 31 | 31 | private static $updates = [ |
| 32 | 32 | '1.0.0' => [ |
| 33 | 33 | 'check_database_tables', |
| 34 | 34 | ], |
| 35 | + '1.2.1' => [ | |
| 36 | + 'add_ip_column_to_contact_segmentation', | |
| 37 | + ], | |
| 38 | + '1.2.3' => [ // @since 1.2.3 | |
| 39 | + 'add_url_query_string_column_to_contact_segmentation', | |
| 40 | + ], | |
| 41 | + '1.2.7' => [ // @since 1.5.0 | |
| 42 | + 'add_funnel_contact_table', | |
| 43 | + ], | |
| 35 | 44 | ]; |
| 36 | 45 | |
| 37 | 46 | /** |
| 38 | 47 | * Install constructor. |
| @@ -43,10 +52,8 @@ | ||
| 43 | 52 | sellkit()->load_files( [ |
| 44 | 53 | 'core/admin/feedback', |
| 45 | 54 | ] ); |
| 46 | 55 | |
| 47 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] ); | |
| 48 | - | |
| 49 | 56 | $current_version = $this->get_current_database_version(); |
| 50 | 57 | $last_version = array_key_last( self::$updates ); |
| 51 | 58 | |
| 52 | 59 | if ( $current_version === $last_version ) { |
| @@ -69,10 +76,16 @@ | ||
| 69 | 76 | public function maybe_update() { |
| 70 | 77 | $current_db_version = $this->get_current_database_version(); |
| 71 | 78 | $current_db_version = ! empty( $current_db_version ) ? $current_db_version : 0; |
| 72 | 79 | self::$updater = new Db_Updater(); |
| 73 | - $has_new_update = false; | |
| 74 | 80 | |
| 81 | + // Avoid stacking duplicate batches (e.g. admin refreshes) or colliding with an in-flight run. | |
| 82 | + if ( self::$updater->has_pending_migrations() ) { | |
| 83 | + return; | |
| 84 | + } | |
| 85 | + | |
| 86 | + $has_new_update = false; | |
| 87 | + | |
| 75 | 88 | foreach ( self::$updates as $version => $update_callbacks ) { |
| 76 | 89 | if ( version_compare( $current_db_version, $version, '<' ) ) { |
| 77 | 90 | foreach ( $update_callbacks as $update_callback ) { |
| 78 | 91 | self::$updater->push_to_queue( [ |
| @@ -85,8 +98,9 @@ | ||
| 85 | 98 | } |
| 86 | 99 | } |
| 87 | 100 | |
| 88 | 101 | if ( $has_new_update ) { |
| 102 | + self::$updater->gate_multisite_initial_loopback = true; | |
| 89 | 103 | self::$updater->save()->dispatch(); |
| 90 | 104 | } |
| 91 | 105 | } |
| 92 | 106 | |
| @@ -118,9 +132,9 @@ | ||
| 118 | 132 | $sellkit_prefix = Database::DATABASE_PREFIX; |
| 119 | 133 | |
| 120 | 134 | // phpcs:disable |
| 121 | 135 | $installed_tables = $wpdb->get_results( |
| 122 | - "SHOW TABLES from {$database_name} | |
| 136 | + "SHOW TABLES from `{$database_name}` | |
| 123 | 137 | where Tables_in_{$database_name} like '%applied_funnel%' |
| 124 | 138 | or Tables_in_{$database_name} like '%contact_segmentation%' |
| 125 | 139 | " ); |
| 126 | 140 | // phpcs:enable |
| @@ -157,40 +171,8 @@ | ||
| 157 | 171 | |
| 158 | 172 | if ( ! empty( $not_installed_tables ) ) { |
| 159 | 173 | self::create_necessary_tables( $not_installed_tables ); |
| 160 | 174 | } |
| 161 | - } | |
| 162 | - | |
| 163 | - /** | |
| 164 | - * Enqueues admin scripts. | |
| 165 | - * | |
| 166 | - * @since 1.1.0 | |
| 167 | - */ | |
| 168 | - public function enqueue_admin_scripts() { | |
| 169 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 170 | - | |
| 171 | - wp_enqueue_script( | |
| 172 | - 'sellkit-admin', | |
| 173 | - sellkit()->plugin_url() . 'assets/dist/js/admin' . $suffix . '.js', | |
| 174 | - [ 'lodash', 'wp-element', 'wp-i18n', 'wp-util' ], | |
| 175 | - sellkit()->version(), | |
| 176 | - true | |
| 177 | - ); | |
| 178 | - | |
| 179 | - wp_enqueue_style( | |
| 180 | - 'sellkit-admin', | |
| 181 | - sellkit()->plugin_url() . 'assets/dist/css/admin' . $suffix . '.css', | |
| 182 | - [], | |
| 183 | - sellkit()->version() | |
| 184 | - ); | |
| 185 | - | |
| 186 | - wp_localize_script( | |
| 187 | - 'sellkit-admin', | |
| 188 | - 'sellkitAdmin', | |
| 189 | - [ | |
| 190 | - 'nonce' => wp_create_nonce( 'sellkit_admin' ), | |
| 191 | - ], | |
| 192 | - ); | |
| 193 | 175 | } |
| 194 | 176 | } |
| 195 | 177 | |
| 196 | 178 | new Install(); |