Drop foreign key before trying to drop the accounts table

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-07-11 12:11:07 +02:00
parent 13e0a95063
commit 0d4ca0e754
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 22 additions and 2 deletions

View File

@ -44,6 +44,8 @@ class SaveAccountsTableData implements IRepairStep {
/** @var IConfig */
protected $config;
protected $hasForeignKeyOnPersistentLocks = false;
/**
* @param IDBConnection $db
* @param IConfig $config
@ -77,6 +79,9 @@ class SaveAccountsTableData implements IRepairStep {
}
// Remove the table
if ($this->hasForeignKeyOnPersistentLocks) {
$this->db->dropTable('persistent_locks');
}
$this->db->dropTable('accounts');
}
@ -85,14 +90,29 @@ class SaveAccountsTableData implements IRepairStep {
*/
protected function shouldRun() {
$schema = $this->db->createSchema();
$prefix = $this->config->getSystemValue('dbtableprefix', 'oc_');
$tableName = $this->config->getSystemValue('dbtableprefix', 'oc_') . 'accounts';
$tableName = $prefix . 'accounts';
if (!$schema->hasTable($tableName)) {
return false;
}
$table = $schema->getTable($tableName);
return $table->hasColumn('user_id');
if (!$table->hasColumn('user_id')) {
return false;
}
if ($schema->hasTable($prefix . 'persistent_locks')) {
$locksTable = $schema->getTable($prefix . 'persistent_locks');
$foreignKeys = $locksTable->getForeignKeys();
foreach ($foreignKeys as $foreignKey) {
if ($tableName === $foreignKey->getForeignTableName()) {
$this->hasForeignKeyOnPersistentLocks = true;
}
}
}
return true;
}
/**