Merge pull request #6442 from nextcloud/backport-6416-make-sure-sqlite-works-without-content

[stable12] Ask the schema whether the table and column exist
This commit is contained in:
Morris Jobke 2017-09-11 23:20:58 +02:00 committed by GitHub
commit 0c43183ac9
1 changed files with 12 additions and 14 deletions

View File

@ -23,8 +23,8 @@
namespace OC\Repair\Owncloud; namespace OC\Repair\Owncloud;
use Doctrine\DBAL\Exception\InvalidFieldNameException; use OC\DB\Connection;
use Doctrine\DBAL\Exception\TableNotFoundException; use OC\DB\MDB2SchemaManager;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -40,7 +40,7 @@ class SaveAccountsTableData implements IRepairStep {
const BATCH_SIZE = 75; const BATCH_SIZE = 75;
/** @var IDBConnection */ /** @var IDBConnection|Connection */
protected $db; protected $db;
/** @var IConfig */ /** @var IConfig */
@ -86,20 +86,18 @@ class SaveAccountsTableData implements IRepairStep {
* @return bool * @return bool
*/ */
protected function shouldRun() { protected function shouldRun() {
$query = $this->db->getQueryBuilder(); // This is the equivalent of the new migration code that is used in 13+
$query->select('*') $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
->from('accounts') $this->db->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
->where($query->expr()->isNotNull('user_id')) $schema = $this->db->getSchemaManager()->createSchema();
->setMaxResults(1);
try { $tableName = $this->config->getSystemValue('dbtableprefix', 'oc_') . 'accounts';
$query->execute(); if (!$schema->hasTable($tableName)) {
return true;
} catch (InvalidFieldNameException $e) {
return false;
} catch (TableNotFoundException $e) {
return false; return false;
} }
$table = $schema->getTable($tableName);
return $table->hasColumn('user_id');
} }
/** /**