Compare commits

..

1 Commits

Author SHA1 Message Date
Git'Fellow 21416b8a31 refactor(dbal): move to modern calls
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
2026-03-13 09:20:00 +01:00
98 changed files with 600 additions and 711 deletions
-29
View File
@@ -4,7 +4,6 @@
# Global exclude
.editorconfig
.envrc
.git
.git-blame-ignore-revs
.gitattributes
@@ -12,40 +11,12 @@
.gitignore
.gitmodules
.idea
.jshint
.l10nignore
.mailmap
.nextcloudignore
.noopenapi
.npmignore
.php-cs-fixer*
.pre-commit-config.yaml
.tag
.tx
CHANGELOG.md
CODE_OF_CONDUCT.md
COPYING-README
DESIGN.md
Makefile
README.md
SECURITY.md
codecov.yml
cs-fixer
csfixer
cypress
eslint.config.js
flake.lock
flake.nix
openapi-extractor
phpunit
psalm
psalm*.xml
rector
stylelint.config.js
tests
tsconfig.json
vitest.config.ts
window.d.ts
# Server specific
/.devcontainer
+1 -1
View File
@@ -10,7 +10,7 @@
<name>WebDAV</name>
<summary>WebDAV endpoint</summary>
<description>WebDAV endpoint</description>
<version>1.38.0</version>
<version>1.37.0</version>
<licence>agpl</licence>
<author>owncloud.org</author>
<namespace>DAV</namespace>
+2 -1
View File
@@ -92,6 +92,7 @@ $server = $serverFactory->createServer(
}
$share = $authBackend->getShare();
$owner = $share->getShareOwner();
$isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
$fileId = $share->getNodeId();
@@ -106,7 +107,7 @@ $server = $serverFactory->createServer(
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
$rootFolder = Server::get(IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($share->getSharedBy());
$userFolder = $rootFolder->getUserFolder($owner);
$node = $userFolder->getFirstNodeById($fileId);
if (!$node) {
throw new \Sabre\DAV\Exception\NotFound();
+2 -1
View File
@@ -99,6 +99,7 @@ $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin,
}
$share = $authBackend->getShare();
$owner = $share->getShareOwner();
$isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
$fileId = $share->getNodeId();
@@ -134,7 +135,7 @@ $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin,
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
$rootFolder = Server::get(IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($share->getSharedBy());
$userFolder = $rootFolder->getUserFolder($owner);
$node = $userFolder->getFirstNodeById($fileId);
if (!$node) {
throw new NotFound();
@@ -389,7 +389,6 @@ return array(
'OCA\\DAV\\Migration\\Version1034Date20250605132605' => $baseDir . '/../lib/Migration/Version1034Date20250605132605.php',
'OCA\\DAV\\Migration\\Version1034Date20250813093701' => $baseDir . '/../lib/Migration/Version1034Date20250813093701.php',
'OCA\\DAV\\Migration\\Version1036Date20251202000000' => $baseDir . '/../lib/Migration/Version1036Date20251202000000.php',
'OCA\\DAV\\Migration\\Version1038Date20260302000000' => $baseDir . '/../lib/Migration/Version1038Date20260302000000.php',
'OCA\\DAV\\Model\\ExampleEvent' => $baseDir . '/../lib/Model/ExampleEvent.php',
'OCA\\DAV\\Paginate\\LimitedCopyIterator' => $baseDir . '/../lib/Paginate/LimitedCopyIterator.php',
'OCA\\DAV\\Paginate\\PaginateCache' => $baseDir . '/../lib/Paginate/PaginateCache.php',
@@ -404,7 +404,6 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Migration\\Version1034Date20250605132605' => __DIR__ . '/..' . '/../lib/Migration/Version1034Date20250605132605.php',
'OCA\\DAV\\Migration\\Version1034Date20250813093701' => __DIR__ . '/..' . '/../lib/Migration/Version1034Date20250813093701.php',
'OCA\\DAV\\Migration\\Version1036Date20251202000000' => __DIR__ . '/..' . '/../lib/Migration/Version1036Date20251202000000.php',
'OCA\\DAV\\Migration\\Version1038Date20260302000000' => __DIR__ . '/..' . '/../lib/Migration/Version1038Date20260302000000.php',
'OCA\\DAV\\Model\\ExampleEvent' => __DIR__ . '/..' . '/../lib/Model/ExampleEvent.php',
'OCA\\DAV\\Paginate\\LimitedCopyIterator' => __DIR__ . '/..' . '/../lib/Paginate/LimitedCopyIterator.php',
'OCA\\DAV\\Paginate\\PaginateCache' => __DIR__ . '/..' . '/../lib/Paginate/PaginateCache.php',
+6 -3
View File
@@ -151,7 +151,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'{http://apple.com/ns/ical/}calendar-order' => ['calendarorder', 'int'],
'{http://apple.com/ns/ical/}calendar-color' => ['calendarcolor', 'string'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => ['deleted_at', 'int'],
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}default-alarm' => ['default_alarm', 'int'],
];
/**
@@ -1571,8 +1570,12 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
}
if ($forceDeletePermanently || $this->config->getAppValue(Application::APP_ID, RetentionService::RETENTION_CONFIG_KEY) === '0') {
$stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ? AND `calendartype` = ?');
$stmt->execute([$calendarId, $objectUri, $calendarType]);
$qb = $this->db->getQueryBuilder();
$qb->delete('calendarobjects')
->where($qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId)))
->andWhere($qb->expr()->eq('uri', $qb->createNamedParameter($objectUri)))
->andWhere($qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType)))
->executeStatement();
$this->purgeProperties($calendarId, $data['id']);
@@ -43,7 +43,7 @@ class PublicLinkCheckPlugin extends ServerPlugin {
}
public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
// verify that the initiator didn't have their share permissions revoked
// verify that the owner didn't have their share permissions revoked
if ($this->fileInfo && !$this->fileInfo->isShareable()) {
throw new NotFound();
}
@@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\Attributes\AddColumn;
use OCP\Migration\Attributes\ColumnType;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
#[AddColumn(table: 'calendars', name: 'default_alarm', type: ColumnType::STRING)]
class Version1038Date20260302000000 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$calendarsTable = $schema->getTable('calendars');
if (!$calendarsTable->hasColumn('default_alarm')) {
$calendarsTable->addColumn('default_alarm', Types::INTEGER, [
'notnull' => false,
'default' => null,
]);
}
return $schema;
}
}
@@ -1881,43 +1881,4 @@ EOD;
);
}
public function testDefaultAlarmProperty(): void {
$calendarId = $this->createTestCalendar();
// Test setting default alarm property to 15 minutes before (-900 seconds)
$patch = new PropPatch([
'{http://nextcloud.com/ns}default-alarm' => -900
]);
$this->backend->updateCalendar($calendarId, $patch);
$patch->commit();
// Verify the property was set
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertCount(1, $calendars);
$this->assertEquals(-900, $calendars[0]['{http://nextcloud.com/ns}default-alarm']);
// Test updating to a different value (1 day before = -86400 seconds)
$patch = new PropPatch([
'{http://nextcloud.com/ns}default-alarm' => -86400
]);
$this->backend->updateCalendar($calendarId, $patch);
$patch->commit();
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(-86400, $calendars[0]['{http://nextcloud.com/ns}default-alarm']);
// Test setting to "none"
$patch = new PropPatch([
'{http://nextcloud.com/ns}default-alarm' => null
]);
$this->backend->updateCalendar($calendarId, $patch);
$patch->commit();
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(null, $calendars[0]['{http://nextcloud.com/ns}default-alarm']);
// Clean up
$this->backend->deleteCalendar($calendars[0]['id'], true);
}
}
@@ -128,30 +128,30 @@ class FederatedShareProvider implements IShareProvider, IShareProviderSupportsAl
$share->setSharedWith($cloudId->getId());
try {
$remoteShare = $this->getShareFromExternalShareTable($share->getShareOwner(), $share->getTarget());
$remoteShare = $this->getShareFromExternalShareTable($share);
} catch (ShareNotFound $e) {
$remoteShare = null;
}
if ($remoteShare) {
$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType, $expirationDate);
[$token, $remoteId] = $this->notifications->requestReShare(
$remoteShare['share_token'],
$remoteShare['remote_id'],
$shareId,
$remoteShare['remote'],
$shareWith,
$permissions,
$share->getNode()->getName(),
$shareType,
);
// remote share was create successfully if we get a valid token as return
if (is_string($token) && $token !== '') {
try {
$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType, $expirationDate);
$share->setId($shareId);
[$token, $remoteId] = $this->askOwnerToReShare($shareWith, $share, $shareId);
// remote share was create successfully if we get a valid token as return
$send = is_string($token) && $token !== '';
} catch (\Exception $e) {
// fall back to old re-share behavior if the remote server
// doesn't support flat re-shares (was introduced with Nextcloud 9.1)
$this->removeShareFromTable($share);
$shareId = $this->createFederatedShare($share);
}
if ($send) {
$this->updateSuccessfulReshare($shareId, $token);
$this->storeRemoteId($shareId, $remoteId);
} else {
$this->removeShareFromTable($shareId);
$this->removeShareFromTable($share);
$message_t = $this->l->t('File is already shared with %s', [$shareWith]);
throw new \Exception($message_t);
}
@@ -216,7 +216,7 @@ class FederatedShareProvider implements IShareProvider, IShareProviderSupportsAl
}
if ($failure) {
$this->removeShareFromTable($shareId);
$this->removeShareFromTableById($shareId);
$message_t = $this->l->t('Sharing %1$s failed, could not find %2$s, maybe the server is currently unreachable or uses a self-signed certificate.',
[$share->getNode()->getName(), $share->getSharedWith()]);
throw new \Exception($message_t);
@@ -225,17 +225,45 @@ class FederatedShareProvider implements IShareProvider, IShareProviderSupportsAl
return $shareId;
}
/**
* @param string $shareWith
* @param IShare $share
* @param string $shareId internal share Id
* @return array
* @throws \Exception
*/
protected function askOwnerToReShare($shareWith, IShare $share, $shareId) {
$remoteShare = $this->getShareFromExternalShareTable($share);
$token = $remoteShare['share_token'];
$remoteId = $remoteShare['remote_id'];
$remote = $remoteShare['remote'];
[$token, $remoteId] = $this->notifications->requestReShare(
$token,
$remoteId,
$shareId,
$remote,
$shareWith,
$share->getPermissions(),
$share->getNode()->getName(),
$share->getShareType(),
);
return [$token, $remoteId];
}
/**
* get federated share from the share_external table but exclude mounted link shares
*
* @param IShare $share
* @return array
* @throws ShareNotFound
*/
protected function getShareFromExternalShareTable(string $owner, string $target) {
protected function getShareFromExternalShareTable(IShare $share) {
$query = $this->dbConnection->getQueryBuilder();
$query->select('*')->from($this->externalShareTable)
->where($query->expr()->eq('user', $query->createNamedParameter($owner)))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($target)));
->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
$qResult = $query->executeQuery();
$result = $qResult->fetchAllAssociative();
$qResult->closeCursor();
@@ -440,7 +468,7 @@ class FederatedShareProvider implements IShareProvider, IShareProviderSupportsAl
// only remove the share when all messages are send to not lose information
// about the share to early
$this->removeShareFromTable($share->getId());
$this->removeShareFromTable($share);
}
/**
@@ -465,10 +493,19 @@ class FederatedShareProvider implements IShareProvider, IShareProviderSupportsAl
}
}
/**
* remove share from table
*
* @param IShare $share
*/
public function removeShareFromTable(IShare $share) {
$this->removeShareFromTableById($share->getId());
}
/**
* Remove share from table.
*/
public function removeShareFromTable(string $shareId): void {
private function removeShareFromTableById(string $shareId): void {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)))
@@ -382,7 +382,7 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
* @throws ShareNotFound
*/
protected function executeDeclineShare(IShare $share): void {
$this->federatedShareProvider->removeShareFromTable($share->getId());
$this->federatedShareProvider->removeShareFromTable($share);
$user = $this->getCorrectUser($share);
@@ -420,7 +420,7 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
$share = $this->federatedShareProvider->getShareById($id);
$this->verifyShare($share, $token);
$this->federatedShareProvider->removeShareFromTable($share->getId());
$this->federatedShareProvider->removeShareFromTable($share);
return [];
}
@@ -249,18 +249,18 @@ class FederatedShareProviderReshareRemoteTest extends \Test\TestCase {
$qb6->method('executeQuery')->willReturn($result6);
$queryBuilderMatcher = $this->exactly(7);
$queryBuilderMatcher = $this->exactly(8);
$this->connection
->expects($queryBuilderMatcher)
->method('getQueryBuilder')
->willReturnCallback(function () use ($queryBuilderMatcher, $qb1, $qb2, $qb3, $qb4, $qb5, $qb6) {
return match ($queryBuilderMatcher->numberOfInvocations()) {
1, 2 => $qb1,
3 => $qb2,
3, 5 => $qb2,
4 => $qb3,
5 => $qb4,
6 => $qb5,
7 => $qb6,
6 => $qb4,
7 => $qb5,
8 => $qb6,
default => throw new LogicException('Unexpected number of invocations for getQueryBuilder')
};
});
@@ -133,8 +133,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setExpirationDate($expirationDate)
->setNode($node)
->setTarget('');
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -216,8 +215,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -270,8 +268,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -362,8 +359,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -435,8 +431,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setExpirationDate(new \DateTime('2019-02-01T01:02:03'))
->setNode($node)
->setTarget('');
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->addressHandler->expects($this->any())->method('generateRemoteURL')
@@ -509,8 +504,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share);
$share2 = $this->shareManager->newShare();
@@ -519,8 +513,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('sharedBy', IShare::TYPE_REMOTE, null, false, -1, 0);
@@ -555,8 +548,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share);
$node2 = $this->getMockBuilder(File::class)->getMock();
@@ -569,8 +561,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node2)
->setTarget('');
->setNode($node2);
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('sharedBy', IShare::TYPE_REMOTE, $node2, false, -1, 0);
@@ -604,8 +595,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share);
$share2 = $this->shareManager->newShare();
@@ -614,8 +604,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_REMOTE, null, true, -1, 0);
@@ -656,8 +645,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share);
$share2 = $this->shareManager->newShare();
@@ -666,8 +654,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node)
->setTarget('');
->setNode($node);
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_REMOTE, null, true, 1, 1);
@@ -848,8 +835,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1)
->setTarget('');
->setNode($file1);
$this->provider->create($share1);
$share2 = $this->shareManager->newShare();
@@ -858,8 +844,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file2)
->setTarget('');
->setNode($file2);
$this->provider->create($share2);
$result = $this->provider->getSharesInFolder($u1->getUID(), $folder1, false);
@@ -910,8 +895,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1)
->setTarget('');
->setNode($file1);
$this->provider->create($share1);
$share2 = $this->shareManager->newShare();
@@ -920,8 +904,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1)
->setTarget('');
->setNode($file1);
$this->provider->create($share2);
$result = $this->provider->getAccessList([$file1], true);
-4
View File
@@ -122,7 +122,6 @@ OC.L10N.register(
"General" : "Yleiset",
"Sort favorites first" : "Järjestä suosikit ensiksi",
"Sort folders before files" : "Järjestä kansiot ennen tiedostoja",
"Enable folder tree view" : "Käytä kansiopuunäkymää",
"Default view" : "Oletusnäkymä",
"All files" : "Kaikki tiedostot",
"Personal files" : "Henkilökohtaiset tiedostot",
@@ -132,8 +131,6 @@ OC.L10N.register(
"Selection" : "Valinta",
"Select all files" : "Valitse kaikki tiedostot",
"Deselect all" : "Poista valinnat",
"Select or deselect" : "Valitse tai poista valinta",
"Select a range" : "Valitse väliltä",
"Navigation" : "Navigointi",
"Go to parent folder" : "Siirry ylätason kansioon",
"Go to file above" : "Siirry yllä olevaan tiedostoon",
@@ -142,7 +139,6 @@ OC.L10N.register(
"Go right in grid" : "Siirry oikealle ruudukossa",
"View" : "Näytä",
"Toggle grid view" : "Ruudukkonäkymä päälle/pois",
"Show those shortcuts" : "Näytä pikanäppäimet",
"Warnings" : "Varoitukset",
"Warn before changing a file extension" : "Varoita ennen tiedostopäätteen muuttamista",
"Warn before deleting a file" : "Varoita ennen tiedoston poistamista",
-4
View File
@@ -120,7 +120,6 @@
"General" : "Yleiset",
"Sort favorites first" : "Järjestä suosikit ensiksi",
"Sort folders before files" : "Järjestä kansiot ennen tiedostoja",
"Enable folder tree view" : "Käytä kansiopuunäkymää",
"Default view" : "Oletusnäkymä",
"All files" : "Kaikki tiedostot",
"Personal files" : "Henkilökohtaiset tiedostot",
@@ -130,8 +129,6 @@
"Selection" : "Valinta",
"Select all files" : "Valitse kaikki tiedostot",
"Deselect all" : "Poista valinnat",
"Select or deselect" : "Valitse tai poista valinta",
"Select a range" : "Valitse väliltä",
"Navigation" : "Navigointi",
"Go to parent folder" : "Siirry ylätason kansioon",
"Go to file above" : "Siirry yllä olevaan tiedostoon",
@@ -140,7 +137,6 @@
"Go right in grid" : "Siirry oikealle ruudukossa",
"View" : "Näytä",
"Toggle grid view" : "Ruudukkonäkymä päälle/pois",
"Show those shortcuts" : "Näytä pikanäppäimet",
"Warnings" : "Varoitukset",
"Warn before changing a file extension" : "Varoita ennen tiedostopäätteen muuttamista",
"Warn before deleting a file" : "Varoita ennen tiedoston poistamista",
@@ -104,7 +104,10 @@ class DeleteOrphanedFilesTest extends TestCase {
$this->assertEquals(1, $this->getMountsCount($numericStorageId), 'Asserts that mount is still available');
$deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]);
$qb = $this->connection->getQueryBuilder();
$deletedRows = $qb->delete('storages')
->where($qb->expr()->eq('id', $qb->createNamedParameter($storageId)))
->executeStatement();
$this->assertNotNull($deletedRows, 'Asserts that storage got deleted');
$this->assertSame(1, $deletedRows, 'Asserts that storage got deleted');
-3
View File
@@ -165,7 +165,6 @@ OC.L10N.register(
"Unshare" : "Lopeta jakaminen",
"Cannot copy, please copy the link manually" : "Kopioiminen ei onnistu. Kopioi linkki manuaalisesti",
"Copy internal link" : "Kopioi sisäinen linkki",
"For people who already have access" : "Henkilöille, joilla on jo käyttöoikeus",
"Internal link" : "Sisäinen linkki",
"Shared via link by {initiator}" : "Jaettu linkin kautta käyttäjältä {initiator}",
"File request ({label})" : "Tiedostopyyntö ({label})",
@@ -248,7 +247,6 @@ OC.L10N.register(
"Toggle list of others with access to this directory" : "Vaihda näkymää kansioon käyttöoikeuden omaavista käyttäjistä",
"Toggle list of others with access to this file" : "Vaihda näkymää tiedostoon käyttöoikeuden omaavista käyttäjistä",
"Shares" : "Jaot",
"Shares from apps or other sources which are not included in internal or external shares." : "Jaot muista sovelluksista tai lähteistä, jotka eivät sisälly sisäisiin tai ulkoisiin jakoihin.",
"Type names or teams" : "Kirjoita nimet tai tiimit",
"Type an email" : "Kirjoita sähköpostiosoite",
"Unable to load the shares list" : "Jakolistan haku epäonnistui",
@@ -257,7 +255,6 @@ OC.L10N.register(
"Shared with you by {owner}" : "{owner} jakoi tämän kanssasi",
"Internal shares" : "Sisäiset jaot",
"External shares" : "Ulkoiset jaot",
"Additional shares" : "Muut jaot",
"Link to a file" : "Linkki tiedostoon",
"_Accept share_::_Accept shares_" : ["Hyväksy jako","Hyväksy jaot"],
"Open in Files" : "Avaa tiedostosovelluksessa",
-3
View File
@@ -163,7 +163,6 @@
"Unshare" : "Lopeta jakaminen",
"Cannot copy, please copy the link manually" : "Kopioiminen ei onnistu. Kopioi linkki manuaalisesti",
"Copy internal link" : "Kopioi sisäinen linkki",
"For people who already have access" : "Henkilöille, joilla on jo käyttöoikeus",
"Internal link" : "Sisäinen linkki",
"Shared via link by {initiator}" : "Jaettu linkin kautta käyttäjältä {initiator}",
"File request ({label})" : "Tiedostopyyntö ({label})",
@@ -246,7 +245,6 @@
"Toggle list of others with access to this directory" : "Vaihda näkymää kansioon käyttöoikeuden omaavista käyttäjistä",
"Toggle list of others with access to this file" : "Vaihda näkymää tiedostoon käyttöoikeuden omaavista käyttäjistä",
"Shares" : "Jaot",
"Shares from apps or other sources which are not included in internal or external shares." : "Jaot muista sovelluksista tai lähteistä, jotka eivät sisälly sisäisiin tai ulkoisiin jakoihin.",
"Type names or teams" : "Kirjoita nimet tai tiimit",
"Type an email" : "Kirjoita sähköpostiosoite",
"Unable to load the shares list" : "Jakolistan haku epäonnistui",
@@ -255,7 +253,6 @@
"Shared with you by {owner}" : "{owner} jakoi tämän kanssasi",
"Internal shares" : "Sisäiset jaot",
"External shares" : "Ulkoiset jaot",
"Additional shares" : "Muut jaot",
"Link to a file" : "Linkki tiedostoon",
"_Accept share_::_Accept shares_" : ["Hyväksy jako","Hyväksy jaot"],
"Open in Files" : "Avaa tiedostosovelluksessa",
@@ -70,7 +70,7 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase {
$this->connection = Server::get(IDBConnection::class);
// clear occasional leftover shares from other tests
$this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->connection->getQueryBuilder()->delete('share')->executeStatement();
$this->user1 = $this->getUniqueID('user1_');
$this->user2 = $this->getUniqueID('user2_');
@@ -85,7 +85,7 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase {
}
protected function tearDown(): void {
$this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->connection->getQueryBuilder()->delete('share')->executeStatement();
$userManager = Server::get(IUserManager::class);
$user1 = $userManager->get($this->user1);
@@ -104,7 +104,10 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase {
private function getShares() {
$shares = [];
$result = $this->connection->executeQuery('SELECT * FROM `*PREFIX*share`');
$result = $this->connection->getQueryBuilder()
->select('*')
->from('share')
->executeQuery();
while ($row = $result->fetchAssociative()) {
$shares[] = $row;
}
@@ -51,7 +51,7 @@ class SharesReminderJobTest extends \Test\TestCase {
$this->mailer = $this->createMock(IMailer::class);
// Clear occasional leftover shares from other tests
$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->db->getQueryBuilder()->delete('share')->executeStatement();
$this->user1 = $this->getUniqueID('user1_');
$this->user2 = $this->getUniqueID('user2_');
@@ -78,7 +78,7 @@ class SharesReminderJobTest extends \Test\TestCase {
}
protected function tearDown(): void {
$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->db->getQueryBuilder()->delete('share')->executeStatement();
$userManager = Server::get(IUserManager::class);
$user1 = $userManager->get($this->user1);
+1 -1
View File
@@ -144,7 +144,7 @@ class TrashbinTest extends \Test\TestCase {
// clear trash table
$connection = Server::get(IDBConnection::class);
$connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`');
$connection->getQueryBuilder()->delete('files_trash')->executeStatement();
parent::tearDown();
}
+1 -1
View File
@@ -4,7 +4,7 @@ OC.L10N.register(
"Profile" : "Profil",
"This application provides the profile" : "Denne applikation leverer profilen",
"Provides a customisable user profile interface." : "Leverer en brugerdefinerbar brugerprofil grænseflade.",
"Searching …" : "Søger …",
"Searching …" : "Søger ...",
"Not found" : "Ikke fundet",
"Insert" : "Indsæt",
"You have not added any info yet" : "Du har ikke tilføjet nogen information endnu",
+1 -1
View File
@@ -2,7 +2,7 @@
"Profile" : "Profil",
"This application provides the profile" : "Denne applikation leverer profilen",
"Provides a customisable user profile interface." : "Leverer en brugerdefinerbar brugerprofil grænseflade.",
"Searching …" : "Søger …",
"Searching …" : "Søger ...",
"Not found" : "Ikke fundet",
"Insert" : "Indsæt",
"You have not added any info yet" : "Du har ikke tilføjet nogen information endnu",
+35 -44
View File
@@ -8,7 +8,6 @@
namespace OCA\User_LDAP\Mapping;
use Doctrine\DBAL\Exception;
use OCP\DB\IPreparedStatement;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IAppConfig;
use OCP\ICache;
@@ -154,23 +153,6 @@ abstract class AbstractMapping {
}
}
/**
* Performs a DELETE or UPDATE query to the database.
*
* @param IPreparedStatement $statement
* @param array $parameters
* @return bool true if at least one row was modified, false otherwise
*/
protected function modify(IPreparedStatement $statement, $parameters) {
try {
$result = $statement->execute($parameters);
$updated = $result->rowCount() > 0;
$result->closeCursor();
return $updated;
} catch (Exception $e) {
return false;
}
}
/**
* Gets the LDAP DN based on the provided name.
@@ -199,13 +181,16 @@ abstract class AbstractMapping {
*/
public function setDNbyUUID($fdn, $uuid) {
$oldDn = $this->getDnByUUID($uuid);
$statement = $this->dbc->prepare('
UPDATE `' . $this->getTableName() . '`
SET `ldap_dn_hash` = ?, `ldap_dn` = ?
WHERE `directory_uuid` = ?
');
$r = $this->modify($statement, [$this->getDNHash($fdn), $fdn, $uuid]);
$qb = $this->dbc->getQueryBuilder();
try {
$r = $qb->update($this->getTableName(false))
->set('ldap_dn_hash', $qb->createNamedParameter($this->getDNHash($fdn)))
->set('ldap_dn', $qb->createNamedParameter($fdn))
->where($qb->expr()->eq('directory_uuid', $qb->createNamedParameter($uuid)))
->executeStatement() > 0;
} catch (Exception $e) {
$r = false;
}
if ($r) {
if (is_string($oldDn) && isset($this->cache[$oldDn])) {
$userId = $this->cache[$oldDn];
@@ -231,15 +216,17 @@ abstract class AbstractMapping {
* @return bool
*/
public function setUUIDbyDN($uuid, $fdn): bool {
$statement = $this->dbc->prepare('
UPDATE `' . $this->getTableName() . '`
SET `directory_uuid` = ?
WHERE `ldap_dn_hash` = ?
');
unset($this->cache[$fdn]);
return $this->modify($statement, [$uuid, $this->getDNHash($fdn)]);
$qb = $this->dbc->getQueryBuilder();
try {
return $qb->update($this->getTableName(false))
->set('directory_uuid', $qb->createNamedParameter($uuid))
->where($qb->expr()->eq('ldap_dn_hash', $qb->createNamedParameter($this->getDNHash($fdn))))
->executeStatement() > 0;
} catch (Exception $e) {
return false;
}
}
/**
@@ -333,14 +320,14 @@ abstract class AbstractMapping {
* @return string[]
*/
public function getNamesBySearch(string $search, string $prefixMatch = '', string $postfixMatch = ''): array {
$statement = $this->dbc->prepare('
SELECT `owncloud_name`
FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` LIKE ?
');
$qb = $this->dbc->getQueryBuilder();
try {
$res = $statement->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]);
$res = $qb->select('owncloud_name')
->from($this->getTableName(false))
->where($qb->expr()->like('owncloud_name', $qb->createNamedParameter(
$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch
)))
->executeQuery();
} catch (Exception $e) {
return [];
}
@@ -348,6 +335,7 @@ abstract class AbstractMapping {
while ($row = $res->fetchAssociative()) {
$names[] = $row['owncloud_name'];
}
$res->closeCursor();
return $names;
}
@@ -443,17 +431,20 @@ abstract class AbstractMapping {
* @return bool
*/
public function unmap($name) {
$statement = $this->dbc->prepare('
DELETE FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` = ?');
$dn = array_search($name, $this->cache, true);
if ($dn !== false) {
unset($this->cache[$dn]);
}
$this->localNameToDnCache?->remove($name);
return $this->modify($statement, [$name]);
$qb = $this->dbc->getQueryBuilder();
try {
return $qb->delete($this->getTableName(false))
->where($qb->expr()->eq('owncloud_name', $qb->createNamedParameter($name)))
->executeStatement() > 0;
} catch (Exception $e) {
return false;
}
}
/**
-1
View File
@@ -204,7 +204,6 @@ OC.L10N.register(
"Search people" : "Etsi ihmisiä",
"People" : "Ihmiset",
"Filter in current view" : "Suodata nykyisessä näkymässä",
"Search connected services" : "Etsi liitetyistä palveluista",
"Results" : "Tulokset",
"Load more results" : "Lataa lisää tuloksia",
"Search in" : "Etsi kohteesta",
-1
View File
@@ -202,7 +202,6 @@
"Search people" : "Etsi ihmisiä",
"People" : "Ihmiset",
"Filter in current view" : "Suodata nykyisessä näkymässä",
"Search connected services" : "Etsi liitetyistä palveluista",
"Results" : "Tulokset",
"Load more results" : "Lataa lisää tuloksia",
"Search in" : "Etsi kohteesta",
+2 -2
View File
@@ -269,7 +269,7 @@ class OC {
$result = $qb->select($qb->func()->count('*', 'user_count'))
->from('ldap_user_mapping')
->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
$tooBig = ($row['user_count'] > 50);
@@ -280,7 +280,7 @@ class OC {
$result = $qb->select($qb->func()->count('*', 'user_count'))
->from('user_saml_users')
->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
$tooBig = ($row['user_count'] > 50);
+2 -2
View File
@@ -197,7 +197,7 @@ class AccountManager implements IAccountManager {
->where($query->expr()->eq('uid', $query->createParameter('uid')))
->setParameter('uid', $uid);
$result = $query->executeQuery();
$accountData = $result->fetchAll();
$accountData = $result->fetchAllAssociative();
$result->closeCursor();
if (empty($accountData)) {
@@ -233,7 +233,7 @@ class AccountManager implements IAccountManager {
$query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$matches[$row['uid']] = $row['value'];
}
$result->closeCursor();
+1 -1
View File
@@ -1360,7 +1360,7 @@ class AppConfig implements IAppConfig {
}
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
foreach ($rows as $row) {
// most of the time, 'lazy' is not in the select because its value is already known
if ($lazy && ((int)$row['lazy']) === 1) {
@@ -14,7 +14,6 @@ use OC\AppFramework\Middleware\Security\Exceptions\AppNotEnabledException;
use OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException;
use OC\AppFramework\Middleware\Security\Exceptions\ExAppRequiredException;
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
use OC\AppFramework\Middleware\Security\Exceptions\NotConfirmedException;
use OC\AppFramework\Middleware\Security\Exceptions\NotLoggedInException;
use OC\AppFramework\Middleware\Security\Exceptions\SecurityException;
use OC\AppFramework\Middleware\Security\Exceptions\StrictCookieMissingException;
@@ -281,9 +280,6 @@ class SecurityMiddleware extends Middleware {
}
}
if ($exception instanceof NotConfirmedException) {
$response->addHeader('X-NC-Auth-NotConfirmed', 'true');
}
$this->logger->debug($exception->getMessage(), [
'exception' => $exception,
]);
@@ -75,7 +75,7 @@ class PublicKeyTokenMapper extends QBMapper {
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data === false) {
throw new DoesNotExistException('token does not exist');
@@ -97,7 +97,7 @@ class PublicKeyTokenMapper extends QBMapper {
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data === false) {
throw new DoesNotExistException('token does not exist');
@@ -123,7 +123,7 @@ class PublicKeyTokenMapper extends QBMapper {
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->setMaxResults(1000);
$result = $qb->executeQuery();
$data = $result->fetchAll();
$data = $result->fetchAllAssociative();
$result->closeCursor();
$entities = array_map(function ($row) {
@@ -178,7 +178,7 @@ class PublicKeyTokenMapper extends QBMapper {
->setMaxResults(1);
$cursor = $qb->executeQuery();
$data = $cursor->fetchAll();
$data = $cursor->fetchAllAssociative();
$cursor->closeCursor();
return count($data) === 1;
@@ -242,7 +242,7 @@ class PublicKeyTokenMapper extends QBMapper {
->orderBy('id');
$result = $qb->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data === false) {
return null;
@@ -37,7 +37,7 @@ class ProviderUserAssignmentDao {
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
$result = $query->executeQuery();
$providers = [];
foreach ($result->fetchAll() as $row) {
foreach ($result->fetchAllAssociative() as $row) {
$providers[(string)$row['provider_id']] = (int)$row['enabled'] === 1;
}
$result->closeCursor();
@@ -80,7 +80,7 @@ class ProviderUserAssignmentDao {
->from(self::TABLE_NAME)
->where($qb1->expr()->eq('uid', $qb1->createNamedParameter($uid)));
$selectResult = $selectQuery->executeQuery();
$rows = $selectResult->fetchAll();
$rows = $selectResult->fetchAllAssociative();
$selectResult->closeCursor();
$qb2 = $this->conn->getQueryBuilder();
+6 -6
View File
@@ -129,7 +129,7 @@ class JobList implements IJobList {
->setMaxResults(1);
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
return (bool)$row;
@@ -158,7 +158,7 @@ class JobList implements IJobList {
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$job = $this->buildJob($row);
if ($job) {
yield $job;
@@ -190,7 +190,7 @@ class JobList implements IJobList {
}
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row) {
@@ -293,7 +293,7 @@ class JobList implements IJobList {
->from('jobs')
->where($query->expr()->eq('id', $query->createNamedParameter($id)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row) {
@@ -407,7 +407,7 @@ class JobList implements IJobList {
try {
$result = $query->executeQuery();
$hasReservedJobs = $result->fetch() !== false;
$hasReservedJobs = $result->fetchAssociative() !== false;
$result->closeCursor();
return $hasReservedJobs;
} catch (Exception $e) {
@@ -429,7 +429,7 @@ class JobList implements IJobList {
$jobs = [];
while (($row = $result->fetch()) !== false) {
while (($row = $result->fetchAssociative()) !== false) {
/**
* @var array{count:int, class:class-string<IJob>} $row
*/
@@ -344,7 +344,7 @@ class ResourcesRoomsUpdater {
->from($table)
->where($query->expr()->eq($foreignKey, $query->createNamedParameter($id)));
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$result->closeCursor();
$metadata = [];
@@ -370,7 +370,7 @@ class ResourcesRoomsUpdater {
->from($tableName)
->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId)));
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$result->closeCursor();
return array_map(function ($row): string {
@@ -130,7 +130,7 @@ readonly class UserPlugin implements ISearchPlugin {
->where($qb->expr()->eq($qb->func()->lower('value'), $qb->createNamedParameter($lowerSearch)))
->andWhere($qb->expr()->in('name', $qb->createNamedParameter(['email', 'additional_mail'], IQueryBuilder::PARAM_STR_ARRAY)));
$result = $qb->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$uid = $row['uid'];
$email = $row['value'];
$isAdditional = $row['name'] === 'additional_mail';
@@ -46,7 +46,7 @@ class Manager implements IManager {
->from(self::TABLE_COLLECTIONS)
->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if (!$row) {
@@ -75,7 +75,7 @@ class Manager implements IManager {
)
->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if (!$row) {
@@ -120,7 +120,7 @@ class Manager implements IManager {
$collections = [];
$foundResults = 0;
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$foundResults++;
$access = $row['access'] === null ? null : (bool)$row['access'];
$collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
@@ -179,7 +179,7 @@ class Manager implements IManager {
->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR)))
->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if (!$row) {
@@ -216,7 +216,7 @@ class Manager implements IManager {
$resources = [];
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$access = $row['access'] === null ? null : (bool)$row['access'];
$resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access);
}
@@ -310,7 +310,7 @@ class Manager implements IManager {
$hasAccess = null;
$result = $query->executeQuery();
if ($row = $result->fetch()) {
if ($row = $result->fetchAssociative()) {
$hasAccess = (bool)$row['access'];
}
$result->closeCursor();
@@ -330,7 +330,7 @@ class Manager implements IManager {
$hasAccess = null;
$result = $query->executeQuery();
if ($row = $result->fetch()) {
if ($row = $result->fetchAssociative()) {
$hasAccess = (bool)$row['access'];
}
$result->closeCursor();
@@ -103,7 +103,7 @@ class Resource implements IResource {
->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId())));
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$collections[] = $this->manager->getCollection((int)$row['collection_id']);
}
$result->closeCursor();
+16 -16
View File
@@ -180,7 +180,7 @@ class Manager implements ICommentsManager {
->setParameter('id', $id);
$resultStatement = $query->executeQuery();
$data = $resultStatement->fetch(\PDO::FETCH_NUM);
$data = $resultStatement->fetchNumeric();
$resultStatement->closeCursor();
$children = (int)$data[0];
@@ -255,7 +255,7 @@ class Manager implements ICommentsManager {
->setParameter('id', $id, IQueryBuilder::PARAM_INT)
->executeQuery();
$data = $resultStatement->fetch();
$data = $resultStatement->fetchAssociative();
$resultStatement->closeCursor();
if (!$data) {
throw new NotFoundException();
@@ -290,7 +290,7 @@ class Manager implements ICommentsManager {
}
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetch()) {
while ($data = $resultStatement->fetchAssociative()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$tree['replies'][] = [
@@ -349,7 +349,7 @@ class Manager implements ICommentsManager {
}
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetch()) {
while ($data = $resultStatement->fetchAssociative()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
@@ -511,7 +511,7 @@ class Manager implements ICommentsManager {
}
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetch()) {
while ($data = $resultStatement->fetchAssociative()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
@@ -537,7 +537,7 @@ class Manager implements ICommentsManager {
->andWhere($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row) {
@@ -609,7 +609,7 @@ class Manager implements ICommentsManager {
$comments = [];
$result = $query->executeQuery();
while ($data = $result->fetch()) {
while ($data = $result->fetchAssociative()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
@@ -653,7 +653,7 @@ class Manager implements ICommentsManager {
$query->groupBy('object_id');
$comments = array_fill_keys($objectIds, 0);
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetch()) {
while ($data = $resultStatement->fetchAssociative()) {
$comments[$data['object_id']] = (int)$data['num_comments'];
}
$resultStatement->closeCursor();
@@ -697,7 +697,7 @@ class Manager implements ICommentsManager {
$query->setParameter('ids', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$unreadComments[$row['object_id']] = (int)$row['num_comments'];
}
$result->closeCursor();
@@ -743,7 +743,7 @@ class Manager implements ICommentsManager {
}
$result = $query->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
return (int)($data['num_messages'] ?? 0);
@@ -771,7 +771,7 @@ class Manager implements ICommentsManager {
}
$result = $query->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
return (int)($data['id'] ?? 0);
@@ -808,7 +808,7 @@ class Manager implements ICommentsManager {
->groupBy('actor_id');
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$lastComments[$row['actor_id']] = $this->timeFactory->getDateTime($row['last_comment']);
}
$result->closeCursor();
@@ -976,7 +976,7 @@ class Manager implements ICommentsManager {
->executeQuery();
$commentIds = [];
while ($data = $result->fetch()) {
while ($data = $result->fetchAssociative()) {
$commentIds[] = $data['message_id'];
}
@@ -1006,7 +1006,7 @@ class Manager implements ICommentsManager {
->executeQuery();
$commentIds = [];
while ($data = $result->fetch()) {
while ($data = $result->fetchAssociative()) {
$commentIds[] = $data['message_id'];
}
$comments = [];
@@ -1063,7 +1063,7 @@ class Manager implements ICommentsManager {
$query->setParameter('ids', $ids, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->executeQuery();
while ($data = $result->fetch()) {
while ($data = $result->fetchAssociative()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
@@ -1415,7 +1415,7 @@ class Manager implements ICommentsManager {
->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR)
->executeQuery();
$data = $resultStatement->fetch();
$data = $resultStatement->fetchAssociative();
$resultStatement->closeCursor();
if (!$data || is_null($data['marker_datetime'])) {
return null;
+4 -4
View File
@@ -102,7 +102,7 @@ class UserConfig implements IUserConfig {
}
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$userIds = [];
foreach ($rows as $row) {
$userIds[] = $row['userid'];
@@ -375,7 +375,7 @@ class UserConfig implements IUserConfig {
// this nested function will execute current Query and store result within $values.
$executeAndStoreValue = function (IQueryBuilder $qb) use (&$values, $typedAs): IResult {
$result = $qb->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$value = $row['configvalue'];
try {
$value = $this->convertTypedValue($value, $typedAs ?? ValueType::from((int)$row['type']));
@@ -535,7 +535,7 @@ class UserConfig implements IUserConfig {
$qb->andWhere($where);
$result = $qb->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
yield $row['userid'];
}
}
@@ -1773,7 +1773,7 @@ class UserConfig implements IUserConfig {
}
$result = $qb->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
foreach ($rows as $row) {
if (($row['lazy'] ?? ($lazy ?? 0) ? 1 : 0) === 1) {
$this->lazyCache[$userId][$row['appid']][$row['configkey']] = $row['configvalue'] ?? '';
+2 -2
View File
@@ -47,7 +47,7 @@ class Adapter {
*/
public function lockTable(string $tableName) {
$this->conn->beginTransaction();
$this->conn->executeUpdate('LOCK TABLE `' . $tableName . '` IN EXCLUSIVE MODE');
$this->conn->executeStatement('LOCK TABLE `' . $tableName . '` IN EXCLUSIVE MODE');
}
/**
@@ -99,7 +99,7 @@ class Adapter {
$query .= ' HAVING COUNT(*) = 0';
try {
return $this->conn->executeUpdate($query, $inserts);
return $this->conn->executeStatement($query, $inserts);
} catch (UniqueConstraintViolationException $e) {
// This exception indicates a concurrent insert happened between
// the insert and the sub-select in the insert, which is safe to ignore.
+2 -2
View File
@@ -15,11 +15,11 @@ class AdapterMySQL extends Adapter {
* @param string $tableName
*/
public function lockTable($tableName) {
$this->conn->executeUpdate('LOCK TABLES `' . $tableName . '` WRITE');
$this->conn->executeStatement('LOCK TABLES `' . $tableName . '` WRITE');
}
public function unlockTable() {
$this->conn->executeUpdate('UNLOCK TABLES');
$this->conn->executeStatement('UNLOCK TABLES');
}
public function fixupStatement($statement) {
+1 -1
View File
@@ -32,6 +32,6 @@ class AdapterPgSql extends Adapter {
$builder->setValue($key, $builder->createNamedParameter($value));
}
$queryString = $builder->getSQL() . ' ON CONFLICT DO NOTHING';
return $this->conn->executeUpdate($queryString, $builder->getParameters(), $builder->getParameterTypes());
return $this->conn->executeStatement($queryString, $builder->getParameters(), $builder->getParameterTypes());
}
}
+3 -3
View File
@@ -14,11 +14,11 @@ class AdapterSqlite extends Adapter {
* @param string $tableName
*/
public function lockTable($tableName) {
$this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION');
$this->conn->executeStatement('BEGIN EXCLUSIVE TRANSACTION');
}
public function unlockTable() {
$this->conn->executeUpdate('COMMIT TRANSACTION');
$this->conn->executeStatement('COMMIT TRANSACTION');
}
public function fixupStatement($statement) {
@@ -67,7 +67,7 @@ class AdapterSqlite extends Adapter {
$query .= ')';
try {
return $this->conn->executeUpdate($query, $inserts);
return $this->conn->executeStatement($query, $inserts);
} catch (UniqueConstraintViolationException $e) {
// if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it
// it's fine to ignore this then
+9 -16
View File
@@ -65,42 +65,35 @@ class ArrayResult implements IResult {
#[Override]
public function fetchOne() {
$row = $this->fetch();
if ($row) {
return current($row);
}
return false;
$row = array_shift($this->rows);
return $row !== null ? current($row) : false;
}
#[Override]
public function fetchAssociative(): array|false {
$row = $this->fetch();
if ($row) {
return $row;
}
return false;
$row = array_shift($this->rows);
return $row !== null ? $row : false;
}
#[Override]
public function fetchNumeric(): array|false {
return $this->fetch(PDO::FETCH_NUM);
$row = array_shift($this->rows);
return $row !== null ? array_values($row) : false;
}
#[Override]
public function fetchAllNumeric(): array {
return $this->fetchAll(PDO::FETCH_NUM);
return array_map(static fn (array $row): array => array_values($row), $this->rows);
}
#[Override]
public function fetchAllAssociative(): array {
return $this->fetchAll();
return $this->rows;
}
#[Override]
public function fetchFirstColumn(): array {
return $this->fetchAll(PDO::FETCH_COLUMN);
return array_map(static fn (array $row): mixed => current($row), $this->rows);
}
#[Override]
+1 -1
View File
@@ -59,7 +59,7 @@ class ConnectionAdapter implements IDBConnection {
public function executeUpdate(string $sql, array $params = [], array $types = []): int {
try {
return $this->inner->executeUpdate($sql, $params, $types);
return $this->inner->executeStatement($sql, $params, $types);
} catch (Exception $e) {
throw DbalException::wrap($e, '', $sql);
}
+1 -1
View File
@@ -173,7 +173,7 @@ class MigrationService {
->orderBy('version');
$result = $qb->executeQuery();
$rows = $result->fetchAll(\PDO::FETCH_COLUMN);
$rows = $result->fetchFirstColumn();
$result->closeCursor();
usort($rows, $this->sortMigrations(...));
+2 -2
View File
@@ -25,7 +25,7 @@ class MySqlTools {
foreach ($variables as $var => $val) {
$result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'");
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row === false) {
return false;
@@ -39,7 +39,7 @@ class MySqlTools {
protected function isMariaDBWithLargePrefix(IDBConnection $connection) {
$result = $connection->executeQuery('SELECT VERSION()');
$row = strtolower($result->fetchColumn());
$row = strtolower($result->fetchOne());
$result->closeCursor();
if ($row === false) {
+13 -3
View File
@@ -42,11 +42,21 @@ class PreparedStatement implements IPreparedStatement {
}
public function fetch(int $fetchMode = PDO::FETCH_ASSOC) {
return $this->getResult()->fetch($fetchMode);
return match ($fetchMode) {
PDO::FETCH_ASSOC => $this->getResult()->fetchAssociative(),
PDO::FETCH_NUM => $this->getResult()->fetchNumeric(),
PDO::FETCH_COLUMN => $this->getResult()->fetchOne(),
default => $this->getResult()->fetch($fetchMode),
};
}
public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array {
return $this->getResult()->fetchAll($fetchMode);
return match ($fetchMode) {
PDO::FETCH_ASSOC => $this->getResult()->fetchAllAssociative(),
PDO::FETCH_NUM => $this->getResult()->fetchAllNumeric(),
PDO::FETCH_COLUMN => $this->getResult()->fetchFirstColumn(),
default => $this->getResult()->fetchAll($fetchMode),
};
}
public function fetchColumn() {
@@ -66,7 +76,7 @@ class PreparedStatement implements IPreparedStatement {
}
public function execute($params = null): IResult {
return ($this->result = new ResultAdapter($this->statement->execute($params)));
return ($this->result = new ResultAdapter($this->statement->execute($params ?? [])));
}
public function rowCount(): int {
@@ -49,7 +49,7 @@ class PartitionQuery {
$this->query->andWhere($this->query->expr()->in($this->joinToColumn, $this->query->createNamedParameter($joinFromValues, IQueryBuilder::PARAM_STR_ARRAY, ':' . uniqid())));
$s = $this->query->getSQL();
$partitionedRows = $this->query->executeQuery()->fetchAll();
$partitionedRows = $this->query->executeQuery()->fetchAllAssociative();
$columns = $this->query->getOutputColumns();
$nullResult = array_combine($columns, array_fill(0, count($columns), null));
@@ -43,6 +43,36 @@ class PartitionedResult extends ArrayResult {
return parent::fetchAll($fetchMode);
}
public function fetchAssociative(): array|false {
$this->fetchRows();
return parent::fetchAssociative();
}
public function fetchNumeric(): array|false {
$this->fetchRows();
return parent::fetchNumeric();
}
public function fetchOne(): mixed {
$this->fetchRows();
return parent::fetchOne();
}
public function fetchAllAssociative(): array {
$this->fetchRows();
return parent::fetchAllAssociative();
}
public function fetchAllNumeric(): array {
$this->fetchRows();
return parent::fetchAllNumeric();
}
public function fetchFirstColumn(): array {
$this->fetchRows();
return parent::fetchFirstColumn();
}
public function rowCount(): int {
$this->fetchRows();
return parent::rowCount();
@@ -51,7 +81,7 @@ class PartitionedResult extends ArrayResult {
private function fetchRows(): void {
if (!$this->fetched) {
$this->fetched = true;
$this->rows = $this->result->fetchAll();
$this->rows = $this->result->fetchAllAssociative();
foreach ($this->splitOfParts as $part) {
$this->rows = $part->mergeWith($this->rows);
}
@@ -90,7 +90,7 @@ class CrossShardMoveHelper {
$results = [];
foreach ($chunks as $chunk) {
$query->setParameter('keys', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$results = array_merge($results, $query->executeQuery()->fetchAll());
$results = array_merge($results, $query->executeQuery()->fetchAllAssociative());
}
return $results;
@@ -138,7 +138,7 @@ class CrossShardMoveHelper {
$query->update($table)
->set($shardColumn, $query->createNamedParameter($targetShardKey, IQueryBuilder::PARAM_INT))
->where($query->expr()->in($primaryColumn, $query->createNamedParameter($primaryKeys, IQueryBuilder::PARAM_INT_ARRAY)));
$query->executeQuery()->fetchAll();
$query->executeQuery()->fetchAllAssociative();
}
/**
@@ -104,7 +104,7 @@ class ShardQueryRunner {
foreach ($shards as $shard) {
$shardConnection = $this->shardConnectionManager->getConnection($this->shardDefinition, $shard);
$subResult = $query->executeQuery($shardConnection);
$results = array_merge($results, $subResult->fetchAll());
$results = array_merge($results, $subResult->fetchAllAssociative());
$subResult->closeCursor();
}
} else {
@@ -118,7 +118,7 @@ class ShardQueryRunner {
foreach ($shards as $shard) {
$shardConnection = $this->shardConnectionManager->getConnection($this->shardDefinition, $shard);
$subResult = $query->executeQuery($shardConnection);
$rows = $subResult->fetchAll();
$rows = $subResult->fetchAllAssociative();
$results = array_merge($results, $rows);
$subResult->closeCursor();
+2 -2
View File
@@ -23,8 +23,8 @@ class SQLiteSessionInit implements EventSubscriber {
public function postConnect(ConnectionEventArgs $args): void {
$sensitive = $this->caseSensitiveLike ? 'true' : 'false';
$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
$args->getConnection()->executeStatement('PRAGMA case_sensitive_like = ' . $sensitive);
$args->getConnection()->executeStatement('PRAGMA journal_mode = ' . $this->journalMode);
/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
$connection = $args->getConnection()->getWrappedConnection();
$pdo = $connection->getWrappedConnection();
+1 -2
View File
@@ -6,7 +6,6 @@
*/
namespace OC\DirectEditing;
use Doctrine\DBAL\FetchMode;
use OCA\Encryption\Util;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
@@ -198,7 +197,7 @@ class Manager implements IManager {
$query->select('*')->from(self::TABLE_TOKENS)
->where($query->expr()->eq('token', $query->createNamedParameter($token, IQueryBuilder::PARAM_STR)));
$result = $query->executeQuery();
if ($tokenRow = $result->fetch(FetchMode::ASSOCIATIVE)) {
if ($tokenRow = $result->fetchAssociative()) {
return new Token($this, $tokenRow);
}
throw new \RuntimeException('Failed to validate the token');
+6 -6
View File
@@ -136,7 +136,7 @@ class Cache implements ICache {
$query->whereStorageId($this->getNumericStorageId());
$result = $query->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data !== false) {
@@ -231,7 +231,7 @@ class Cache implements ICache {
$metadataQuery = $query->selectMetadata();
$result = $query->executeQuery();
$files = $result->fetchAll();
$files = $result->fetchAllAssociative();
$result->closeCursor();
return array_map(function (array $data) use ($metadataQuery): ICacheEntry {
@@ -858,7 +858,7 @@ class Cache implements ICache {
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($path) . '/%')));
return $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
return $query->executeQuery()->fetchFirstColumn();
}
/**
@@ -1038,7 +1038,7 @@ class Cache implements ICache {
}
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$result->closeCursor();
if ($rows) {
@@ -1112,7 +1112,7 @@ class Cache implements ICache {
->whereStorageId($this->getNumericStorageId());
$result = $query->executeQuery();
$files = $result->fetchAll(\PDO::FETCH_COLUMN);
$files = $result->fetchFirstColumn();
$result->closeCursor();
return array_map(function ($id) {
@@ -1185,7 +1185,7 @@ class Cache implements ICache {
->where($query->expr()->eq('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row) {
+10 -10
View File
@@ -49,7 +49,7 @@ class FileAccess implements IFileAccess {
$query->andWhere($query->expr()->eq('filecache.path_hash', $query->createNamedParameter(md5($path))));
$query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
$row = $query->executeQuery()->fetch();
$row = $query->executeQuery()->fetchAssociative();
return $row ? Cache::cacheEntryFromData($row, $this->mimeTypeLoader) : null;
}
@@ -79,7 +79,7 @@ class FileAccess implements IFileAccess {
$query = $this->getQuery()->selectFileCache();
$query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)));
$rows = $query->executeQuery()->fetchAll();
$rows = $query->executeQuery()->fetchAllAssociative();
return $this->rowsToEntries($rows);
}
@@ -94,7 +94,7 @@ class FileAccess implements IFileAccess {
$query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)));
$query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
$rows = $query->executeQuery()->fetchAll();
$rows = $query->executeQuery()->fetchAllAssociative();
return $this->rowsToEntries($rows);
}
@@ -105,7 +105,7 @@ class FileAccess implements IFileAccess {
->where($qb->expr()->eq('fileid', $qb->createNamedParameter($folderId, IQueryBuilder::PARAM_INT)));
$result = $qb->executeQuery();
/** @var array{path:string}|false $root */
$root = $result->fetch();
$root = $result->fetchAssociative();
$result->closeCursor();
if ($root === false) {
@@ -153,7 +153,7 @@ class FileAccess implements IFileAccess {
// If the filecache table is sharded we need to check with a separate query if the parent is encrypted
$rows = [];
do {
while (count($rows) < 1000 && ($row = $files->fetch())) {
while (count($rows) < 1000 && ($row = $files->fetchAssociative())) {
$rows[] = $row;
}
$parents = array_map(function ($row) {
@@ -165,7 +165,7 @@ class FileAccess implements IFileAccess {
$parentQuery->where($parentQuery->expr()->in('fileid', $parentQuery->createNamedParameter($parents, IQueryBuilder::PARAM_INT_ARRAY)));
$parentQuery->hintShardKey('storage', $storageId);
$result = $parentQuery->executeQuery();
$parentRows = $result->fetchAll();
$parentRows = $result->fetchAllAssociative();
$result->closeCursor();
$encryptedByFileId = array_column($parentRows, 'encrypted', 'fileid');
@@ -176,11 +176,11 @@ class FileAccess implements IFileAccess {
yield Cache::cacheEntryFromData($row, $this->mimeTypeLoader);
}
$rows = [];
} while ($rows[] = $files->fetch());
} while ($rows[] = $files->fetchAssociative());
} else {
while (
/** @var array */
$row = $files->fetch()
$row = $files->fetchAssociative()
) {
yield Cache::cacheEntryFromData($row, $this->mimeTypeLoader);
}
@@ -212,7 +212,7 @@ class FileAccess implements IFileAccess {
while (
/** @var array{storage_id:int, root_id:int,mount_provider_class:string} $row */
$row = $result->fetch()
$row = $result->fetchAssociative()
) {
$storageId = (int)$row['storage_id'];
$rootId = (int)$row['root_id'];
@@ -232,7 +232,7 @@ class FileAccess implements IFileAccess {
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($rootId, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('path', $qb->createNamedParameter('files')));
/** @var array|false $root */
$root = $qb->executeQuery()->fetch();
$root = $qb->executeQuery()->fetchAssociative();
if ($root !== false) {
$overrideRoot = (int)$root['fileid'];
}
@@ -91,7 +91,7 @@ class QuerySearchHelper {
$result = $query->executeQuery();
/** @var list<array{id: int, name: string, visibility: int, editable: int, ref_file_id: int, number_files: int}> $tags */
$tags = $result->fetchAll();
$tags = $result->fetchAllAssociative();
$result->closeCursor();
return $tags;
}
@@ -172,7 +172,7 @@ class QuerySearchHelper {
$this->applySearchConstraints($query, $searchQuery, $caches, $metadataQuery);
$result = $query->executeQuery();
$files = $result->fetchAll();
$files = $result->fetchAllAssociative();
$rawEntries = array_map(function (array $data) use ($metadataQuery) {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
+1 -1
View File
@@ -174,7 +174,7 @@ class Storage {
$query->select('storage_id')
->from('mounts')
->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
$storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
$storageIds = $query->executeQuery()->fetchFirstColumn();
$storageIds = array_unique($storageIds);
$query = $db->getQueryBuilder();
+3 -3
View File
@@ -44,7 +44,7 @@ class StorageGlobal {
->where($builder->expr()->in('id', $builder->createNamedParameter(array_values($storageIds), IQueryBuilder::PARAM_STR_ARRAY)));
$result = $query->executeQuery();
while (($row = $result->fetch()) !== false) {
while (($row = $result->fetchAssociative()) !== false) {
$normalizedRow = [
'id' => (string)$row['id'],
'numeric_id' => (int)$row['numeric_id'],
@@ -69,7 +69,7 @@ class StorageGlobal {
->where($builder->expr()->eq('id', $builder->createNamedParameter($storageId)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row !== false) {
@@ -99,7 +99,7 @@ class StorageGlobal {
->where($builder->expr()->eq('numeric_id', $builder->createNamedParameter($numericId)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if ($row !== false) {
+46 -24
View File
@@ -7,8 +7,10 @@
*/
namespace OC\Files\Config;
use OC\DB\Exceptions\DbalException;
use OC\User\LazyUser;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
@@ -165,15 +167,25 @@ class UserMountCache implements IUserMountCache {
private function addToCache(ICachedMountInfo $mount) {
if ($mount->getStorageId() !== -1) {
$this->connection->insertIgnoreConflict('mounts', [
'storage_id' => $mount->getStorageId(),
'root_id' => $mount->getRootId(),
'user_id' => $mount->getUser()->getUID(),
'mount_point' => $mount->getMountPoint(),
'mount_point_hash' => hash('xxh128', $mount->getMountPoint()),
'mount_id' => $mount->getMountId(),
'mount_provider_class' => $mount->getMountProvider(),
]);
$qb = $this->connection->getQueryBuilder();
$qb
->insert('mounts')
->values([
'storage_id' => $qb->createNamedParameter($mount->getStorageId(), IQueryBuilder::PARAM_INT),
'root_id' => $qb->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT),
'user_id' => $qb->createNamedParameter($mount->getUser()->getUID()),
'mount_point' => $qb->createNamedParameter($mount->getMountPoint()),
'mount_point_hash' => $qb->createNamedParameter(hash('xxh128', $mount->getMountPoint())),
'mount_id' => $qb->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT),
'mount_provider_class' => $qb->createNamedParameter($mount->getMountProvider()),
]);
try {
$qb->executeStatement();
} catch (Exception $e) {
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}
}
} else {
// in some cases this is legitimate, like orphaned shares
$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
@@ -255,7 +267,7 @@ class UserMountCache implements IUserMountCache {
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userUID)));
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$result->closeCursor();
/** @var array<string, ICachedMountInfo> $mounts */
@@ -300,7 +312,7 @@ class UserMountCache implements IUserMountCache {
}
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$result->closeCursor();
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
@@ -318,7 +330,7 @@ class UserMountCache implements IUserMountCache {
->where($builder->expr()->eq('root_id', $builder->createNamedParameter($rootFileId, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$result->closeCursor();
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
@@ -337,7 +349,7 @@ class UserMountCache implements IUserMountCache {
->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if (is_array($row)) {
@@ -396,7 +408,7 @@ class UserMountCache implements IUserMountCache {
$result = $query->executeQuery();
$mounts = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if ($user === null && !$this->userManager->userExists($row['user_id'])) {
continue;
}
@@ -469,7 +481,7 @@ class UserMountCache implements IUserMountCache {
$result = $query->executeQuery();
$results = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$results[$row['user_id']] = $row['size'];
}
$result->closeCursor();
@@ -527,15 +539,25 @@ class UserMountCache implements IUserMountCache {
}
public function addMount(IUser $user, string $mountPoint, ICacheEntry $rootCacheEntry, string $mountProvider, ?int $mountId = null): void {
$this->connection->insertIgnoreConflict('mounts', [
'storage_id' => $rootCacheEntry->getStorageId(),
'root_id' => $rootCacheEntry->getId(),
'user_id' => $user->getUID(),
'mount_point' => $mountPoint,
'mount_point_hash' => hash('xxh128', $mountPoint),
'mount_id' => $mountId,
'mount_provider_class' => $mountProvider
]);
$query = $this->connection->getQueryBuilder();
$query->insert('mounts')
->values([
'storage_id' => $query->createNamedParameter($rootCacheEntry->getStorageId()),
'root_id' => $query->createNamedParameter($rootCacheEntry->getId()),
'user_id' => $query->createNamedParameter($user->getUID()),
'mount_point' => $query->createNamedParameter($mountPoint),
'mount_point_hash' => $query->createNamedParameter(hash('xxh128', $mountPoint)),
'mount_id' => $query->createNamedParameter($mountId),
'mount_provider_class' => $query->createNamedParameter($mountProvider)
]);
try {
$query->executeStatement();
} catch (DbalException $e) {
if ($e->getReason() !== DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}
}
}
/**
@@ -457,7 +457,6 @@ class ObjectStoreStorage extends Common implements IChunkedFileWrite {
}
public function writeStream(string $path, $stream, ?int $size = null): int {
// If caller didn't provide size, try to infer it from the input stream metadata.
if ($size === null) {
$stats = fstat($stream);
if (is_array($stats) && isset($stats['size'])) {
@@ -465,22 +464,19 @@ class ObjectStoreStorage extends Common implements IChunkedFileWrite {
}
}
// Load current file metadata from cache. If not found, initialize stat for a new file.
$stat = $this->stat($path);
if (empty($stat)) {
// create new file
$stat = [
// New files cannot create children; mirror existing behavior for object store entries.
'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE,
];
}
// Refresh mutable metadata for this write.
// update stat with new data
$mTime = time();
$stat['size'] = (int)$size;
$stat['mtime'] = $mTime;
$stat['storage_mtime'] = $mTime;
// Derive mimetype from path and prepare object-store metadata payload.
$mimetypeDetector = Server::get(IMimeTypeDetector::class);
$mimetype = $mimetypeDetector->detectPath($path);
$metadata = [
@@ -488,7 +484,7 @@ class ObjectStoreStorage extends Common implements IChunkedFileWrite {
'original-storage' => $this->getId(),
'original-path' => $path,
];
if ($size !== null) {
if ($size) {
$metadata['size'] = $size;
}
@@ -496,30 +492,25 @@ class ObjectStoreStorage extends Common implements IChunkedFileWrite {
$stat['etag'] = $this->getETag($path);
$stat['checksum'] = '';
// Existing files are updated in place.
// New files are first written under "<path>.part" and moved into place after successful upload.
$exists = $this->getCache()->inCache($path);
$uploadPath = $exists ? $path : $path . '.part';
if ($exists) {
$fileId = $stat['fileid'];
} else {
// For new files, ensure parent exists and is a directory before creating cache entry.
$parent = $this->normalizePath(dirname($path));
if (!$this->is_dir($parent)) {
throw new \InvalidArgumentException(
sprintf('Cannot write "%s": parent path "%s" is not a directory', $path, $parent)
);
throw new \InvalidArgumentException("trying to upload a file ($path) inside a non-directory ($parent)");
}
$fileId = $this->getCache()->put($uploadPath, $stat);
}
$urn = $this->getURN($fileId);
try {
// Upload stream to object storage while counting bytes actually written.
//upload to object storage
$totalWritten = 0;
$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, $size, $exists, &$totalWritten): void {
// If total size is unknown and this is a new file, update cached size progressively.
if (is_null($size) && !$exists) {
$this->getCache()->update($fileId, [
'size' => $writtenSize,
@@ -528,7 +519,6 @@ class ObjectStoreStorage extends Common implements IChunkedFileWrite {
$totalWritten = $writtenSize;
});
// Prefer metadata-aware writes when supported by the backend; otherwise fall back to the legacy write API
if ($this->objectStore instanceof IObjectStoreMetaData) {
$this->objectStore->writeObjectWithMetaData($urn, $countStream, $metadata);
} else {
@@ -538,36 +528,38 @@ class ObjectStoreStorage extends Common implements IChunkedFileWrite {
fclose($countStream);
}
// Trust counted bytes as the authoritative written size.
$stat['size'] = $totalWritten;
} catch (\Exception $ex) {
/*
* Only remove cache entry for new files.
* For existing files, removing would drop visibility of the prior valid file entry.
*/
if (!$exists) {
/*
* Only remove the entry if we are dealing with a new file.
* Else people lose access to existing files
*/
$this->getCache()->remove($uploadPath);
$this->logger->error(
'Could not create object ' . $urn . ' for ' . $path,
[
'app' => 'objectstore',
'exception' => $ex,
]
);
} else {
$this->logger->error(
'Could not update object ' . $urn . ' for ' . $path,
[
'app' => 'objectstore',
'exception' => $ex,
]
);
}
$operation = $exists ? 'update' : 'create';
$this->logger->error(
sprintf('Could not %s object %s for %s', $operation, $urn, $path),,
[
'app' => 'objectstore',
'exception' => $ex,
]
);
throw new GenericFileException('Error while writing stream to object store', 0, $ex);
}
if ($exists) {
// Keep unencrypted_size in sync for existing files.
// (Encryption wrapper may adjust this afterwards when applicable.)
// Always update the unencrypted size, for encryption the Encryption wrapper will update this afterwards anyways
$stat['unencrypted_size'] = $stat['size'];
$this->getCache()->update($fileId, $stat);
} else {
// For new files, publish temp entry only after write validation (if enabled).
if (!$this->validateWrites || $this->objectStore->objectExists($urn)) {
$this->getCache()->move($uploadPath, $path);
} else {
+1 -1
View File
@@ -131,7 +131,7 @@ class Loader implements IMimeTypeLoader {
->from('mimetypes');
$result = $qb->executeQuery();
$results = $result->fetchAll();
$results = $result->fetchAllAssociative();
$result->closeCursor();
foreach ($results as $row) {
+20 -32
View File
@@ -96,15 +96,12 @@ class View {
}
/**
* Returns an absolute path in Nextcloud's virtual filesystem for this view.
*
* The returned path is scoped by this view's fake root.
*
* @param ?string $path
* @psalm-template S as string|null
* @psalm-param S $path
* @psalm-return (S is string ? string : null)
*/
public function getAbsolutePath(?string $path = '/'): ?string {
public function getAbsolutePath($path = '/'): ?string {
if ($path === null) {
return null;
}
@@ -188,42 +185,33 @@ class View {
}
/**
* Resolve a path to a storage and internal path.
* Resolve a path to a storage and internal path
*
* Accepts both:
* - relative paths (interpreted relative to this view root), and
* - absolute paths in Nextcloud's virtual filesystem (leading '/').
*
* @param string $path Relative path, or absolute virtual filesystem path
* @return array{?IStorage, string} An array containing [storage, internalPath]
* @param string $path
* @return array{?IStorage, string} an array consisting of the storage and the internal path
*/
public function resolvePath(string $path): array {
$absolutePath = $this->getAbsolutePath($path);
$normalizedPath = Filesystem::normalizePath($absolutePath);
return Filesystem::resolvePath($normalizedPath);
public function resolvePath($path): array {
$a = $this->getAbsolutePath($path);
$p = Filesystem::normalizePath($a);
return Filesystem::resolvePath($p);
}
/**
* Return the path to a local representation of a file.
* Return the path to a local version of the file
* we need this because we can't know if a file is stored local or not from
* outside the filestorage and for some purposes a local file is needed
*
* For local storages this is usually the real on-disk path.
* For non-local storages this may be a temporary local file.
*
* @param string $path Path relative to this view, or absolute virtual filesystem path
* @return string|false Local file path, or false if unavailable
* @param string $path
*/
public function getLocalFile(string $path): string|false {
$parentPath = dirname($path);
if (!Filesystem::isValidPath($parentPath)) {
public function getLocalFile($path): string|false {
$parent = substr($path, 0, strrpos($path, '/') ?: 0);
$path = $this->getAbsolutePath($path);
[$storage, $internalPath] = Filesystem::resolvePath($path);
if (Filesystem::isValidPath($parent) && $storage) {
return $storage->getLocalFile($internalPath);
} else {
return false;
}
[$storage, $internalPath] = $this->resolvePath($path);
if (!$storage) {
return false;
}
return $storage->getLocalFile($internalPath);
}
/**
@@ -41,7 +41,7 @@ class MetadataRequestService {
$query->select('storage')
->from('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($filesMetadata->getFileId(), IQueryBuilder::PARAM_INT)));
$storageId = $query->executeQuery()->fetchColumn();
$storageId = (int)$query->executeQuery()->fetchOne();
if ($filesMetadata instanceof FilesMetadata) {
$filesMetadata->setStorageId($storageId);
@@ -81,7 +81,7 @@ class MetadataRequestService {
$qb->select('json', 'sync_token')->from(self::TABLE_METADATA);
$qb->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$result = $qb->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
} catch (Exception $e) {
$this->logger->warning('exception while getMetadataFromDatabase()', ['exception' => $e, 'fileId' => $fileId]);
@@ -115,7 +115,7 @@ class MetadataRequestService {
$list = [];
$result = $qb->executeQuery();
while ($data = $result->fetch()) {
while ($data = $result->fetchAssociative()) {
$fileId = (int)$data['file_id'];
$metadata = new FilesMetadata($fileId);
try {
+7 -7
View File
@@ -146,7 +146,7 @@ class Database extends ABackend implements
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->executeQuery();
$result = $cursor->fetch();
$result = $cursor->fetchAssociative();
$cursor->closeCursor();
return $result ? true : false;
@@ -221,7 +221,7 @@ class Database extends ABackend implements
->executeQuery();
$groups = [];
while ($row = $cursor->fetch()) {
while ($row = $cursor->fetchAssociative()) {
$groups[] = $row['gid'];
$this->groupCache[$row['gid']] = [
'gid' => $row['gid'],
@@ -268,7 +268,7 @@ class Database extends ABackend implements
$result = $query->executeQuery();
$groups = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$this->groupCache[$row['gid']] = [
'displayname' => $row['displayname'],
'gid' => $row['gid'],
@@ -298,7 +298,7 @@ class Database extends ABackend implements
->from('groups')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
->executeQuery();
$result = $cursor->fetch();
$result = $cursor->fetchAssociative();
$cursor->closeCursor();
if ($result !== false) {
@@ -335,7 +335,7 @@ class Database extends ABackend implements
foreach (array_chunk($notFoundGids, 1000) as $chunk) {
$qb->setParameter('ids', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$result = $qb->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$this->groupCache[(string)$row['gid']] = [
'displayname' => (string)$row['displayname'],
'gid' => (string)$row['gid'],
@@ -413,7 +413,7 @@ class Database extends ABackend implements
$users = [];
$userManager = Server::get(IUserManager::class);
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$users[$row['uid']] = new LazyUser($row['uid'], $userManager, $row['displayname'] ?? null);
}
$result->closeCursor();
@@ -544,7 +544,7 @@ class Database extends ABackend implements
->where($query->expr()->in('gid', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)));
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$details[(string)$row['gid']] = ['displayName' => (string)$row['displayname']];
$this->groupCache[(string)$row['gid']] = [
'displayname' => (string)$row['displayname'],
+3 -3
View File
@@ -63,14 +63,14 @@ class Manager extends PublicEmitter implements IGroupManager {
) {
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
$this->listen('\OC\Group', 'preDelete', function (IGroup $group): void {
$this->listen('\OC\Group', 'postDelete', function (IGroup $group): void {
unset($this->cachedGroups[$group->getGID()]);
$this->cachedUserGroups = [];
});
$this->listen('\OC\Group', 'preAddUser', function (IGroup $group): void {
$this->listen('\OC\Group', 'postAddUser', function (IGroup $group): void {
$this->cachedUserGroups = [];
});
$this->listen('\OC\Group', 'preRemoveUser', function (IGroup $group): void {
$this->listen('\OC\Group', 'postRemoveUser', function (IGroup $group): void {
$this->cachedUserGroups = [];
});
}
+2 -2
View File
@@ -83,7 +83,7 @@ class BackgroundCleanupJob extends TimedJob {
}
$cursor = $qb->executeQuery();
while ($row = $cursor->fetch()) {
while ($row = $cursor->fetchAssociative()) {
yield (int)$row['file_id'];
}
$cursor->closeCursor();
@@ -101,7 +101,7 @@ class BackgroundCleanupJob extends TimedJob {
$qb->expr()->in('fileid', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)),
$qb->expr()->eq('storage', $qb->createNamedParameter($storage, IQueryBuilder::PARAM_INT)),
));
$found = $qb->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
$found = $qb->executeQuery()->fetchFirstColumn();
return array_diff($ids, $found);
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ class PreviewService {
$found = false;
// Previews next to each others in the database are likely in the same storage, so group them
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$found = true;
if ($lastStorageId !== (int)$row['storage_id']) {
if ($lastStorageId !== -1) {
+2 -2
View File
@@ -66,7 +66,7 @@ class CleanTags implements IRepairStep {
$users = [];
$hadResults = false;
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$hadResults = true;
if (!$this->userManager->userExists($row['uid'])) {
$users[] = $row['uid'];
@@ -149,7 +149,7 @@ class CleanTags implements IRepairStep {
$result = $qb->executeQuery();
$orphanItems = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$orphanItems[] = (int)$row[$deleteId];
}
+2 -2
View File
@@ -87,7 +87,7 @@ class Collation implements IRepairStep {
. " AND TABLE_NAME LIKE '*PREFIX*%'",
[$dbName]
);
$rows = $statement->fetchAll();
$rows = $statement->fetchAllAssociative();
$result = [];
foreach ($rows as $row) {
$result[$row['table']] = true;
@@ -102,7 +102,7 @@ class Collation implements IRepairStep {
. " AND TABLE_NAME LIKE '*PREFIX*%'",
[$dbName]
);
$rows = $statement->fetchAll();
$rows = $statement->fetchAllAssociative();
foreach ($rows as $row) {
$result[$row['table']] = true;
}
@@ -53,7 +53,7 @@ class OldGroupMembershipShares implements IRepairStep {
->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
if (!$this->isMember($row['group'], $row['user'])) {
$deletedEntries += $deleteQuery->setParameter('share', (int)$row['id'])
->executeStatement();
@@ -109,7 +109,7 @@ class MigrateOauthTables implements IRepairStep {
->from('oauth2_clients');
$result = $qbSelect->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$id = $row['id'];
$shortenedName = mb_substr($row['name'], 0, 64);
$qb->setParameter('theId', $id, IQueryBuilder::PARAM_INT);
@@ -147,7 +147,7 @@ class MigrateOauthTables implements IRepairStep {
$selectQuery = $this->db->getQueryBuilder();
$selectQuery->select('id', 'identifier')->from('oauth2_clients');
$result = $selectQuery->executeQuery();
$identifiers = $result->fetchAll();
$identifiers = $result->fetchAllAssociative();
$result->closeCursor();
// 2. Insert them into the client_identifier column.
@@ -218,7 +218,7 @@ class MigrateOauthTables implements IRepairStep {
$result = $qbSelect->executeQuery();
$now = $this->timeFactory->now()->getTimestamp();
$index = 0;
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$clientId = $row['client_id'];
$refreshToken = $row['token'];
@@ -110,7 +110,7 @@ class SaveAccountsTableData implements IRepairStep {
->where($update->expr()->eq('uid', $update->createParameter('userid')));
$updatedUsers = 0;
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
try {
$this->migrateUserInfo($update, $row);
} catch (PreConditionNotMetException|\UnexpectedValueException) {
@@ -35,7 +35,7 @@ class RemoveBrokenProperties implements IRepairStep {
$result = $qb->executeQuery();
// find broken object properties
$brokenIds = [];
while ($entry = $result->fetch()) {
while ($entry = $result->fetchAssociative()) {
if (!empty($entry['propertyvalue'])) {
$object = @unserialize(str_replace('\x00', chr(0), $entry['propertyvalue']));
if ($object === false) {
+2 -2
View File
@@ -87,7 +87,7 @@ class RemoveLinkShares implements IRepairStep {
->where($query->expr()->in('id', $query->createFunction($subQuery->getSQL())));
$result = $query->executeQuery();
$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
return (int)$data['total'];
@@ -166,7 +166,7 @@ class RemoveLinkShares implements IRepairStep {
$output->startProgress($total);
$shareResult = $this->getShares();
while ($data = $shareResult->fetch()) {
while ($data = $shareResult->fetchAssociative()) {
$this->processShare($data);
$output->advance();
}
+1 -1
View File
@@ -49,7 +49,7 @@ class RepairDavShares implements IRepairStep {
->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('shareId')));
$statement = $qb->executeQuery();
while ($share = $statement->fetch()) {
while ($share = $statement->fetchAssociative()) {
$gid = substr($share['principaluri'], strlen(self::GROUP_PRINCIPAL_PREFIX));
$decodedGid = urldecode($gid);
$encodedGid = urlencode($gid);
+1 -1
View File
@@ -72,7 +72,7 @@ class RepairInvalidShares implements IRepairStep {
while ($deletedInLastChunk === self::CHUNK_SIZE) {
$deletedInLastChunk = 0;
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$deletedInLastChunk++;
$deletedEntries += $deleteQuery->setParameter('parent', (int)$row['parent'])
->executeStatement();
@@ -43,7 +43,7 @@ class DatabaseBackend implements IBackend {
}
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
return (int)$row['attempts'];
+1 -1
View File
@@ -61,7 +61,7 @@ class CredentialsManager implements ICredentialsManager {
}
$qResult = $qb->executeQuery();
$result = $qResult->fetch();
$result = $qResult->fetchAssociative();
$qResult->closeCursor();
if (!$result) {
+3 -3
View File
@@ -65,7 +65,7 @@ class MySQL extends AbstractDatabase {
//we can't use OC_DB functions here because we need to connect as the administrative user.
$characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE {$characterSet}_bin;";
$connection->executeUpdate($query);
$connection->executeStatement($query);
} catch (\Exception $ex) {
$this->logger->error('Database creation failed.', [
'exception' => $ex,
@@ -77,7 +77,7 @@ class MySQL extends AbstractDatabase {
try {
//this query will fail if there aren't the right permissions, ignore the error
$query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'";
$connection->executeUpdate($query);
$connection->executeStatement($query);
} catch (\Exception $ex) {
$this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges.', [
'exception' => $ex,
@@ -152,7 +152,7 @@ class MySQL extends AbstractDatabase {
$result = $connection->executeQuery($query, [$adminUser]);
//current dbuser has admin rights
$data = $result->fetchAll();
$data = $result->fetchAllAssociative();
$result->closeCursor();
//new dbuser does not exist
if (count($data) === 0) {
+17 -17
View File
@@ -340,7 +340,7 @@ class DefaultShareProvider implements
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
->executeQuery();
$data = $stmt->fetch();
$data = $stmt->fetchAssociative();
$stmt->closeCursor();
/*
@@ -392,7 +392,7 @@ class DefaultShareProvider implements
->orderBy('id');
$cursor = $qb->executeQuery();
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
$children[] = $this->createShare($data);
}
$cursor->closeCursor();
@@ -454,7 +454,7 @@ class DefaultShareProvider implements
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
->executeQuery();
$data = $stmt->fetch();
$data = $stmt->fetchAssociative();
/*
* Check if there already is a user specific group share.
@@ -533,7 +533,7 @@ class DefaultShareProvider implements
$qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))
);
$cursor = $qb->executeQuery();
$data = $cursor->fetch();
$data = $cursor->fetchAssociative();
$cursor->closeCursor();
$originalPermission = $data['permissions'];
@@ -577,7 +577,7 @@ class DefaultShareProvider implements
->setMaxResults(1)
->executeQuery();
$data = $stmt->fetch();
$data = $stmt->fetchAssociative();
$stmt->closeCursor();
$shareAttributes = $this->formatShareAttributes(
@@ -687,7 +687,7 @@ class DefaultShareProvider implements
foreach ($chunks as $chunk) {
$qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$cursor = $qb->executeQuery();
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
$shares[$data['fileid']][] = $this->createShare($data);
}
$cursor->closeCursor();
@@ -736,7 +736,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
$shares = [];
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
$shares[] = $this->createShare($data);
}
$cursor->closeCursor();
@@ -766,7 +766,7 @@ class DefaultShareProvider implements
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
$cursor = $qb->executeQuery();
$data = $cursor->fetch();
$data = $cursor->fetchAssociative();
$cursor->closeCursor();
if ($data === false) {
@@ -805,7 +805,7 @@ class DefaultShareProvider implements
->executeQuery();
$shares = [];
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
$shares[] = $this->createShare($data);
}
$cursor->closeCursor();
@@ -927,7 +927,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
if ($data['fileid'] && $data['path'] === null) {
$data['path'] = (string)$data['path'];
$data['name'] = (string)$data['name'];
@@ -1018,7 +1018,7 @@ class DefaultShareProvider implements
->andWhere($qb->expr()->in('s.item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
$cursor = $qb->executeQuery();
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
if ($offset > 0) {
$offset--;
continue;
@@ -1061,7 +1061,7 @@ class DefaultShareProvider implements
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
->executeQuery();
$data = $cursor->fetch();
$data = $cursor->fetchAssociative();
if ($data === false) {
throw new ShareNotFound();
@@ -1176,7 +1176,7 @@ class DefaultShareProvider implements
$stmt = $query->executeQuery();
while ($data = $stmt->fetch()) {
while ($data = $stmt->fetchAssociative()) {
if (array_key_exists($data['parent'], $shareMap)) {
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
$shareMap[$data['parent']]->setStatus((int)$data['accepted']);
@@ -1272,7 +1272,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
$ids = [];
while ($row = $cursor->fetch()) {
while ($row = $cursor->fetchAssociative()) {
$ids[] = (int)$row['id'];
}
$cursor->closeCursor();
@@ -1320,7 +1320,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
$ids = [];
while ($row = $cursor->fetch()) {
while ($row = $cursor->fetchAssociative()) {
$ids[] = (int)$row['id'];
}
$cursor->closeCursor();
@@ -1423,7 +1423,7 @@ class DefaultShareProvider implements
$users = [];
$link = false;
while ($row = $cursor->fetch()) {
while ($row = $cursor->fetchAssociative()) {
$type = (int)$row['share_type'];
if ($type === IShare::TYPE_USER) {
$uid = $row['share_with'];
@@ -1726,7 +1726,7 @@ class DefaultShareProvider implements
->where($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY)));
$cursor = $qb->executeQuery();
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
try {
$share = $this->createShare($data);
} catch (InvalidShare $e) {
+1 -1
View File
@@ -1069,7 +1069,7 @@ class Manager implements IManager {
$cursor = $qb->executeQuery();
/** @var array<string, list<array{IShare::TYPE_*, Node}>> $rawShare */
$rawShares = [];
while ($data = $cursor->fetch()) {
while ($data = $cursor->fetchAssociative()) {
if (!isset($rawShares[$data['uid_initiator']])) {
$rawShares[$data['uid_initiator']] = [];
}
+5 -5
View File
@@ -106,7 +106,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->executeQuery();
$groups = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$groups[] = $row['gid'];
}
$result->closeCursor();
@@ -139,7 +139,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->executeQuery();
$users = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$user = $this->userManager->get($row['uid']);
if (!is_null($user)) {
$users[] = $user;
@@ -162,7 +162,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->executeQuery();
$subadmins = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$user = $this->userManager->get($row['uid']);
$group = $this->groupManager->get($row['gid']);
if (!is_null($user) && !is_null($group)) {
@@ -195,7 +195,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->executeQuery();
$fetch = $result->fetch();
$fetch = $result->fetchAssociative();
$result->closeCursor();
$result = !empty($fetch) ? true : false;
@@ -226,7 +226,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->setMaxResults(1)
->executeQuery();
$isSubAdmin = $result->fetch();
$isSubAdmin = $result->fetchAssociative();
$result->closeCursor();
return $isSubAdmin !== false;
+4 -4
View File
@@ -75,7 +75,7 @@ class SystemTagManager implements ISystemTagManager {
->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY);
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$tag = $this->createSystemTagFromRow($row);
if ($user && !$this->canUserSeeTag($tag, $user)) {
// if a user is given, hide invisible tags
@@ -121,7 +121,7 @@ class SystemTagManager implements ISystemTagManager {
->addOrderBy('editable', 'ASC');
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$tags[$row['id']] = $this->createSystemTagFromRow($row);
}
@@ -139,7 +139,7 @@ class SystemTagManager implements ISystemTagManager {
->setParameter('editable', $userAssignable ? 1 : 0)
->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
if (!$row) {
throw new TagNotFoundException(
@@ -452,7 +452,7 @@ class SystemTagManager implements ISystemTagManager {
->orderBy('gid');
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$groupIds[] = $row['gid'];
}
@@ -56,7 +56,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
foreach ($chunks as $chunk) {
$query->setParameter('objectids', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$objectId = $row['objectid'];
$mapping[$objectId][] = (string)$row['systemtagid'];
}
@@ -99,7 +99,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$objectIds = [];
$result = $query->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$objectIds[] = $row['objectid'];
}
$result->closeCursor();
@@ -123,7 +123,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType)))
->andWhere($query->expr()->eq('objectid', $query->createNamedParameter($objId)));
$result = $query->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
$existingTags = [];
foreach ($rows as $row) {
$existingTags[] = $row['systemtagid'];
@@ -259,7 +259,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
->setParameter('objecttype', $objectType);
$result = $query->executeQuery();
$row = $result->fetch(\PDO::FETCH_NUM);
$row = $result->fetchNumeric();
$result->closeCursor();
if ($all) {
@@ -376,7 +376,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$result = $query->executeQuery();
$objectTypes = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$objectTypes[] = $row['objecttype'];
}
$result->closeCursor();
+2 -2
View File
@@ -79,7 +79,7 @@ class TagManager implements ITagManager, IEventListener {
->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE)));
$result = $query->executeQuery();
$users = $result->fetchAll(\PDO::FETCH_COLUMN);
$users = $result->fetchFirstColumn();
$result->closeCursor();
return $users;
@@ -106,7 +106,7 @@ class TagManager implements ITagManager, IEventListener {
return;
}
$tagsIds = array_map(fn (array $row) => (int)$row['id'], $result->fetchAll());
$tagsIds = array_map(fn (array $row) => (int)$row['id'], $result->fetchAllAssociative());
$result->closeCursor();
if (count($tagsIds) === 0) {
+2 -2
View File
@@ -159,7 +159,7 @@ class Tags implements ITags {
$qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR);
$qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$result = $qb->executeQuery();
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$objId = (int)$row['objid'];
if (!isset($entries[$objId])) {
$entries[$objId] = [];
@@ -223,7 +223,7 @@ class Tags implements ITags {
return false;
}
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$ids[] = (int)$row['objid'];
}
$result->closeCursor();
+1 -1
View File
@@ -276,7 +276,7 @@ class TaskMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('status', $qb->createNamedParameter(\OCP\TaskProcessing\Task::STATUS_RUNNING, IQueryBuilder::PARAM_INT)));
$qb->setMaxResults(1);
$result = $qb->executeQuery();
$hasRunningTasks = $result->fetch() !== false;
$hasRunningTasks = $result->fetchAssociative() !== false;
$result->closeCursor();
return $hasRunningTasks;
}
+3 -3
View File
@@ -289,7 +289,7 @@ class Database extends ABackend implements
$result = $query->executeQuery();
$displayNames = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$displayNames[(string)$row['uid']] = (string)$row['displayname'];
}
@@ -328,7 +328,7 @@ class Database extends ABackend implements
$result = $query->executeQuery();
$displayNames = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$displayNames[(string)$row['uid']] = (string)$row['displayname'];
}
@@ -389,7 +389,7 @@ class Database extends ABackend implements
)
);
$result = $qb->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();
// "uid" is primary key, so there can only be a single result
+2 -2
View File
@@ -651,7 +651,7 @@ class Manager extends PublicEmitter implements IUserManager {
$query = $queryBuilder->executeQuery();
$result = [];
while ($row = $query->fetch()) {
while ($row = $query->fetchAssociative()) {
$result[] = $row['userid'];
}
@@ -774,7 +774,7 @@ class Manager extends PublicEmitter implements IUserManager {
}
/** @var list<string> */
$list = $queryBuilder->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
$list = $queryBuilder->executeQuery()->fetchFirstColumn();
return $list;
}
+4 -4
View File
@@ -275,7 +275,7 @@ abstract class QBMapper {
protected function findOneQuery(IQueryBuilder $query): array {
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
if ($row === false) {
$result->closeCursor();
$msg = $this->buildDebugMessage(
@@ -284,7 +284,7 @@ abstract class QBMapper {
throw new DoesNotExistException($msg);
}
$row2 = $result->fetch();
$row2 = $result->fetchAssociative();
$result->closeCursor();
if ($row2 !== false) {
$msg = $this->buildDebugMessage(
@@ -336,7 +336,7 @@ abstract class QBMapper {
$result = $query->executeQuery();
try {
$entities = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$entities[] = $this->mapRowToEntity($row);
}
return $entities;
@@ -357,7 +357,7 @@ abstract class QBMapper {
protected function yieldEntities(IQueryBuilder $query): Generator {
$result = $query->executeQuery();
try {
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
yield $this->mapRowToEntity($row);
}
} finally {
+101 -154
View File
@@ -23,6 +23,43 @@ class AllConfigTest extends \Test\TestCase {
/** @var IDBConnection */
protected $connection;
/** Insert one row into oc_preferences */
private function insertPreferenceRow(string $userid, string $appid, string $configkey, string $configvalue): void {
$qb = $this->connection->getQueryBuilder();
$qb->insert('preferences')
->values([
'userid' => $qb->createNamedParameter($userid),
'appid' => $qb->createNamedParameter($appid),
'configkey' => $qb->createNamedParameter($configkey),
'configvalue' => $qb->createNamedParameter($configvalue),
])
->executeStatement();
}
/** Return all oc_preferences rows for the given user */
private function getPreferenceRows(string $userid): array {
$qb = $this->connection->getQueryBuilder();
return $qb->select('userid', 'appid', 'configkey', 'configvalue')
->from('preferences')
->where($qb->expr()->eq('userid', $qb->createNamedParameter($userid)))
->executeQuery()
->fetchAllAssociative();
}
/** Return the total number of rows in oc_preferences */
private function countPreferenceRows(): int {
$qb = $this->connection->getQueryBuilder();
return (int)$qb->select($qb->func()->count('*'))
->from('preferences')
->executeQuery()
->fetchOne();
}
/** Truncate oc_preferences */
private function clearPreferences(): void {
$this->connection->getQueryBuilder()->delete('preferences')->executeStatement();
}
protected function getConfig($systemConfig = null, $connection = null) {
if ($this->connection === null) {
$this->connection = Server::get(IDBConnection::class);
@@ -42,30 +79,21 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig();
// preparation - add something to the database
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
['userDelete', 'appDelete', 'keyDelete', 'valueDelete']
);
$this->insertPreferenceRow('userDelete', 'appDelete', 'keyDelete', 'valueDelete');
$config->deleteUserValue('userDelete', 'appDelete', 'keyDelete');
$result = $this->connection->executeQuery(
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?',
['userDelete']
)->fetchAssociative();
$actualCount = $result['count'];
$actualCount = count($this->getPreferenceRows('userDelete'));
$this->assertEquals(0, $actualCount, 'There was one value in the database and after the tests there should be no entry left.');
}
public function testSetUserValue(): void {
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
$config = $this->getConfig();
$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet');
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userSet');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -78,7 +106,7 @@ class AllConfigTest extends \Test\TestCase {
// test if the method overwrites existing database entries
$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet2');
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userSet');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -97,12 +125,11 @@ class AllConfigTest extends \Test\TestCase {
* This way we can skip the expensive casing change on the database.
*/
public function testSetUserValueSettingsEmail(): void {
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
$config = $this->getConfig();
$config->setUserValue('userSet', 'settings', 'email', 'mixed.CASE@domain.COM');
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userSet');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -116,11 +143,9 @@ class AllConfigTest extends \Test\TestCase {
public function testSetUserValueWithPreCondition(): void {
$config = $this->getConfig();
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
$config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userPreCond');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -133,7 +158,7 @@ class AllConfigTest extends \Test\TestCase {
// test if the method overwrites existing database entries with valid precond
$config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userPreCond');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -173,11 +198,9 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig();
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userPreCond1');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -190,7 +213,7 @@ class AllConfigTest extends \Test\TestCase {
// test if the method overwrites existing database entries with valid precond
$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond3');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userPreCond1');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -209,11 +232,9 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig();
$selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userPreCond1');
$this->assertCount(1, $result);
$this->assertEquals([
@@ -226,7 +247,7 @@ class AllConfigTest extends \Test\TestCase {
// test if the method throws with invalid precondition when the value is the same
$config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond', 'valuePreCond3');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$result = $this->getPreferenceRows('userPreCond1');
$this->assertCount(1, $result);
$this->assertEquals([
@@ -247,7 +268,7 @@ class AllConfigTest extends \Test\TestCase {
$resultMock = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')
->disableOriginalConstructor()->getMock();
$resultMock->expects($this->once())
->method('fetchColumn')
->method('fetchOne')
->willReturn('valueSetUnchanged');
$connectionMock = $this->createMock(IDBConnection::class);
@@ -258,7 +279,7 @@ class AllConfigTest extends \Test\TestCase {
$this->equalTo(['userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged']))
->willReturn($resultMock);
$connectionMock->expects($this->never())
->method('executeUpdate');
->method('executeStatement');
$config = $this->getConfig(null, $connectionMock);
@@ -274,10 +295,7 @@ class AllConfigTest extends \Test\TestCase {
$this->assertEquals('valueGet', $value);
$result = $this->connection->executeQuery(
'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
['userGet']
)->fetchAllAssociative();
$result = $this->getPreferenceRows('userGet');
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -288,41 +306,30 @@ class AllConfigTest extends \Test\TestCase {
], $result[0]);
// drop data from database - but the config option should be cached in the config object
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?', ['userGet']);
$qb = $this->connection->getQueryBuilder();
$qb->delete('preferences')
->where($qb->expr()->eq('userid', $qb->createNamedParameter('userGet')))
->executeStatement();
// testing the caching mechanism
$value = $config->getUserValue('userGet', 'appGet', 'keyGet');
$this->assertEquals('valueGet', $value);
$result = $this->connection->executeQuery(
'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
['userGet']
)->fetchAllAssociative();
$this->assertEquals(0, count($result));
$this->assertEquals(0, count($this->getPreferenceRows('userGet')));
}
public function testGetUserKeys(): void {
$config = $this->getConfig();
// preparation - add something to the database
$data = [
['userFetch', 'appFetch1', 'keyFetch1', 'value1'],
['userFetch', 'appFetch1', 'keyFetch2', 'value2'],
['userFetch', 'appFetch2', 'keyFetch3', 'value3'],
['userFetch', 'appFetch1', 'keyFetch4', 'value4'],
['userFetch', 'appFetch4', 'keyFetch1', 'value5'],
['userFetch', 'appFetch5', 'keyFetch1', 'value6'],
['userFetch2', 'appFetch', 'keyFetch1', 'value7']
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$this->insertPreferenceRow('userFetch', 'appFetch1', 'keyFetch1', 'value1');
$this->insertPreferenceRow('userFetch', 'appFetch1', 'keyFetch2', 'value2');
$this->insertPreferenceRow('userFetch', 'appFetch2', 'keyFetch3', 'value3');
$this->insertPreferenceRow('userFetch', 'appFetch1', 'keyFetch4', 'value4');
$this->insertPreferenceRow('userFetch', 'appFetch4', 'keyFetch1', 'value5');
$this->insertPreferenceRow('userFetch', 'appFetch5', 'keyFetch1', 'value6');
$this->insertPreferenceRow('userFetch2', 'appFetch', 'keyFetch1', 'value7');
$value = $config->getUserKeys('userFetch', 'appFetch1');
$this->assertEquals(['keyFetch1', 'keyFetch2', 'keyFetch4'], $value);
@@ -331,24 +338,15 @@ class AllConfigTest extends \Test\TestCase {
$this->assertEquals(['keyFetch1'], $value);
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
$this->clearPreferences();
}
public function testGetUserKeysAllInts(): void {
$config = $this->getConfig();
// preparation - add something to the database
$data = [
['userFetch8', 'appFetch1', '123', 'value'],
['userFetch8', 'appFetch1', '456', 'value'],
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$this->insertPreferenceRow('userFetch8', 'appFetch1', '123', 'value');
$this->insertPreferenceRow('userFetch8', 'appFetch1', '456', 'value');
$value = $config->getUserKeys('userFetch8', 'appFetch1');
$this->assertEquals(['123', '456'], $value);
@@ -356,7 +354,7 @@ class AllConfigTest extends \Test\TestCase {
$this->assertIsString($value[1]);
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
$this->clearPreferences();
}
public function testGetUserValueDefault(): void {
@@ -371,22 +369,13 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig();
// preparation - add something to the database
$data = [
['userFetch1', 'appFetch2', 'keyFetch1', 'value1'],
['userFetch2', 'appFetch2', 'keyFetch1', 'value2'],
['userFetch3', 'appFetch2', 'keyFetch1', 3],
['userFetch4', 'appFetch2', 'keyFetch1', 'value4'],
['userFetch5', 'appFetch2', 'keyFetch1', 'value5'],
['userFetch6', 'appFetch2', 'keyFetch1', 'value6'],
['userFetch7', 'appFetch2', 'keyFetch1', 'value7']
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$this->insertPreferenceRow('userFetch1', 'appFetch2', 'keyFetch1', 'value1');
$this->insertPreferenceRow('userFetch2', 'appFetch2', 'keyFetch1', 'value2');
$this->insertPreferenceRow('userFetch3', 'appFetch2', 'keyFetch1', '3');
$this->insertPreferenceRow('userFetch4', 'appFetch2', 'keyFetch1', 'value4');
$this->insertPreferenceRow('userFetch5', 'appFetch2', 'keyFetch1', 'value5');
$this->insertPreferenceRow('userFetch6', 'appFetch2', 'keyFetch1', 'value6');
$this->insertPreferenceRow('userFetch7', 'appFetch2', 'keyFetch1', 'value7');
$value = $config->getUserValueForUsers('appFetch2', 'keyFetch1',
['userFetch1', 'userFetch2', 'userFetch3', 'userFetch5']);
@@ -405,84 +394,51 @@ class AllConfigTest extends \Test\TestCase {
], $value, 'userFetch9 is an non-existent user and should not be shown.');
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
$this->clearPreferences();
}
public function testDeleteAllUserValues(): void {
$config = $this->getConfig();
// preparation - add something to the database
$data = [
['userFetch3', 'appFetch1', 'keyFetch1', 'value1'],
['userFetch3', 'appFetch1', 'keyFetch2', 'value2'],
['userFetch3', 'appFetch2', 'keyFetch3', 'value3'],
['userFetch3', 'appFetch1', 'keyFetch4', 'value4'],
['userFetch3', 'appFetch4', 'keyFetch1', 'value5'],
['userFetch3', 'appFetch5', 'keyFetch1', 'value6'],
['userFetch4', 'appFetch2', 'keyFetch1', 'value7']
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$this->insertPreferenceRow('userFetch3', 'appFetch1', 'keyFetch1', 'value1');
$this->insertPreferenceRow('userFetch3', 'appFetch1', 'keyFetch2', 'value2');
$this->insertPreferenceRow('userFetch3', 'appFetch2', 'keyFetch3', 'value3');
$this->insertPreferenceRow('userFetch3', 'appFetch1', 'keyFetch4', 'value4');
$this->insertPreferenceRow('userFetch3', 'appFetch4', 'keyFetch1', 'value5');
$this->insertPreferenceRow('userFetch3', 'appFetch5', 'keyFetch1', 'value6');
$this->insertPreferenceRow('userFetch4', 'appFetch2', 'keyFetch1', 'value7');
$config->deleteAllUserValues('userFetch3');
$result = $this->connection->executeQuery(
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
)->fetchAssociative();
$actualCount = $result['count'];
$this->assertEquals(1, $actualCount, 'After removing `userFetch3` there should be exactly 1 entry left.');
$this->assertEquals(1, $this->countPreferenceRows(), 'After removing `userFetch3` there should be exactly 1 entry left.');
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
$this->clearPreferences();
}
public function testDeleteAppFromAllUsers(): void {
$config = $this->getConfig();
// preparation - add something to the database
$data = [
['userFetch5', 'appFetch1', 'keyFetch1', 'value1'],
['userFetch5', 'appFetch1', 'keyFetch2', 'value2'],
['userFetch5', 'appFetch2', 'keyFetch3', 'value3'],
['userFetch5', 'appFetch1', 'keyFetch4', 'value4'],
['userFetch5', 'appFetch4', 'keyFetch1', 'value5'],
['userFetch5', 'appFetch5', 'keyFetch1', 'value6'],
['userFetch6', 'appFetch2', 'keyFetch1', 'value7']
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$this->insertPreferenceRow('userFetch5', 'appFetch1', 'keyFetch1', 'value1');
$this->insertPreferenceRow('userFetch5', 'appFetch1', 'keyFetch2', 'value2');
$this->insertPreferenceRow('userFetch5', 'appFetch2', 'keyFetch3', 'value3');
$this->insertPreferenceRow('userFetch5', 'appFetch1', 'keyFetch4', 'value4');
$this->insertPreferenceRow('userFetch5', 'appFetch4', 'keyFetch1', 'value5');
$this->insertPreferenceRow('userFetch5', 'appFetch5', 'keyFetch1', 'value6');
$this->insertPreferenceRow('userFetch6', 'appFetch2', 'keyFetch1', 'value7');
$config->deleteAppFromAllUsers('appFetch1');
$result = $this->connection->executeQuery(
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
)->fetchAssociative();
$actualCount = $result['count'];
$this->assertEquals(4, $actualCount, 'After removing `appFetch1` there should be exactly 4 entries left.');
$this->assertEquals(4, $this->countPreferenceRows(), 'After removing `appFetch1` there should be exactly 4 entries left.');
$config->deleteAppFromAllUsers('appFetch2');
$result = $this->connection->executeQuery(
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`'
)->fetchAssociative();
$actualCount = $result['count'];
$this->assertEquals(2, $actualCount, 'After removing `appFetch2` there should be exactly 2 entries left.');
$this->assertEquals(2, $this->countPreferenceRows(), 'After removing `appFetch2` there should be exactly 2 entries left.');
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
$this->clearPreferences();
}
public function testGetUsersForUserValue(): void {
@@ -493,26 +449,17 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig($systemConfig);
// preparation - add something to the database
$data = [
['user1', 'appFetch9', 'keyFetch9', 'value9'],
['user2', 'appFetch9', 'keyFetch9', 'value9'],
['user3', 'appFetch9', 'keyFetch9', 'value8'],
['user4', 'appFetch9', 'keyFetch8', 'value9'],
['user5', 'appFetch8', 'keyFetch9', 'value9'],
['user6', 'appFetch9', 'keyFetch9', 'value9'],
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$this->insertPreferenceRow('user1', 'appFetch9', 'keyFetch9', 'value9');
$this->insertPreferenceRow('user2', 'appFetch9', 'keyFetch9', 'value9');
$this->insertPreferenceRow('user3', 'appFetch9', 'keyFetch9', 'value8');
$this->insertPreferenceRow('user4', 'appFetch9', 'keyFetch8', 'value9');
$this->insertPreferenceRow('user5', 'appFetch8', 'keyFetch9', 'value9');
$this->insertPreferenceRow('user6', 'appFetch9', 'keyFetch9', 'value9');
$value = $config->getUsersForUserValue('appFetch9', 'keyFetch9', 'value9');
$this->assertEquals(['user1', 'user2', 'user6'], $value);
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
$this->clearPreferences();
}
}
+1 -1
View File
@@ -149,7 +149,7 @@ class AppConfigTest extends TestCase {
]);
$result = $this->createMock(IResult::class);
$result->method('fetchAll')->willReturn([
$result->method('fetchAllAssociative')->willReturn([
['lazy' => 1, 'appid' => 'appid', 'configkey' => 'lazy-key', 'configvalue' => 'lazy value'],
]);
$expression = $this->createMock(IExpressionBuilder::class);
+14
View File
@@ -595,6 +595,20 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($cachedData['storage_mtime'], $cachedData['mtime']);
}
public function testTouchFloat(): void {
$storage = $this->getTestStorage(true, TemporaryNoTouch::class);
Filesystem::mount($storage, [], '/');
$rootView = new View('');
$oldCachedData = $rootView->getFileInfo('foo.txt');
$rootView->touch('foo.txt', 500.5);
$cachedData = $rootView->getFileInfo('foo.txt');
$this->assertEquals(500, $cachedData['mtime']);
}
public function testViewHooks(): void {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
+2 -2
View File
@@ -110,9 +110,9 @@ class RepairDavSharesTest extends TestCase {
$shareResults = $this->createMock(IResult::class);
$shareResults->expects($this->any())
->method('fetch')
->method('fetchAssociative')
->willReturnCallback(function () use (&$shareResultData) {
return array_pop($shareResultData);
return array_pop($shareResultData) ?? false;
});
$expressionBuilder = $this->createMock(IExpressionBuilder::class);
+4 -4
View File
@@ -517,7 +517,7 @@ class ManagerTest extends \Test\TestCase {
->willReturn($result);
$this->connection->method('getQueryBuilder')
->willReturn($qb);
$result->method('fetch')
$result->method('fetchAssociative')
->willReturnOnConsecutiveCalls(
['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42],
false,
@@ -613,7 +613,7 @@ class ManagerTest extends \Test\TestCase {
->willReturn($result);
$this->connection->method('getQueryBuilder')
->willReturn($qb);
$result->method('fetch')
$result->method('fetchAssociative')
->willReturnOnConsecutiveCalls(
['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 41],
['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42],
@@ -670,7 +670,7 @@ class ManagerTest extends \Test\TestCase {
->willReturn($result);
$this->connection->method('getQueryBuilder')
->willReturn($qb);
$result->method('fetch')
$result->method('fetchAssociative')
->willReturnOnConsecutiveCalls(
['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42],
false,
@@ -764,7 +764,7 @@ class ManagerTest extends \Test\TestCase {
->willReturn($result);
$this->connection->method('getQueryBuilder')
->willReturn($qb);
$result->method('fetch')
$result->method('fetchAssociative')
->willReturnOnConsecutiveCalls(
['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42],
['uid_initiator' => 'userC', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42],
+15 -16
View File
@@ -10,6 +10,7 @@ namespace Test;
use OC\Tagging\TagMapper;
use OC\TagManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -28,15 +29,11 @@ use Psr\Log\LoggerInterface;
#[\PHPUnit\Framework\Attributes\Group('DB')]
class TagsTest extends \Test\TestCase {
protected $objectType;
/** @var IUser */
protected $user;
/** @var IUserSession */
protected $userSession;
protected IUser $user;
protected IUserSession $userSession;
protected $backupGlobals = false;
/** @var TagMapper */
protected $tagMapper;
/** @var ITagManager */
protected $tagMgr;
protected TagMapper $tagMapper;
protected ITagManager $tagMgr;
protected IRootFolder $rootFolder;
protected function setUp(): void {
@@ -75,8 +72,8 @@ class TagsTest extends \Test\TestCase {
protected function tearDown(): void {
$conn = Server::get(IDBConnection::class);
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`');
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory`');
$conn->getQueryBuilder()->delete('vcategory_to_object')->executeStatement();
$conn->getQueryBuilder()->delete('vcategory')->executeStatement();
parent::tearDown();
}
@@ -214,16 +211,18 @@ class TagsTest extends \Test\TestCase {
$tagType = $tagData[0]['type'];
$conn = Server::get(IDBConnection::class);
$statement = $conn->prepare(
'INSERT INTO `*PREFIX*vcategory_to_object` '
. '(`objid`, `categoryid`, `type`) VALUES '
. '(?, ?, ?)'
);
// insert lots of entries
$idsArray = [];
for ($i = 1; $i <= 1500; $i++) {
$statement->execute([$i, $tagId, $tagType]);
$qb = $conn->getQueryBuilder();
$qb->insert('vcategory_to_object')
->values([
'objid' => $qb->createNamedParameter($i, IQueryBuilder::PARAM_INT),
'categoryid' => $qb->createNamedParameter($tagId, IQueryBuilder::PARAM_INT),
'type' => $qb->createNamedParameter($tagType),
])
->executeStatement();
$idsArray[] = $i;
}