]> source.dussan.org Git - nextcloud-server.git/commitdiff
Drop foreign key before trying to drop the accounts table 16361/head
authorJoas Schilling <coding@schilljs.com>
Thu, 11 Jul 2019 10:11:07 +0000 (12:11 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 11 Jul 2019 10:14:25 +0000 (12:14 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Repair/Owncloud/SaveAccountsTableData.php

index c9e67356fb9c50d1d30677e58db4683ff991e32c..f62f8b56b2638df304d827de0e9fc85e8353bc09 100644 (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;
        }
 
        /**