setName($tableName) ->execute(); if (!$inspect->getResult()) { $schema = Manager::getSchemaForTable($tableName); DatabaseFactory::table('create') ->setName($tableName) ->setArgs($schema) ->execute(); } } catch (\Exception $e) { throw new \RuntimeException("Failed to inspect or create table `$tableName`: " . $e->getMessage(), 0, $e); } } Option::saveOptionGroup('check', false, 'db'); if (CoreFactory::isFresh()) { Option::saveOptionGroup('migrated', true, 'db'); Option::saveOptionGroup('version', WP_STATISTICS_VERSION, 'db'); return; } Option::saveOptionGroup('migrated', false, 'db'); Option::saveOptionGroup('migration_status_detail', null, 'db'); Option::saveOptionGroup('completed', false, 'queue_background_process'); Option::saveOptionGroup('status', null, 'queue_background_process'); $ajaxMigrationOption = Option::getOptionGroup('ajax_background_process', 'jobs', []); $ajaxIsDone = Option::getOptionGroup('ajax_background_process', 'is_done', false); if ($ajaxIsDone || in_array('visitor_columns_migrate', $ajaxMigrationOption, true)) { Option::saveOptionGroup('visitor_columns_migrator_initiated', true, 'jobs'); } $dismissedNotices = get_option('wp_statistics_dismissed_notices', []); if (in_array('database_manual_migration_progress', $dismissedNotices, true)) { $dismissedNotices = array_diff($dismissedNotices, ['database_manual_migration_progress']); update_option('wp_statistics_dismissed_notices', $dismissedNotices); } } /** * Create a single table. * * @param string $tableName The name of the table to create. * @param array $schema The schema for the table. * @return void * @throws \RuntimeException If the table creation fails. */ public static function createTable(string $tableName, array $schema) { try { $createOperation = DatabaseFactory::table('create'); $createOperation ->setName($tableName) ->setArgs($schema) ->execute(); } catch (\Exception $e) { throw new \RuntimeException("Failed to create table `$tableName`: " . $e->getMessage(), 0, $e); } } /** * Drop a single table. * * @param string $tableName The name of the table to drop. * @return void * @throws \RuntimeException If the table drop operation fails. */ public static function dropTable(string $tableName) { try { DatabaseFactory::table('drop') ->setName($tableName) ->execute(); } catch (\Exception $e) { throw new \RuntimeException("Failed to drop table `$tableName`: " . $e->getMessage(), 0, $e); } } /** * Drop all known tables. * * @return void * @throws \RuntimeException If any table drop operation fails. */ public static function dropAllTables() { $tableNames = Manager::getAllTableNames(); foreach ($tableNames as $tableName) { try { self::dropTable($tableName); } catch (\Exception $e) { throw new \RuntimeException("Failed to drop table `$tableName`: " . $e->getMessage(), 0, $e); } } } }