diff --git a/code/Task/UserFormsColumnCleanTask.php b/code/Task/UserFormsColumnCleanTask.php
index 5c284065..ec1c074e 100644
--- a/code/Task/UserFormsColumnCleanTask.php
+++ b/code/Task/UserFormsColumnCleanTask.php
@@ -38,32 +38,32 @@ protected function execute(InputInterface $input, PolyOutput $output): int
$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
");
- $output->writeln("Creating Backup_$db
");
+ $backedUp = false;
+ foreach ($liveColumns as $column) {
+ if (!$backedUp) {
+ $output->writeln("Backing up $table
");
+ $output->writeln("Creating Backup_$table
");
// backup table
- $query = "CREATE TABLE Backup_$db LIKE $db";
+ $query = "CREATE TABLE Backup_$table LIKE $table";
DB::query($query);
- $output->writeln("Populating Backup_$db
");
- $query = "INSERT Backup_$db SELECT * FROM $db";
+ $output->writeln("Populating Backup_$table
");
+ $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
");
- $query = "ALTER TABLE $db DROP COLUMN $column";
+ $output->writeln("Dropping $column from $table
");
+ $query = "ALTER TABLE $table DROP COLUMN $column";
DB::query($query);
}
}