/** @var IConfig */
protected $config;
+ protected $hasForeignKeyOnPersistentLocks = false;
+
/**
* @param IDBConnection $db
* @param IConfig $config
}
// Remove the table
+ if ($this->hasForeignKeyOnPersistentLocks) {
+ $this->db->dropTable('persistent_locks');
+ }
$this->db->dropTable('accounts');
}
*/
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;
}
/**