mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
Compare commits
No commits in common. "a8df472903ca59d5493f8e1b0c090fd35628a78c" and "574ca14ee7f511f85db356406c5c56d20c9ea34d" have entirely different histories.
a8df472903
...
574ca14ee7
@ -38,32 +38,32 @@ class UserFormsColumnCleanTask extends BuildTask
|
|||||||
$schema = DataObject::getSchema();
|
$schema = DataObject::getSchema();
|
||||||
|
|
||||||
foreach ($this->tables as $db) {
|
foreach ($this->tables as $db) {
|
||||||
$table = $schema->tableName($db);
|
|
||||||
$columns = $schema->databaseFields($db);
|
$columns = $schema->databaseFields($db);
|
||||||
$query = "SHOW COLUMNS FROM $table";
|
$query = "SHOW COLUMNS FROM $db";
|
||||||
$liveColumns = DB::query($query)->column();
|
$liveColumns = DB::query($query)->column();
|
||||||
$query = "SHOW TABLES LIKE 'Backup_$table'";
|
$backedUp = 0;
|
||||||
|
$query = "SHOW TABLES LIKE 'Backup_$db'";
|
||||||
$tableExists = DB::query($query)->value();
|
$tableExists = DB::query($query)->value();
|
||||||
if ($tableExists != null) {
|
if ($tableExists != null) {
|
||||||
$output->writeln("Tasks run already on $table exiting");
|
$output->writeln("Tasks run already on $db exiting");
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
$backedUp = false;
|
$backedUp = 0;
|
||||||
foreach ($liveColumns as $column) {
|
foreach ($liveColumns as $index => $column) {
|
||||||
if (!$backedUp) {
|
if ($backedUp == 0) {
|
||||||
$output->writeln("Backing up $table <br />");
|
$output->writeln("Backing up $db <br />");
|
||||||
$output->writeln("Creating Backup_$table <br />");
|
$output->writeln("Creating Backup_$db <br />");
|
||||||
// backup table
|
// backup table
|
||||||
$query = "CREATE TABLE Backup_$table LIKE $table";
|
$query = "CREATE TABLE Backup_$db LIKE $db";
|
||||||
DB::query($query);
|
DB::query($query);
|
||||||
$output->writeln("Populating Backup_$table <br />");
|
$output->writeln("Populating Backup_$db <br />");
|
||||||
$query = "INSERT Backup_$table SELECT * FROM $table";
|
$query = "INSERT Backup_$db SELECT * FROM $db";
|
||||||
DB::query($query);
|
DB::query($query);
|
||||||
$backedUp = true;
|
$backedUp = 1;
|
||||||
}
|
}
|
||||||
if (!isset($columns[$column]) && !in_array($column, $this->keepColumns ?? [])) {
|
if (!isset($columns[$column]) && !in_array($column, $this->keepColumns ?? [])) {
|
||||||
$output->writeln("Dropping $column from $table <br />");
|
$output->writeln("Dropping $column from $db <br />");
|
||||||
$query = "ALTER TABLE $table DROP COLUMN $column";
|
$query = "ALTER TABLE $db DROP COLUMN $column";
|
||||||
DB::query($query);
|
DB::query($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user