Skip to content

Instantly share code, notes, and snippets.

@av-jok
Forked from ig0r74/change_prefix.php
Created January 12, 2021 02:19
Show Gist options
  • Save av-jok/c0a7ceb05bc46ee6f9f959eff76c31a7 to your computer and use it in GitHub Desktop.
Save av-jok/c0a7ceb05bc46ee6f9f959eff76c31a7 to your computer and use it in GitHub Desktop.
Изменить префикс у таблиц MODX Revolution
<?php
ini_set("max_execution_time", 0);
ignore_user_abort(true);
$current_prefix = $modx->config['table_prefix'];
$new_prefix = 'My_Prefix234_';
$stmt = $modx->query("SHOW TABLES");
$tables = $stmt->fetchAll(PDO::FETCH_NUM);
$stmt->closeCursor();
foreach ($tables as $table) {
$table = reset($table);
$preg = "/^{$current_prefix}/u";
if (preg_match($preg, $table)) {
$new_table_name = preg_replace($preg, $new_prefix, $table);
$sql = "RENAME TABLE `{$table}` TO `{$new_table_name}`";
if ($s = $modx->prepare($sql)) {
$s->execute();
}
}
}
print "\nTables are updated";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment