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 (Install::isFresh()) { Option::saveOptionGroup('migrated', true, 'db'); Option::saveOptionGroup('manual_migration_tasks', [], 'db'); Option::saveOptionGroup('auto_migration_tasks', [], 'db'); Option::saveOptionGroup('version', WP_STATISTICS_VERSION, 'db'); Option::saveOptionGroup('is_done', true, 'ajax_background_process'); return; } Option::saveOptionGroup('migrated', false, 'db'); Option::saveOptionGroup('migration_status_detail', null, 'db'); Option::saveOptionGroup('is_done', null, 'ajax_background_process'); Option::saveOptionGroup('status', null, 'ajax_background_process'); $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); } } } }