Compare commits

...

4 Commits

Author SHA1 Message Date
Steve Boyd
a8df472903 Merge branch '6' into 7 2024-10-22 16:48:00 +13:00
github-actions
69548a5c12 Merge branch '6.3' into 6 2024-10-16 08:44:24 +00:00
github-actions
5b71b31040 Merge branch '6.2' into 6.3 2024-10-16 08:44:23 +00:00
Guy Sartorelli
fadfec264b
FIX Ensure UserFormsColumnCleanTask runs safely (#1335) 2024-10-15 14:54:37 +13:00

View File

@ -38,32 +38,32 @@ class UserFormsColumnCleanTask extends BuildTask
$schema = DataObject::getSchema();
foreach ($this->tables as $db) {
$table = $schema->tableName($db);
$columns = $schema->databaseFields($db);
$query = "SHOW COLUMNS FROM $db";
$query = "SHOW COLUMNS FROM $table";
$liveColumns = DB::query($query)->column();
$backedUp = 0;
$query = "SHOW TABLES LIKE 'Backup_$db'";
$query = "SHOW TABLES LIKE 'Backup_$table'";
$tableExists = DB::query($query)->value();
if ($tableExists != null) {
$output->writeln("Tasks run already on $db exiting");
$output->writeln("Tasks run already on $table exiting");
return Command::SUCCESS;
}
$backedUp = 0;
foreach ($liveColumns as $index => $column) {
if ($backedUp == 0) {
$output->writeln("Backing up $db <br />");
$output->writeln("Creating Backup_$db <br />");
$backedUp = false;
foreach ($liveColumns as $column) {
if (!$backedUp) {
$output->writeln("Backing up $table <br />");
$output->writeln("Creating Backup_$table <br />");
// backup table
$query = "CREATE TABLE Backup_$db LIKE $db";
$query = "CREATE TABLE Backup_$table LIKE $table";
DB::query($query);
$output->writeln("Populating Backup_$db <br />");
$query = "INSERT Backup_$db SELECT * FROM $db";
$output->writeln("Populating Backup_$table <br />");
$query = "INSERT Backup_$table SELECT * FROM $table";
DB::query($query);
$backedUp = 1;
$backedUp = true;
}
if (!isset($columns[$column]) && !in_array($column, $this->keepColumns ?? [])) {
$output->writeln("Dropping $column from $db <br />");
$query = "ALTER TABLE $db DROP COLUMN $column";
$output->writeln("Dropping $column from $table <br />");
$query = "ALTER TABLE $table DROP COLUMN $column";
DB::query($query);
}
}