Compare commits

..

No commits in common. "69548a5c12ec499db230b3ce2038691b6e2ade32" and "7466999d84b98a22c7fff37e47ca56df60f823e5" have entirely different histories.

View File

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