Merge pull request #23882 from nextcloud/tests/oracle

Run unit tests against oracle
This commit is contained in:
Joas Schilling 2020-11-11 10:05:24 +01:00 committed by GitHub
commit e39d657e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 905 additions and 91 deletions

56
.github/workflows/oci.yml vendored Normal file
View File

@ -0,0 +1,56 @@
name: PHPUnit
on:
pull_request:
push:
branches:
- master
- stable*
jobs:
phpunit-oci8:
runs-on: ubuntu-latest
strategy:
# do not stop on another job's failure
fail-fast: false
matrix:
php-versions: [ '7.4' ]
databases: [ 'oci' ]
name: php${{ matrix.php-versions }}-${{ matrix.databases }}
services:
oracle:
image: deepdiver/docker-oracle-xe-11g # "wnameless/oracle-xe-11g-r2"
ports:
- "1521:1521"
steps:
- name: Checkout server
uses: actions/checkout@v2
- name: Checkout submodules
shell: bash
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, oci8
tools: phpunit:8.5.2
coverage: none
- name: Set up Nextcloud
run: |
mkdir data
./occ maintenance:install --verbose --database=oci --database-name=XE --database-host=127.0.0.1 --database-port=1521 --database-user=autotest --database-pass=owncloud --admin-user admin --admin-pass admin
php -f index.php
- name: PHPUnit
working-directory: tests
run: phpunit --configuration phpunit-autotest.xml --group DB,SLOWDB

View File

@ -5,7 +5,7 @@
<name>WebDAV</name> <name>WebDAV</name>
<summary>WebDAV endpoint</summary> <summary>WebDAV endpoint</summary>
<description>WebDAV endpoint</description> <description>WebDAV endpoint</description>
<version>1.17.0</version> <version>1.17.1</version>
<licence>agpl</licence> <licence>agpl</licence>
<author>owncloud.org</author> <author>owncloud.org</author>
<namespace>DAV</namespace> <namespace>DAV</namespace>

View File

@ -230,6 +230,7 @@ return array(
'OCA\\DAV\\Migration\\Version1011Date20190725113607' => $baseDir . '/../lib/Migration/Version1011Date20190725113607.php', 'OCA\\DAV\\Migration\\Version1011Date20190725113607' => $baseDir . '/../lib/Migration/Version1011Date20190725113607.php',
'OCA\\DAV\\Migration\\Version1011Date20190806104428' => $baseDir . '/../lib/Migration/Version1011Date20190806104428.php', 'OCA\\DAV\\Migration\\Version1011Date20190806104428' => $baseDir . '/../lib/Migration/Version1011Date20190806104428.php',
'OCA\\DAV\\Migration\\Version1012Date20190808122342' => $baseDir . '/../lib/Migration/Version1012Date20190808122342.php', 'OCA\\DAV\\Migration\\Version1012Date20190808122342' => $baseDir . '/../lib/Migration/Version1012Date20190808122342.php',
'OCA\\DAV\\Migration\\Version1016Date20201109085907' => $baseDir . '/../lib/Migration/Version1016Date20201109085907.php',
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningNode.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php', 'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php',

View File

@ -245,6 +245,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Migration\\Version1011Date20190725113607' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20190725113607.php', 'OCA\\DAV\\Migration\\Version1011Date20190725113607' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20190725113607.php',
'OCA\\DAV\\Migration\\Version1011Date20190806104428' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20190806104428.php', 'OCA\\DAV\\Migration\\Version1011Date20190806104428' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20190806104428.php',
'OCA\\DAV\\Migration\\Version1012Date20190808122342' => __DIR__ . '/..' . '/../lib/Migration/Version1012Date20190808122342.php', 'OCA\\DAV\\Migration\\Version1012Date20190808122342' => __DIR__ . '/..' . '/../lib/Migration/Version1012Date20190808122342.php',
'OCA\\DAV\\Migration\\Version1016Date20201109085907' => __DIR__ . '/..' . '/../lib/Migration/Version1016Date20201109085907.php',
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningNode.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php', 'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php',

View File

@ -242,8 +242,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$principalUri = $this->convertPrincipal($principalUri, true); $principalUri = $this->convertPrincipal($principalUri, true);
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select($query->func()->count('*')) $query->select($query->func()->count('*'))
->from('calendars') ->from('calendars');
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
if ($principalUri === '') {
$query->where($query->expr()->emptyString('principaluri'));
} else {
$query->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
}
if ($excludeBirthday) { if ($excludeBirthday) {
$query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)));
@ -293,13 +298,21 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
// Making fields a comma-delimited list // Making fields a comma-delimited list
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select($fields)->from('calendars') $query->select($fields)
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) ->from('calendars')
->orderBy('calendarorder', 'ASC'); ->orderBy('calendarorder', 'ASC');
$stmt = $query->execute();
if ($principalUri === '') {
$query->where($query->expr()->emptyString('principaluri'));
} else {
$query->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
}
$result = $query->execute();
$calendars = []; $calendars = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { while ($row = $result->fetch()) {
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -326,8 +339,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendars[$calendar['id']] = $calendar; $calendars[$calendar['id']] = $calendar;
} }
} }
$result->closeCursor();
$stmt->closeCursor();
// query for shared calendars // query for shared calendars
$principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true);
@ -347,17 +359,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$fields[] = 'a.transparent'; $fields[] = 'a.transparent';
$fields[] = 's.access'; $fields[] = 's.access';
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$result = $query->select($fields) $query->select($fields)
->from('dav_shares', 's') ->from('dav_shares', 's')
->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id'))
->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))
->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) ->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))
->setParameter('type', 'calendar') ->setParameter('type', 'calendar')
->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
->execute();
$result = $query->execute();
$readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
while ($row = $result->fetch()) { while ($row = $result->fetch()) {
$row['principaluri'] = (string) $row['principaluri'];
if ($row['principaluri'] === $principalUri) { if ($row['principaluri'] === $principalUri) {
continue; continue;
} }
@ -428,6 +442,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$stmt = $query->execute(); $stmt = $query->execute();
$calendars = []; $calendars = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -497,6 +512,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->execute(); ->execute();
while ($row = $result->fetch()) { while ($row = $result->fetch()) {
$row['principaluri'] = (string) $row['principaluri'];
list(, $name) = Uri\split($row['principaluri']); list(, $name) = Uri\split($row['principaluri']);
$row['displayname'] = $row['displayname'] . "($name)"; $row['displayname'] = $row['displayname'] . "($name)";
$components = []; $components = [];
@ -563,6 +579,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
throw new NotFound('Node with name \'' . $uri . '\' could not be found'); throw new NotFound('Node with name \'' . $uri . '\' could not be found');
} }
$row['principaluri'] = (string) $row['principaluri'];
list(, $name) = Uri\split($row['principaluri']); list(, $name) = Uri\split($row['principaluri']);
$row['displayname'] = $row['displayname'] . ' ' . "($name)"; $row['displayname'] = $row['displayname'] . ' ' . "($name)";
$components = []; $components = [];
@ -619,6 +636,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return null; return null;
} }
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -669,6 +687,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return null; return null;
} }
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -718,6 +737,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return null; return null;
} }
$row['principaluri'] = (string) $row['principaluri'];
$subscription = [ $subscription = [
'id' => $row['id'], 'id' => $row['id'],
'uri' => $row['uri'], 'uri' => $row['uri'],
@ -965,6 +985,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'classification' => (int)$row['classification'] 'classification' => (int)$row['classification']
]; ];
} }
$stmt->closeCursor();
return $result; return $result;
} }
@ -995,6 +1016,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)));
$stmt = $query->execute(); $stmt = $query->execute();
$row = $stmt->fetch(\PDO::FETCH_ASSOC); $row = $stmt->fetch(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row) { if (!$row) {
return null; return null;

View File

@ -69,7 +69,7 @@ class Version1012Date20190808122342 extends SimpleMigrationStep {
'length' => 11, 'length' => 11,
]); ]);
$table->addColumn('is_recurring', Types::SMALLINT, [ $table->addColumn('is_recurring', Types::SMALLINT, [
'notnull' => true, 'notnull' => false,
'length' => 1, 'length' => 1,
]); ]);
$table->addColumn('uid', Types::STRING, [ $table->addColumn('uid', Types::STRING, [

View File

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version1016Date20201109085907 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$result = $this->ensureColumnIsNullable($schema, 'calendar_reminders', 'is_recurring');
return $result ? $schema : null;
}
protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
$table = $schema->getTable($tableName);
$column = $table->getColumn($columnName);
if ($column->getNotnull()) {
$column->setNotnull(false);
return true;
}
return false;
}
}

View File

@ -110,10 +110,13 @@ class CustomPropertiesBackendTest extends TestCase {
->where($query->expr()->eq('userid', $query->createNamedParameter($user))) ->where($query->expr()->eq('userid', $query->createNamedParameter($user)))
->where($query->expr()->eq('propertypath', $query->createNamedParameter($this->formatPath($path)))); ->where($query->expr()->eq('propertypath', $query->createNamedParameter($this->formatPath($path))));
$result = $query->execute(); $result = $query->execute();
$data = $result->fetchAll(\PDO::FETCH_KEY_PAIR); $data = [];
while ($row = $result->fetch()) {
$data[$row['propertyname']] = $row['propertyvalue'];
}
$result->closeCursor(); $result->closeCursor();
return $data; return $data;
} }

View File

@ -52,7 +52,8 @@ class Version1010Date20200630191755 extends SimpleMigrationStep {
'notnull' => true, 'notnull' => true,
'length' => 4, 'length' => 4,
]); ]);
$table->addUniqueIndex(['share_id'], 'share_id_index'); $table->setPrimaryKey(['share_id'], 'federated_res_pk');
// $table->addUniqueIndex(['share_id'], 'share_id_index');
} }
return $schema; return $schema;
} }

View File

@ -40,6 +40,13 @@ class ClientMapperTest extends TestCase {
$this->clientMapper = new ClientMapper(\OC::$server->getDatabaseConnection()); $this->clientMapper = new ClientMapper(\OC::$server->getDatabaseConnection());
} }
protected function tearDown(): void {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->delete('oauth2_clients')->execute();
parent::tearDown();
}
public function testGetByIdentifier() { public function testGetByIdentifier() {
$client = new Client(); $client = new Client();
$client->setClientIdentifier('MyAwesomeClientIdentifier'); $client->setClientIdentifier('MyAwesomeClientIdentifier');
@ -51,7 +58,6 @@ class ClientMapperTest extends TestCase {
$this->assertEquals($client, $this->clientMapper->getByIdentifier('MyAwesomeClientIdentifier')); $this->assertEquals($client, $this->clientMapper->getByIdentifier('MyAwesomeClientIdentifier'));
} }
public function testGetByIdentifierNotExisting() { public function testGetByIdentifierNotExisting() {
$this->expectException(\OCA\OAuth2\Exceptions\ClientNotFoundException::class); $this->expectException(\OCA\OAuth2\Exceptions\ClientNotFoundException::class);
@ -69,7 +75,6 @@ class ClientMapperTest extends TestCase {
$this->assertEquals($client, $this->clientMapper->getByUid($client->getId())); $this->assertEquals($client, $this->clientMapper->getByUid($client->getId()));
} }
public function testGetByUidNotExisting() { public function testGetByUidNotExisting() {
$this->expectException(\OCA\OAuth2\Exceptions\ClientNotFoundException::class); $this->expectException(\OCA\OAuth2\Exceptions\ClientNotFoundException::class);

View File

@ -49,6 +49,7 @@ use OC\AppFramework\Http;
use OC\DB\Connection; use OC\DB\Connection;
use OC\DB\MissingColumnInformation; use OC\DB\MissingColumnInformation;
use OC\DB\MissingIndexInformation; use OC\DB\MissingIndexInformation;
use OC\DB\MissingPrimaryKeyInformation;
use OC\DB\SchemaWrapper; use OC\DB\SchemaWrapper;
use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Checker;
use OC\Lock\NoopLockingProvider; use OC\Lock\NoopLockingProvider;
@ -452,6 +453,15 @@ Raw output
return $indexInfo->getListOfMissingIndexes(); return $indexInfo->getListOfMissingIndexes();
} }
protected function hasMissingPrimaryKeys(): array {
$info = new MissingPrimaryKeyInformation();
// Dispatch event so apps can also hint for pending index updates if needed
$event = new GenericEvent($info);
$this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, $event);
return $info->getListOfMissingPrimaryKeys();
}
protected function hasMissingColumns(): array { protected function hasMissingColumns(): array {
$indexInfo = new MissingColumnInformation(); $indexInfo = new MissingColumnInformation();
// Dispatch event so apps can also hint for pending index updates if needed // Dispatch event so apps can also hint for pending index updates if needed
@ -722,6 +732,7 @@ Raw output
'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'), 'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
'hasFreeTypeSupport' => $this->hasFreeTypeSupport(), 'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
'missingPrimaryKeys' => $this->hasMissingPrimaryKeys(),
'missingIndexes' => $this->hasMissingIndexes(), 'missingIndexes' => $this->hasMissingIndexes(),
'missingColumns' => $this->hasMissingColumns(), 'missingColumns' => $this->hasMissingColumns(),
'isSqliteUsed' => $this->isSqliteUsed(), 'isSqliteUsed' => $this->isSqliteUsed(),

View File

@ -165,6 +165,7 @@ class CheckSetupControllerTest extends TestCase {
'isOpcacheProperlySetup', 'isOpcacheProperlySetup',
'hasFreeTypeSupport', 'hasFreeTypeSupport',
'hasMissingIndexes', 'hasMissingIndexes',
'hasMissingPrimaryKeys',
'isSqliteUsed', 'isSqliteUsed',
'isPHPMailerUsed', 'isPHPMailerUsed',
'hasOpcacheLoaded', 'hasOpcacheLoaded',
@ -448,6 +449,9 @@ class CheckSetupControllerTest extends TestCase {
$this->checkSetupController $this->checkSetupController
->method('hasMissingIndexes') ->method('hasMissingIndexes')
->willReturn([]); ->willReturn([]);
$this->checkSetupController
->method('hasMissingPrimaryKeys')
->willReturn([]);
$this->checkSetupController $this->checkSetupController
->method('isSqliteUsed') ->method('isSqliteUsed')
->willReturn(false); ->willReturn(false);
@ -587,6 +591,7 @@ class CheckSetupControllerTest extends TestCase {
'isSqliteUsed' => false, 'isSqliteUsed' => false,
'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion', 'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion',
'missingIndexes' => [], 'missingIndexes' => [],
'missingPrimaryKeys' => [],
'missingColumns' => [], 'missingColumns' => [],
'isMemoryLimitSufficient' => true, 'isMemoryLimitSufficient' => true,
'appDirsWithDifferentOwner' => [], 'appDirsWithDifferentOwner' => [],

View File

@ -1700,6 +1700,7 @@
<file src="apps/files_sharing/lib/Controller/ShareController.php"> <file src="apps/files_sharing/lib/Controller/ShareController.php">
<InvalidArgument occurrences="2"> <InvalidArgument occurrences="2">
<code>$files_list</code> <code>$files_list</code>
<code>'Share has no read permission'</code>
</InvalidArgument> </InvalidArgument>
<InvalidScalarArgument occurrences="3"> <InvalidScalarArgument occurrences="3">
<code>$freeSpace</code> <code>$freeSpace</code>
@ -2031,9 +2032,10 @@
</UndefinedInterfaceMethod> </UndefinedInterfaceMethod>
</file> </file>
<file src="apps/settings/lib/Controller/CheckSetupController.php"> <file src="apps/settings/lib/Controller/CheckSetupController.php">
<InvalidArgument occurrences="2"> <InvalidArgument occurrences="3">
<code>IDBConnection::CHECK_MISSING_COLUMNS_EVENT</code> <code>IDBConnection::CHECK_MISSING_COLUMNS_EVENT</code>
<code>IDBConnection::CHECK_MISSING_INDEXES_EVENT</code> <code>IDBConnection::CHECK_MISSING_INDEXES_EVENT</code>
<code>IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT</code>
</InvalidArgument> </InvalidArgument>
<InvalidOperand occurrences="1"> <InvalidOperand occurrences="1">
<code>$lastCronRun</code> <code>$lastCronRun</code>
@ -2049,7 +2051,8 @@
<code>$lastCronRun</code> <code>$lastCronRun</code>
<code>0</code> <code>0</code>
</InvalidScalarArgument> </InvalidScalarArgument>
<TooManyArguments occurrences="2"> <TooManyArguments occurrences="3">
<code>dispatch</code>
<code>dispatch</code> <code>dispatch</code>
<code>dispatch</code> <code>dispatch</code>
</TooManyArguments> </TooManyArguments>
@ -2728,6 +2731,14 @@
<code>dispatch</code> <code>dispatch</code>
</TooManyArguments> </TooManyArguments>
</file> </file>
<file src="core/Command/Db/AddMissingPrimaryKeys.php">
<InvalidArgument occurrences="1">
<code>IDBConnection::ADD_MISSING_PRIMARY_KEYS_EVENT</code>
</InvalidArgument>
<TooManyArguments occurrences="1">
<code>dispatch</code>
</TooManyArguments>
</file>
<file src="core/Command/Db/ConvertType.php"> <file src="core/Command/Db/ConvertType.php">
<InvalidArgument occurrences="2"> <InvalidArgument occurrences="2">
<code>$chunk * $chunkSize</code> <code>$chunk * $chunkSize</code>
@ -3506,7 +3517,9 @@
<InvalidScalarArgument occurrences="1"> <InvalidScalarArgument occurrences="1">
<code>$e-&gt;getCode()</code> <code>$e-&gt;getCode()</code>
</InvalidScalarArgument> </InvalidScalarArgument>
<LessSpecificImplementedReturnType occurrences="1"/> <LessSpecificImplementedReturnType occurrences="1">
<code>\Doctrine\DBAL\Driver\Statement</code>
</LessSpecificImplementedReturnType>
<ParamNameMismatch occurrences="1"> <ParamNameMismatch occurrences="1">
<code>$statement</code> <code>$statement</code>
</ParamNameMismatch> </ParamNameMismatch>
@ -3599,7 +3612,9 @@
</NullableReturnStatement> </NullableReturnStatement>
</file> </file>
<file src="lib/private/DB/ReconnectWrapper.php"> <file src="lib/private/DB/ReconnectWrapper.php">
<InternalMethod occurrences="1"/> <InternalMethod occurrences="1">
<code>parent::__construct($params, $driver, $config, $eventManager)</code>
</InternalMethod>
</file> </file>
<file src="lib/private/DateTimeFormatter.php"> <file src="lib/private/DateTimeFormatter.php">
<FalsableReturnStatement occurrences="1"/> <FalsableReturnStatement occurrences="1"/>
@ -5284,7 +5299,6 @@
<code>$appName</code> <code>$appName</code>
<code>$appName</code> <code>$appName</code>
<code>\OC_User::getUser()</code> <code>\OC_User::getUser()</code>
<code>\OC_User::getUser()</code>
</InvalidScalarArgument> </InvalidScalarArgument>
<TooManyArguments occurrences="1"> <TooManyArguments occurrences="1">
<code>Util::addScript('dist/unified-search', null, true)</code> <code>Util::addScript('dist/unified-search', null, true)</code>

View File

@ -42,6 +42,7 @@ use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
use OC\Core\Notification\RemoveLinkSharesNotifier; use OC\Core\Notification\RemoveLinkSharesNotifier;
use OC\DB\MissingColumnInformation; use OC\DB\MissingColumnInformation;
use OC\DB\MissingIndexInformation; use OC\DB\MissingIndexInformation;
use OC\DB\MissingPrimaryKeyInformation;
use OC\DB\SchemaWrapper; use OC\DB\SchemaWrapper;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
@ -181,6 +182,63 @@ class Application extends App {
} }
); );
$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
function (GenericEvent $event) use ($container) {
/** @var MissingPrimaryKeyInformation $subject */
$subject = $event->getSubject();
$schema = new SchemaWrapper($container->query(IDBConnection::class));
if ($schema->hasTable('federated_reshares')) {
$table = $schema->getTable('federated_reshares');
if (!$table->hasPrimaryKey()) {
$subject->addHintForMissingSubject($table->getName());
}
}
if ($schema->hasTable('systemtag_object_mapping')) {
$table = $schema->getTable('systemtag_object_mapping');
if (!$table->hasPrimaryKey()) {
$subject->addHintForMissingSubject($table->getName());
}
}
if ($schema->hasTable('comments_read_markers')) {
$table = $schema->getTable('comments_read_markers');
if (!$table->hasPrimaryKey()) {
$subject->addHintForMissingSubject($table->getName());
}
}
if ($schema->hasTable('collres_resources')) {
$table = $schema->getTable('collres_resources');
if (!$table->hasPrimaryKey()) {
$subject->addHintForMissingSubject($table->getName());
}
}
if ($schema->hasTable('collres_accesscache')) {
$table = $schema->getTable('collres_accesscache');
if (!$table->hasPrimaryKey()) {
$subject->addHintForMissingSubject($table->getName());
}
}
if ($schema->hasTable('filecache_extended')) {
$table = $schema->getTable('filecache_extended');
if (!$table->hasPrimaryKey()) {
$subject->addHintForMissingSubject($table->getName());
}
}
}
);
$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
function (GenericEvent $event) use ($container) { function (GenericEvent $event) use ($container) {
/** @var MissingColumnInformation $subject */ /** @var MissingColumnInformation $subject */

View File

@ -0,0 +1,181 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Joas Schilling <coding@schilljs.com>
* @author Mario Danic <mario@lovelyhq.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Core\Command\Db;
use OC\DB\SchemaWrapper;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class AddMissingPrimaryKeys
*
* if you added primary keys to the database, this is the right place to add
* your update routine for existing instances
*
* @package OC\Core\Command\Db
*/
class AddMissingPrimaryKeys extends Command {
/** @var IDBConnection */
private $connection;
/** @var EventDispatcherInterface */
private $dispatcher;
public function __construct(IDBConnection $connection, EventDispatcherInterface $dispatcher) {
parent::__construct();
$this->connection = $connection;
$this->dispatcher = $dispatcher;
}
protected function configure() {
$this
->setName('db:add-missing-primary-keys')
->setDescription('Add missing primary keys to the database tables');
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->addCorePrimaryKeys($output);
// Dispatch event so apps can also update indexes if needed
$event = new GenericEvent($output);
$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_PRIMARY_KEYS_EVENT, $event);
return 0;
}
/**
* add missing indices to the share table
*
* @param OutputInterface $output
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
private function addCorePrimaryKeys(OutputInterface $output) {
$output->writeln('<info>Check primary keys.</info>');
$schema = new SchemaWrapper($this->connection);
$updated = false;
if ($schema->hasTable('federated_reshares')) {
$table = $schema->getTable('federated_reshares');
if (!$table->hasPrimaryKey()) {
$output->writeln('<info>Adding primary key to the federated_reshares table, this can take some time...</info>');
$table->setPrimaryKey(['share_id'], 'federated_res_pk');
if ($table->hasIndex('share_id_index')) {
$table->dropIndex('share_id_index');
}
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>federated_reshares table updated successfully.</info>');
}
}
if ($schema->hasTable('systemtag_object_mapping')) {
$table = $schema->getTable('systemtag_object_mapping');
if (!$table->hasPrimaryKey()) {
$output->writeln('<info>Adding primary key to the systemtag_object_mapping table, this can take some time...</info>');
$table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
if ($table->hasIndex('mapping')) {
$table->dropIndex('mapping');
}
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>systemtag_object_mapping table updated successfully.</info>');
}
}
if ($schema->hasTable('comments_read_markers')) {
$table = $schema->getTable('comments_read_markers');
if (!$table->hasPrimaryKey()) {
$output->writeln('<info>Adding primary key to the comments_read_markers table, this can take some time...</info>');
$table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
if ($table->hasIndex('comments_marker_index')) {
$table->dropIndex('comments_marker_index');
}
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>comments_read_markers table updated successfully.</info>');
}
}
if ($schema->hasTable('collres_resources')) {
$table = $schema->getTable('collres_resources');
if (!$table->hasPrimaryKey()) {
$output->writeln('<info>Adding primary key to the collres_resources table, this can take some time...</info>');
$table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
if ($table->hasIndex('collres_unique_res')) {
$table->dropIndex('collres_unique_res');
}
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>collres_resources table updated successfully.</info>');
}
}
if ($schema->hasTable('collres_accesscache')) {
$table = $schema->getTable('collres_accesscache');
if (!$table->hasPrimaryKey()) {
$output->writeln('<info>Adding primary key to the collres_accesscache table, this can take some time...</info>');
$table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
if ($table->hasIndex('collres_unique_user')) {
$table->dropIndex('collres_unique_user');
}
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>collres_accesscache table updated successfully.</info>');
}
}
if ($schema->hasTable('filecache_extended')) {
$table = $schema->getTable('filecache_extended');
if (!$table->hasPrimaryKey()) {
$output->writeln('<info>Adding primary key to the filecache_extended table, this can take some time...</info>');
$table->setPrimaryKey(['fileid'], 'fce_pk');
if ($table->hasIndex('fce_fileid_idx')) {
$table->dropIndex('fce_fileid_idx');
}
$this->connection->migrateToSchema($schema->getWrappedSchema());
$updated = true;
$output->writeln('<info>filecache_extended table updated successfully.</info>');
}
}
if (!$updated) {
$output->writeln('<info>Done.</info>');
}
}
}

View File

@ -673,7 +673,8 @@ class Version13000Date20170718121200 extends SimpleMigrationStep {
'default' => 0, 'default' => 0,
'unsigned' => true, 'unsigned' => true,
]); ]);
$table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping'); $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
// $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
} }
if (!$schema->hasTable('systemtag_group')) { if (!$schema->hasTable('systemtag_group')) {
@ -808,25 +809,26 @@ class Version13000Date20170718121200 extends SimpleMigrationStep {
'default' => '', 'default' => '',
]); ]);
$table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index'); $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
$table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index'); $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
// $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
} }
if (!$schema->hasTable('credentials')) { // if (!$schema->hasTable('credentials')) {
$table = $schema->createTable('credentials'); // $table = $schema->createTable('credentials');
$table->addColumn('user', 'string', [ // $table->addColumn('user', 'string', [
'notnull' => true, // 'notnull' => false,
'length' => 64, // 'length' => 64,
]); // ]);
$table->addColumn('identifier', 'string', [ // $table->addColumn('identifier', 'string', [
'notnull' => true, // 'notnull' => true,
'length' => 64, // 'length' => 64,
]); // ]);
$table->addColumn('credentials', 'text', [ // $table->addColumn('credentials', 'text', [
'notnull' => false, // 'notnull' => false,
]); // ]);
$table->setPrimaryKey(['user', 'identifier']); // $table->setPrimaryKey(['user', 'identifier']);
$table->addIndex(['user'], 'credentials_user'); // $table->addIndex(['user'], 'credentials_user');
} // }
if (!$schema->hasTable('admin_sections')) { if (!$schema->hasTable('admin_sections')) {
$table = $schema->createTable('admin_sections'); $table = $schema->createTable('admin_sections');

View File

@ -43,6 +43,7 @@ class Version14000Date20180710092004 extends SimpleMigrationStep {
if (!$table->hasColumn('password_by_talk')) { if (!$table->hasColumn('password_by_talk')) {
$table->addColumn('password_by_talk', Types::BOOLEAN, [ $table->addColumn('password_by_talk', Types::BOOLEAN, [
'default' => 0, 'default' => 0,
'notnull' => false,
]); ]);
} }

View File

@ -45,8 +45,8 @@ class Version15000Date20180926101451 extends SimpleMigrationStep {
$table = $schema->getTable('authtoken'); $table = $schema->getTable('authtoken');
$table->addColumn('password_invalid','boolean', [ $table->addColumn('password_invalid','boolean', [
'notnull' => true, 'default' => 0,
'default' => false, 'notnull' => false,
]); ]);
return $schema; return $schema;

View File

@ -45,7 +45,7 @@ class Version15000Date20181015062942 extends SimpleMigrationStep {
$table = $schema->getTable('share'); $table = $schema->getTable('share');
$table->addColumn('hide_download', 'smallint', [ $table->addColumn('hide_download', 'smallint', [
'notnull' => true, 'notnull' => false,
'length' => 1, 'length' => 1,
'default' => 0, 'default' => 0,
]); ]);

View File

@ -77,7 +77,8 @@ class Version16000Date20190207141427 extends SimpleMigrationStep {
'length' => 64, 'length' => 64,
]); ]);
$table->addUniqueIndex(['collection_id', 'resource_type', 'resource_id'], 'collres_unique_res'); $table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
// $table->addUniqueIndex(['collection_id', 'resource_type', 'resource_id'], 'collres_unique_res');
} }
if (!$schema->hasTable('collres_accesscache')) { if (!$schema->hasTable('collres_accesscache')) {
@ -102,11 +103,12 @@ class Version16000Date20190207141427 extends SimpleMigrationStep {
'default' => '', 'default' => '',
]); ]);
$table->addColumn('access', Types::SMALLINT, [ $table->addColumn('access', Types::SMALLINT, [
'notnull' => true, 'notnull' => false,
'default' => 0, 'default' => 0,
]); ]);
$table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user'); $table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
// $table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user');
$table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res'); $table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res');
$table->addIndex(['user_id', 'collection_id'], 'collres_user_coll'); $table->addIndex(['user_id', 'collection_id'], 'collres_user_coll');
} }

View File

@ -49,7 +49,7 @@ class Version16000Date20190428150708 extends SimpleMigrationStep {
if ($schema->hasTable('collres_accesscache')) { if ($schema->hasTable('collres_accesscache')) {
$table = $schema->getTable('collres_accesscache'); $table = $schema->getTable('collres_accesscache');
$table->addColumn('access', Types::BOOLEAN, [ $table->addColumn('access', Types::BOOLEAN, [
'notnull' => true, 'notnull' => false,
'default' => false 'default' => false
]); ]);
} }

View File

@ -67,7 +67,8 @@ class Version17000Date20190514105811 extends SimpleMigrationStep {
'length' => 20, 'length' => 20,
'default' => 0, 'default' => 0,
]); ]);
$table->addUniqueIndex(['fileid'], 'fce_fileid_idx'); $table->setPrimaryKey(['fileid'], 'fce_pk');
// $table->addUniqueIndex(['fileid'], 'fce_fileid_idx');
$table->addIndex(['creation_time'], 'fce_ctime_idx'); $table->addIndex(['creation_time'], 'fce_ctime_idx');
$table->addIndex(['upload_time'], 'fce_utime_idx'); $table->addIndex(['upload_time'], 'fce_utime_idx');
} }

View File

@ -58,7 +58,6 @@ class Version18000Date20191204114856 extends SimpleMigrationStep {
'length' => 4000, 'length' => 4000,
]); ]);
return $schema; return $schema;
} }
} }

View File

@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Core\Migrations;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version20000Date20201109081915 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$result = $this->ensureColumnIsNullable($schema, 'share', 'password_by_talk');
$result = $this->ensureColumnIsNullable($schema, 'share', 'hide_download') || $result;
// $result = $this->ensureColumnIsNullable($schema, 'credentials', 'user') || $result;
$result = $this->ensureColumnIsNullable($schema, 'authtoken', 'password_invalid') || $result;
$result = $this->ensureColumnIsNullable($schema, 'collres_accesscache', 'access') || $result;
return $result ? $schema : null;
}
protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
$table = $schema->getTable($tableName);
$column = $table->getColumn($columnName);
if ($column->getNotnull()) {
$column->setNotnull(false);
return true;
}
return false;
}
}

View File

@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Core\Migrations;
use Closure;
use Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version20000Date20201109081918 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->createTable('storages_credentials');
$table->addColumn('id', Type::BIGINT, [
'autoincrement' => true,
'notnull' => true,
'length' => 64,
]);
$table->addColumn('user', Type::STRING, [
'notnull' => false,
'length' => 64,
]);
$table->addColumn('identifier', Type::STRING, [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('credentials', Type::TEXT, [
'notnull' => false,
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['user', 'identifier'], 'stocred_ui');
$table->addIndex(['user'], 'stocred_user');
return $schema;
}
/**
* {@inheritDoc}
*
* @since 13.0.0
*/
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
if (!$this->connection->tableExists('credentials')) {
return;
}
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('credentials');
$insert = $this->connection->getQueryBuilder();
$insert->insert('storages_credentials')
->setValue('user', $insert->createNamedParameter('user'))
->setValue('identifier', $insert->createNamedParameter('identifier'))
->setValue('credentials', $insert->createNamedParameter('credentials'));
$result = $query->execute();
while ($row = $result->fetch()) {
$insert->setParameter('user', (string) $row['user'])
->setParameter('identifier', (string) $row['identifier'])
->setParameter('credentials', (string) $row['credentials']);
$insert->execute();
}
$result->closeCursor();
}
}

View File

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Core\Migrations;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version20000Date20201109081919 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if ($schema->hasTable('credentials')) {
$schema->dropTable('credentials');
return $schema;
}
return null;
}
}

View File

@ -357,6 +357,21 @@
type: OC.SetupChecks.MESSAGE_TYPE_INFO type: OC.SetupChecks.MESSAGE_TYPE_INFO
}) })
} }
if (data.missingPrimaryKeys.length > 0) {
var listOfMissingPrimaryKeys = "";
data.missingPrimaryKeys.forEach(function(element){
listOfMissingPrimaryKeys += "<li>";
listOfMissingPrimaryKeys += t('core', 'Missing primary key on table "{tableName}".', element);
listOfMissingPrimaryKeys += "</li>";
});
messages.push({
msg: t(
'core',
'The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.'
) + "<ul>" + listOfMissingPrimaryKeys + "</ul>",
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.missingColumns.length > 0) { if (data.missingColumns.length > 0) {
var listOfMissingColumns = ""; var listOfMissingColumns = "";
data.missingColumns.forEach(function(element){ data.missingColumns.forEach(function(element){

View File

@ -240,6 +240,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -294,6 +295,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -349,6 +351,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -402,6 +405,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -453,6 +457,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -504,6 +509,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -557,6 +563,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -608,6 +615,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: false, isSettimelimitAvailable: false,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -659,6 +667,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -731,6 +740,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -783,6 +793,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -835,6 +846,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -887,6 +899,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: false, hasFreeTypeSupport: false,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -938,6 +951,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -989,6 +1003,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {
@ -1041,6 +1056,7 @@ describe('OC.SetupChecks tests', function() {
isSettimelimitAvailable: true, isSettimelimitAvailable: true,
hasFreeTypeSupport: true, hasFreeTypeSupport: true,
missingIndexes: [], missingIndexes: [],
missingPrimaryKeys: [],
missingColumns: [], missingColumns: [],
cronErrors: [], cronErrors: [],
cronInfo: { cronInfo: {

View File

@ -799,6 +799,7 @@ return array(
'OC\\Core\\Command\\Config\\System\\SetConfig' => $baseDir . '/core/Command/Config/System/SetConfig.php', 'OC\\Core\\Command\\Config\\System\\SetConfig' => $baseDir . '/core/Command/Config/System/SetConfig.php',
'OC\\Core\\Command\\Db\\AddMissingColumns' => $baseDir . '/core/Command/Db/AddMissingColumns.php', 'OC\\Core\\Command\\Db\\AddMissingColumns' => $baseDir . '/core/Command/Db/AddMissingColumns.php',
'OC\\Core\\Command\\Db\\AddMissingIndices' => $baseDir . '/core/Command/Db/AddMissingIndices.php', 'OC\\Core\\Command\\Db\\AddMissingIndices' => $baseDir . '/core/Command/Db/AddMissingIndices.php',
'OC\\Core\\Command\\Db\\AddMissingPrimaryKeys' => $baseDir . '/core/Command/Db/AddMissingPrimaryKeys.php',
'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => $baseDir . '/core/Command/Db/ConvertFilecacheBigInt.php', 'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => $baseDir . '/core/Command/Db/ConvertFilecacheBigInt.php',
'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => $baseDir . '/core/Command/Db/ConvertMysqlToMB4.php', 'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => $baseDir . '/core/Command/Db/ConvertMysqlToMB4.php',
'OC\\Core\\Command\\Db\\ConvertType' => $baseDir . '/core/Command/Db/ConvertType.php', 'OC\\Core\\Command\\Db\\ConvertType' => $baseDir . '/core/Command/Db/ConvertType.php',
@ -922,6 +923,9 @@ return array(
'OC\\Core\\Migrations\\Version18000Date20191014105105' => $baseDir . '/core/Migrations/Version18000Date20191014105105.php', 'OC\\Core\\Migrations\\Version18000Date20191014105105' => $baseDir . '/core/Migrations/Version18000Date20191014105105.php',
'OC\\Core\\Migrations\\Version18000Date20191204114856' => $baseDir . '/core/Migrations/Version18000Date20191204114856.php', 'OC\\Core\\Migrations\\Version18000Date20191204114856' => $baseDir . '/core/Migrations/Version18000Date20191204114856.php',
'OC\\Core\\Migrations\\Version19000Date20200211083441' => $baseDir . '/core/Migrations/Version19000Date20200211083441.php', 'OC\\Core\\Migrations\\Version19000Date20200211083441' => $baseDir . '/core/Migrations/Version19000Date20200211083441.php',
'OC\\Core\\Migrations\\Version20000Date20201109081915' => $baseDir . '/core/Migrations/Version20000Date20201109081915.php',
'OC\\Core\\Migrations\\Version20000Date20201109081918' => $baseDir . '/core/Migrations/Version20000Date20201109081918.php',
'OC\\Core\\Migrations\\Version20000Date20201109081919' => $baseDir . '/core/Migrations/Version20000Date20201109081919.php',
'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
@ -939,6 +943,7 @@ return array(
'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php', 'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php',
'OC\\DB\\MissingColumnInformation' => $baseDir . '/lib/private/DB/MissingColumnInformation.php', 'OC\\DB\\MissingColumnInformation' => $baseDir . '/lib/private/DB/MissingColumnInformation.php',
'OC\\DB\\MissingIndexInformation' => $baseDir . '/lib/private/DB/MissingIndexInformation.php', 'OC\\DB\\MissingIndexInformation' => $baseDir . '/lib/private/DB/MissingIndexInformation.php',
'OC\\DB\\MissingPrimaryKeyInformation' => $baseDir . '/lib/private/DB/MissingPrimaryKeyInformation.php',
'OC\\DB\\MySQLMigrator' => $baseDir . '/lib/private/DB/MySQLMigrator.php', 'OC\\DB\\MySQLMigrator' => $baseDir . '/lib/private/DB/MySQLMigrator.php',
'OC\\DB\\MySqlTools' => $baseDir . '/lib/private/DB/MySqlTools.php', 'OC\\DB\\MySqlTools' => $baseDir . '/lib/private/DB/MySqlTools.php',
'OC\\DB\\OCSqlitePlatform' => $baseDir . '/lib/private/DB/OCSqlitePlatform.php', 'OC\\DB\\OCSqlitePlatform' => $baseDir . '/lib/private/DB/OCSqlitePlatform.php',

View File

@ -828,6 +828,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Command\\Config\\System\\SetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/SetConfig.php', 'OC\\Core\\Command\\Config\\System\\SetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/SetConfig.php',
'OC\\Core\\Command\\Db\\AddMissingColumns' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingColumns.php', 'OC\\Core\\Command\\Db\\AddMissingColumns' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingColumns.php',
'OC\\Core\\Command\\Db\\AddMissingIndices' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingIndices.php', 'OC\\Core\\Command\\Db\\AddMissingIndices' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingIndices.php',
'OC\\Core\\Command\\Db\\AddMissingPrimaryKeys' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingPrimaryKeys.php',
'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertFilecacheBigInt.php', 'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertFilecacheBigInt.php',
'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertMysqlToMB4.php', 'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertMysqlToMB4.php',
'OC\\Core\\Command\\Db\\ConvertType' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertType.php', 'OC\\Core\\Command\\Db\\ConvertType' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertType.php',
@ -951,6 +952,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Migrations\\Version18000Date20191014105105' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191014105105.php', 'OC\\Core\\Migrations\\Version18000Date20191014105105' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191014105105.php',
'OC\\Core\\Migrations\\Version18000Date20191204114856' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191204114856.php', 'OC\\Core\\Migrations\\Version18000Date20191204114856' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191204114856.php',
'OC\\Core\\Migrations\\Version19000Date20200211083441' => __DIR__ . '/../../..' . '/core/Migrations/Version19000Date20200211083441.php', 'OC\\Core\\Migrations\\Version19000Date20200211083441' => __DIR__ . '/../../..' . '/core/Migrations/Version19000Date20200211083441.php',
'OC\\Core\\Migrations\\Version20000Date20201109081915' => __DIR__ . '/../../..' . '/core/Migrations/Version20000Date20201109081915.php',
'OC\\Core\\Migrations\\Version20000Date20201109081918' => __DIR__ . '/../../..' . '/core/Migrations/Version20000Date20201109081918.php',
'OC\\Core\\Migrations\\Version20000Date20201109081919' => __DIR__ . '/../../..' . '/core/Migrations/Version20000Date20201109081919.php',
'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
@ -968,6 +972,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php', 'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php',
'OC\\DB\\MissingColumnInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingColumnInformation.php', 'OC\\DB\\MissingColumnInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingColumnInformation.php',
'OC\\DB\\MissingIndexInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingIndexInformation.php', 'OC\\DB\\MissingIndexInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingIndexInformation.php',
'OC\\DB\\MissingPrimaryKeyInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingPrimaryKeyInformation.php',
'OC\\DB\\MySQLMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/MySQLMigrator.php', 'OC\\DB\\MySQLMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/MySQLMigrator.php',
'OC\\DB\\MySqlTools' => __DIR__ . '/../../..' . '/lib/private/DB/MySqlTools.php', 'OC\\DB\\MySqlTools' => __DIR__ . '/../../..' . '/lib/private/DB/MySqlTools.php',
'OC\\DB\\OCSqlitePlatform' => __DIR__ . '/../../..' . '/lib/private/DB/OCSqlitePlatform.php', 'OC\\DB\\OCSqlitePlatform' => __DIR__ . '/../../..' . '/lib/private/DB/OCSqlitePlatform.php',

View File

@ -39,6 +39,7 @@ use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception\ConstraintViolationException; use Doctrine\DBAL\Exception\ConstraintViolationException;
use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use OC\DB\QueryBuilder\QueryBuilder; use OC\DB\QueryBuilder\QueryBuilder;
@ -322,6 +323,8 @@ class Connection extends ReconnectWrapper implements IDBConnection {
}, array_merge($keys, $values)) }, array_merge($keys, $values))
); );
return $insertQb->execute(); return $insertQb->execute();
} catch (NotNullConstraintViolationException $e) {
throw $e;
} catch (ConstraintViolationException $e) { } catch (ConstraintViolationException $e) {
// value already exists, try update // value already exists, try update
$updateQb = $this->getQueryBuilder(); $updateQb = $this->getQueryBuilder();
@ -332,11 +335,17 @@ class Connection extends ReconnectWrapper implements IDBConnection {
$where = $updateQb->expr()->andX(); $where = $updateQb->expr()->andX();
$whereValues = array_merge($keys, $updatePreconditionValues); $whereValues = array_merge($keys, $updatePreconditionValues);
foreach ($whereValues as $name => $value) { foreach ($whereValues as $name => $value) {
$where->add($updateQb->expr()->eq( if ($value === '') {
$name, $where->add($updateQb->expr()->emptyString(
$updateQb->createNamedParameter($value, $this->getType($value)), $name
$this->getType($value) ));
)); } else {
$where->add($updateQb->expr()->eq(
$name,
$updateQb->createNamedParameter($value, $this->getType($value)),
$this->getType($value)
));
}
} }
$updateQb->where($where); $updateQb->where($where);
$affected = $updateQb->execute(); $affected = $updateQb->execute();

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Morris Jobke <hey@morrisjobke.de>
*
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\DB;
class MissingPrimaryKeyInformation {
private $listOfMissingPrimaryKeys = [];
public function addHintForMissingSubject(string $tableName) {
$this->listOfMissingPrimaryKeys[] = [
'tableName' => $tableName,
];
}
public function getListOfMissingPrimaryKeys(): array {
return $this->listOfMissingPrimaryKeys;
}
}

View File

@ -998,7 +998,11 @@ class Cache implements ICache {
$path = $result->fetchColumn(); $path = $result->fetchColumn();
$result->closeCursor(); $result->closeCursor();
return $path === false ? null : $path; if ($path === false) {
return null;
}
return (string) $path;
} }
/** /**

View File

@ -35,7 +35,7 @@ use OCP\Security\ICrypto;
* @package OC\Security * @package OC\Security
*/ */
class CredentialsManager implements ICredentialsManager { class CredentialsManager implements ICredentialsManager {
public const DB_TABLE = 'credentials'; public const DB_TABLE = 'storages_credentials';
/** @var ICrypto */ /** @var ICrypto */
protected $crypto; protected $crypto;
@ -81,9 +81,13 @@ class CredentialsManager implements ICredentialsManager {
$qb = $this->dbConnection->getQueryBuilder(); $qb = $this->dbConnection->getQueryBuilder();
$qb->select('credentials') $qb->select('credentials')
->from(self::DB_TABLE) ->from(self::DB_TABLE)
->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) ->where($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)));
->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
; if ($userId === '') {
$qb->andWhere($qb->expr()->emptyString('user'));
} else {
$qb->andWhere($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId)));
}
$qResult = $qb->execute(); $qResult = $qb->execute();
$result = $qResult->fetch(); $result = $qResult->fetch();
@ -107,9 +111,14 @@ class CredentialsManager implements ICredentialsManager {
public function delete($userId, $identifier) { public function delete($userId, $identifier) {
$qb = $this->dbConnection->getQueryBuilder(); $qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::DB_TABLE) $qb->delete(self::DB_TABLE)
->where($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId))) ->where($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)));
->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
; if ($userId === '') {
$qb->andWhere($qb->expr()->emptyString('user'));
} else {
$qb->andWhere($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId)));
}
return $qb->execute(); return $qb->execute();
} }

View File

@ -874,6 +874,11 @@ class DefaultShareProvider implements IShareProvider {
$cursor = $qb->execute(); $cursor = $qb->execute();
while ($data = $cursor->fetch()) { while ($data = $cursor->fetch()) {
if ($data['fileid'] && $data['path'] === null) {
$data['path'] = (string) $data['path'];
$data['name'] = (string) $data['name'];
$data['checksum'] = (string) $data['checksum'];
}
if ($this->isAccessibleResult($data)) { if ($this->isAccessibleResult($data)) {
$shares[] = $this->createShare($data); $shares[] = $this->createShare($data);
} }
@ -1004,7 +1009,7 @@ class DefaultShareProvider implements IShareProvider {
->setShareType((int)$data['share_type']) ->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions']) ->setPermissions((int)$data['permissions'])
->setTarget($data['file_target']) ->setTarget($data['file_target'])
->setNote($data['note']) ->setNote((string)$data['note'])
->setMailSend((bool)$data['mail_send']) ->setMailSend((bool)$data['mail_send'])
->setStatus((int)$data['accepted']) ->setStatus((int)$data['accepted'])
->setLabel($data['label']); ->setLabel($data['label']);

View File

@ -50,6 +50,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
interface IDBConnection { interface IDBConnection {
public const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES'; public const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES';
public const CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES'; public const CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES';
public const ADD_MISSING_PRIMARY_KEYS_EVENT = self::class . '::ADD_MISSING_PRIMARY_KEYS';
public const CHECK_MISSING_PRIMARY_KEYS_EVENT = self::class . '::CHECK_MISSING_PRIMARY_KEYS';
public const ADD_MISSING_COLUMNS_EVENT = self::class . '::ADD_MISSING_COLUMNS'; public const ADD_MISSING_COLUMNS_EVENT = self::class . '::ADD_MISSING_COLUMNS';
public const CHECK_MISSING_COLUMNS_EVENT = self::class . '::CHECK_MISSING_COLUMNS'; public const CHECK_MISSING_COLUMNS_EVENT = self::class . '::CHECK_MISSING_COLUMNS';

View File

@ -9,6 +9,7 @@
namespace Test; namespace Test;
use OC\AppConfig;
use OCP\IConfig; use OCP\IConfig;
/** /**
@ -42,7 +43,7 @@ class AppConfigTest extends TestCase {
$sql->delete('appconfig'); $sql->delete('appconfig');
$sql->execute(); $sql->execute();
$this->overwriteService('AppConfig', new \OC\AppConfig($this->connection)); $this->overwriteService(AppConfig::class, new \OC\AppConfig($this->connection));
$sql = $this->connection->getQueryBuilder(); $sql = $this->connection->getQueryBuilder();
$sql->insert('appconfig') $sql->insert('appconfig')
@ -132,7 +133,7 @@ class AppConfigTest extends TestCase {
$sql->execute(); $sql->execute();
} }
$this->restoreService('AppConfig'); $this->restoreService(AppConfig::class);
parent::tearDown(); parent::tearDown();
} }

View File

@ -97,14 +97,17 @@ class ConnectionTest extends \Test\TestCase {
$this->assertTableNotExist('table'); $this->assertTableNotExist('table');
} }
private function getTextValueByIntergerField($integerField) { private function getTextValueByIntegerField($integerField) {
$builder = $this->connection->getQueryBuilder(); $builder = $this->connection->getQueryBuilder();
$query = $builder->select('textfield') $query = $builder->select('*')
->from('table') ->from('table')
->where($builder->expr()->eq('integerfield', $builder->createNamedParameter($integerField, IQueryBuilder::PARAM_INT))); ->where($builder->expr()->eq('integerfield', $builder->createNamedParameter($integerField, IQueryBuilder::PARAM_INT)));
$result = $query->execute(); $result = $query->execute();
return $result->fetchColumn(); $row = $result->fetch();
$result->closeCursor();
return $row['textfield'] ?? null;
} }
public function testSetValues() { public function testSetValues() {
@ -116,7 +119,7 @@ class ConnectionTest extends \Test\TestCase {
'clobfield' => 'not_null' 'clobfield' => 'not_null'
]); ]);
$this->assertEquals('foo', $this->getTextValueByIntergerField(1)); $this->assertEquals('foo', $this->getTextValueByIntegerField(1));
} }
public function testSetValuesOverWrite() { public function testSetValuesOverWrite() {
@ -133,7 +136,7 @@ class ConnectionTest extends \Test\TestCase {
'textfield' => 'bar' 'textfield' => 'bar'
]); ]);
$this->assertEquals('bar', $this->getTextValueByIntergerField(1)); $this->assertEquals('bar', $this->getTextValueByIntegerField(1));
} }
public function testSetValuesOverWritePrecondition() { public function testSetValuesOverWritePrecondition() {
@ -154,7 +157,7 @@ class ConnectionTest extends \Test\TestCase {
'booleanfield' => true 'booleanfield' => true
]); ]);
$this->assertEquals('bar', $this->getTextValueByIntergerField(1)); $this->assertEquals('bar', $this->getTextValueByIntegerField(1));
} }
@ -200,6 +203,10 @@ class ConnectionTest extends \Test\TestCase {
} }
public function testInsertIfNotExist() { public function testInsertIfNotExist() {
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') {
self::markTestSkipped('Insert if not exist does not work with clob on oracle');
}
$this->makeTestTable(); $this->makeTestTable();
$categoryEntries = [ $categoryEntries = [
['user' => 'test', 'category' => 'Family', 'expectedResult' => 1], ['user' => 'test', 'category' => 'Family', 'expectedResult' => 1],
@ -213,13 +220,15 @@ class ConnectionTest extends \Test\TestCase {
['user' => 'test2', 'category' => 'Coworkers', 'expectedResult' => 1], ['user' => 'test2', 'category' => 'Coworkers', 'expectedResult' => 1],
]; ];
$row = 0;
foreach ($categoryEntries as $entry) { foreach ($categoryEntries as $entry) {
$result = $this->connection->insertIfNotExist('*PREFIX*table', $result = $this->connection->insertIfNotExist('*PREFIX*table',
[ [
'textfield' => $entry['user'], 'textfield' => $entry['user'],
'clobfield' => $entry['category'], 'clobfield' => $entry['category'],
]); 'integerfield' => $row++,
$this->assertEquals($entry['expectedResult'], $result); ], ['textfield', 'clobfield']);
$this->assertEquals($entry['expectedResult'], $result, json_encode($entry));
} }
$query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`');
@ -229,6 +238,10 @@ class ConnectionTest extends \Test\TestCase {
} }
public function testInsertIfNotExistNull() { public function testInsertIfNotExistNull() {
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') {
self::markTestSkipped('Insert if not exist does not work with clob on oracle');
}
$this->makeTestTable(); $this->makeTestTable();
$categoryEntries = [ $categoryEntries = [
['addressbookid' => 123, 'fullname' => null, 'expectedResult' => 1], ['addressbookid' => 123, 'fullname' => null, 'expectedResult' => 1],
@ -236,13 +249,15 @@ class ConnectionTest extends \Test\TestCase {
['addressbookid' => 123, 'fullname' => 'test', 'expectedResult' => 1], ['addressbookid' => 123, 'fullname' => 'test', 'expectedResult' => 1],
]; ];
$row = 0;
foreach ($categoryEntries as $entry) { foreach ($categoryEntries as $entry) {
$result = $this->connection->insertIfNotExist('*PREFIX*table', $result = $this->connection->insertIfNotExist('*PREFIX*table',
[ [
'integerfield_default' => $entry['addressbookid'], 'integerfield_default' => $entry['addressbookid'],
'clobfield' => $entry['fullname'], 'clobfield' => $entry['fullname'],
]); 'integerfield' => $row++,
$this->assertEquals($entry['expectedResult'], $result); ], ['integerfield_default', 'clobfield']);
$this->assertEquals($entry['expectedResult'], $result, json_encode($entry));
} }
$query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`');
@ -252,6 +267,10 @@ class ConnectionTest extends \Test\TestCase {
} }
public function testInsertIfNotExistDonTOverwrite() { public function testInsertIfNotExistDonTOverwrite() {
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') {
self::markTestSkipped('Insert if not exist does not work with clob on oracle');
}
$this->makeTestTable(); $this->makeTestTable();
$fullName = 'fullname test'; $fullName = 'fullname test';
$uri = 'uri_1'; $uri = 'uri_1';
@ -288,6 +307,10 @@ class ConnectionTest extends \Test\TestCase {
} }
public function testInsertIfNotExistsViolating() { public function testInsertIfNotExistsViolating() {
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') {
self::markTestSkipped('Insert if not exist does not work with clob on oracle');
}
$this->makeTestTable(); $this->makeTestTable();
$result = $this->connection->insertIfNotExist('*PREFIX*table', $result = $this->connection->insertIfNotExist('*PREFIX*table',
[ [
@ -318,6 +341,10 @@ class ConnectionTest extends \Test\TestCase {
* @param array $compareKeys * @param array $compareKeys
*/ */
public function testInsertIfNotExistsViolatingUnique($compareKeys) { public function testInsertIfNotExistsViolatingUnique($compareKeys) {
if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') {
self::markTestSkipped('Insert if not exist does not work with clob on oracle');
}
$this->makeTestTable(); $this->makeTestTable();
$result = $this->connection->insertIfNotExist('*PREFIX*table', $result = $this->connection->insertIfNotExist('*PREFIX*table',
[ [

View File

@ -14,6 +14,10 @@ use Doctrine\DBAL\Schema\Schema;
use OC\DB\MDB2SchemaReader; use OC\DB\MDB2SchemaReader;
use OCP\IConfig; use OCP\IConfig;
use Test\TestCase; use Test\TestCase;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\BooleanType;
/** /**
* Class MDB2SchemaReaderTest * Class MDB2SchemaReaderTest
@ -51,13 +55,13 @@ class MDB2SchemaReaderTest extends TestCase {
$this->assertCount(1, $schema->getTables()); $this->assertCount(1, $schema->getTables());
$table = $schema->getTable('test_table'); $table = $schema->getTable('test_table');
$this->assertCount(8, $table->getColumns()); $this->assertCount(9, $table->getColumns());
$this->assertEquals(4, $table->getColumn('integerfield')->getLength()); $this->assertEquals(4, $table->getColumn('id')->getLength());
$this->assertTrue($table->getColumn('integerfield')->getAutoincrement()); $this->assertTrue($table->getColumn('id')->getAutoincrement());
$this->assertEquals(0, $table->getColumn('integerfield')->getDefault()); $this->assertEquals(0, $table->getColumn('id')->getDefault());
$this->assertTrue($table->getColumn('integerfield')->getNotnull()); $this->assertTrue($table->getColumn('id')->getNotnull());
$this->assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $table->getColumn('integerfield')->getType()); $this->assertInstanceOf(IntegerType::class, $table->getColumn('id')->getType());
$this->assertSame(10, $table->getColumn('integerfield_default')->getDefault()); $this->assertSame(10, $table->getColumn('integerfield_default')->getDefault());
@ -65,18 +69,19 @@ class MDB2SchemaReaderTest extends TestCase {
$this->assertFalse($table->getColumn('textfield')->getAutoincrement()); $this->assertFalse($table->getColumn('textfield')->getAutoincrement());
$this->assertSame('foo', $table->getColumn('textfield')->getDefault()); $this->assertSame('foo', $table->getColumn('textfield')->getDefault());
$this->assertTrue($table->getColumn('textfield')->getNotnull()); $this->assertTrue($table->getColumn('textfield')->getNotnull());
$this->assertInstanceOf('Doctrine\DBAL\Types\StringType', $table->getColumn('textfield')->getType()); $this->assertInstanceOf(StringType::class, $table->getColumn('textfield')->getType());
$this->assertNull($table->getColumn('clobfield')->getLength()); $this->assertNull($table->getColumn('clobfield')->getLength());
$this->assertFalse($table->getColumn('clobfield')->getAutoincrement()); $this->assertFalse($table->getColumn('clobfield')->getAutoincrement());
$this->assertNull($table->getColumn('clobfield')->getDefault()); $this->assertNull($table->getColumn('clobfield')->getDefault());
$this->assertFalse($table->getColumn('clobfield')->getNotnull()); $this->assertFalse($table->getColumn('clobfield')->getNotnull());
$this->assertInstanceOf('Doctrine\DBAL\Types\TextType', $table->getColumn('clobfield')->getType()); $this->assertInstanceOf(StringType::class, $table->getColumn('clobfield')->getType());
// $this->assertInstanceOf(TextType::class, $table->getColumn('clobfield')->getType());
$this->assertNull($table->getColumn('booleanfield')->getLength()); $this->assertNull($table->getColumn('booleanfield')->getLength());
$this->assertFalse($table->getColumn('booleanfield')->getAutoincrement()); $this->assertFalse($table->getColumn('booleanfield')->getAutoincrement());
$this->assertNull($table->getColumn('booleanfield')->getDefault()); $this->assertNull($table->getColumn('booleanfield')->getDefault());
$this->assertInstanceOf('Doctrine\DBAL\Types\BooleanType', $table->getColumn('booleanfield')->getType()); $this->assertInstanceOf(BooleanType::class, $table->getColumn('booleanfield')->getType());
$this->assertTrue($table->getColumn('booleanfield_true')->getDefault()); $this->assertTrue($table->getColumn('booleanfield_true')->getDefault());
$this->assertFalse($table->getColumn('booleanfield_false')->getDefault()); $this->assertFalse($table->getColumn('booleanfield_false')->getDefault());
@ -84,10 +89,13 @@ class MDB2SchemaReaderTest extends TestCase {
$this->assertEquals(12, $table->getColumn('decimalfield_precision_scale')->getPrecision()); $this->assertEquals(12, $table->getColumn('decimalfield_precision_scale')->getPrecision());
$this->assertEquals(2, $table->getColumn('decimalfield_precision_scale')->getScale()); $this->assertEquals(2, $table->getColumn('decimalfield_precision_scale')->getScale());
$this->assertCount(2, $table->getIndexes()); $this->assertCount(3, $table->getIndexes());
$this->assertEquals(['integerfield'], $table->getIndex('primary')->getUnquotedColumns()); $this->assertEquals(['id'], $table->getIndex('primary')->getUnquotedColumns());
$this->assertTrue($table->getIndex('primary')->isPrimary()); $this->assertTrue($table->getIndex('primary')->isPrimary());
$this->assertTrue($table->getIndex('primary')->isUnique()); $this->assertTrue($table->getIndex('primary')->isUnique());
$this->assertEquals(['integerfield'], $table->getIndex('index_integerfield')->getUnquotedColumns());
$this->assertFalse($table->getIndex('index_integerfield')->isPrimary());
$this->assertTrue($table->getIndex('index_integerfield')->isUnique());
$this->assertEquals(['booleanfield'], $table->getIndex('index_boolean')->getUnquotedColumns()); $this->assertEquals(['booleanfield'], $table->getIndex('index_boolean')->getUnquotedColumns());
$this->assertFalse($table->getIndex('index_boolean')->isPrimary()); $this->assertFalse($table->getIndex('index_boolean')->isPrimary());
$this->assertFalse($table->getIndex('index_boolean')->isUnique()); $this->assertFalse($table->getIndex('index_boolean')->isUnique());

View File

@ -13,7 +13,7 @@
<declaration> <declaration>
<field> <field>
<name>integerfield</name> <name>id</name>
<type>integer</type> <type>integer</type>
<default>0</default> <default>0</default>
<notnull>true</notnull> <notnull>true</notnull>
@ -21,6 +21,13 @@
<length>4</length> <length>4</length>
<autoincrement>1</autoincrement> <autoincrement>1</autoincrement>
</field> </field>
<field>
<name>integerfield</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>4</length>
</field>
<field> <field>
<name>integerfield_default</name> <name>integerfield_default</name>
<type>integer</type> <type>integer</type>
@ -37,7 +44,7 @@
</field> </field>
<field> <field>
<name>clobfield</name> <name>clobfield</name>
<type>clob</type> <type>text</type>
</field> </field>
<field> <field>
<name>booleanfield</name> <name>booleanfield</name>
@ -64,6 +71,15 @@
<name>index_primary</name> <name>index_primary</name>
<primary>true</primary> <primary>true</primary>
<unique>true</unique> <unique>true</unique>
<field>
<name>id</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>index_integerfield</name>
<unique>true</unique>
<field> <field>
<name>integerfield</name> <name>integerfield</name>
<sorting>ascending</sorting> <sorting>ascending</sorting>

View File

@ -29,7 +29,7 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number. // when updating major/minor version number.
$OC_Version = [21, 0, 0, 2]; $OC_Version = [21, 0, 0, 6];
// The human readable string // The human readable string
$OC_VersionString = '21.0.0 alpha'; $OC_VersionString = '21.0.0 alpha';