Compare commits

..

17 Commits

Author SHA1 Message Date
nfebe 89c6af10d1 fix(sharing): Surface specific error message on share update failure
InvalidArgumentException from the share manager (e.g. "Cannot enable
sending the password by Talk with an empty password") was caught by
the generic Exception handler and re-thrown as "Failed to update
share.", hiding the actual cause from the user. Catch it separately
to preserve the original message.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
2026-03-21 01:01:58 +01:00
Benjamin Gaussorgues 8c6d314b0e Merge pull request #58798 from AIlkiv/fix-UserMountCache-for-postgresql 2026-03-12 12:11:29 +01:00
Kate ddf79066b9 Merge pull request #58689 from nextcloud/fix/federated-reshare 2026-03-12 12:01:24 +01:00
Sebastian Krupinski ed3a230403 Merge pull request #58679 from nextcloud/feat/add-default-reminder-setting-caldav
feat: add default reminder setting caldav
2026-03-12 06:26:12 -04:00
provokateurin 5dbbe2ccf9 fix(dav): Use share initiator to get the share node, because the owner might on another server
Signed-off-by: provokateurin <kate@provokateurin.de>
2026-03-12 10:31:25 +01:00
provokateurin 045ad43237 fix(federatedfilesharing): Do not set the share id for an existing share
Signed-off-by: provokateurin <kate@provokateurin.de>
2026-03-12 10:31:25 +01:00
Carl Schwan 83956e9f04 Merge pull request #58854 from nextcloud/jtr/refactor-View-getLocalFile
refactor(view): `getLocalFile` path handling
2026-03-12 10:05:19 +01:00
Kate c8380b1b62 Merge pull request #58869 from nextcloud/fix/pwd-confirmation 2026-03-12 09:54:15 +01:00
Nextcloud bot 5ff62d5baf fix(l10n): Update translations from Transifex
Signed-off-by: Nextcloud bot <bot@nextcloud.com>
2026-03-12 00:19:26 +00:00
Josh eb5a9085ee Merge pull request #58855 from nextcloud/jtr/test-drop-testTouchFloat
tests - Fix `Implicit conversion from float 500.5 to int loses precision` in ViewTest
2026-03-11 15:07:57 -04:00
Grigory Vodyanov e3c2920c18 feat: add default reminder setting caldav
Signed-off-by: Grigory Vodyanov <scratchx@gmx.com>
2026-03-11 12:45:04 -04:00
Ferdinand Thiessen 9b54b06de5 fix(SecurityMiddleware): return header to distinguish error type
Currently we return a 403 (Forbidden) when the password confirmation
failed - which itself seems to be inappropriate as its basically a login
failing so a 401 (not authorized) is more appropriate.

This is especially a problem because APIs might return 403 internally
for good reason (e.g. user missing permission) but 401 would not be a
problem.

But as this is a breaking change so my solution to be able to
distinguish API error from password confirmation error is:

Add a header inside the response that marks failed password confirmation
`X-NC-Auth-NotConfirmed`.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-03-11 15:11:29 +01:00
Josh 8895970019 test(ViewTest): disable Nextcloud not PHP - drop testTouchFloat()
Our interface contract (and implementations) in IStorage are:
`public function touch(string $path, ?int $mtime = null): bool {`

This wasn't always the case but it is today, so testTouchFloat() no longer makes sense; it's not testing our code, just PHP.

Signed-off-by: Josh <josh.t.richards@gmail.com>
2026-03-10 22:12:42 -04:00
Josh 0a7420d0a4 chore(View): fixup for php-cs
Signed-off-by: Josh <josh.t.richards@gmail.com>
2026-03-10 21:40:44 -04:00
Josh 14e837ce11 refactor(View): add typing to getAbsolutePath and clarify contract
Signed-off-by: Josh <josh.t.richards@gmail.com>
2026-03-10 19:42:16 -04:00
Josh af78da59bc refactor(View): improve readability of getLocalFile and resolvePath
Signed-off-by: Josh <josh.t.richards@gmail.com>
2026-03-10 19:21:47 -04:00
ailkiv e958fa0113 fix: PostgreSQL transaction aborts when caching user mounts
Signed-off-by: ailkiv <a.ilkiv.ye@gmail.com>
2026-03-09 10:02:40 +00:00
96 changed files with 647 additions and 571 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
<name>WebDAV</name>
<summary>WebDAV endpoint</summary>
<description>WebDAV endpoint</description>
<version>1.37.0</version>
<version>1.38.0</version>
<licence>agpl</licence>
<author>owncloud.org</author>
<namespace>DAV</namespace>
+1 -2
View File
@@ -92,7 +92,6 @@ $server = $serverFactory->createServer(
}
$share = $authBackend->getShare();
$owner = $share->getShareOwner();
$isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
$fileId = $share->getNodeId();
@@ -107,7 +106,7 @@ $server = $serverFactory->createServer(
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
$rootFolder = Server::get(IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($owner);
$userFolder = $rootFolder->getUserFolder($share->getSharedBy());
$node = $userFolder->getFirstNodeById($fileId);
if (!$node) {
throw new \Sabre\DAV\Exception\NotFound();
+1 -2
View File
@@ -99,7 +99,6 @@ $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin,
}
$share = $authBackend->getShare();
$owner = $share->getShareOwner();
$isReadable = $share->getPermissions() & Constants::PERMISSION_READ;
$fileId = $share->getNodeId();
@@ -135,7 +134,7 @@ $server = $serverFactory->createServer(true, $baseuri, $requestUri, $authPlugin,
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
$rootFolder = Server::get(IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($owner);
$userFolder = $rootFolder->getUserFolder($share->getSharedBy());
$node = $userFolder->getFirstNodeById($fileId);
if (!$node) {
throw new NotFound();
@@ -389,6 +389,7 @@ 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,6 +404,7 @@ 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',
+3 -6
View File
@@ -151,6 +151,7 @@ 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'],
];
/**
@@ -1570,12 +1571,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
}
if ($forceDeletePermanently || $this->config->getAppValue(Application::APP_ID, RetentionService::RETENTION_CONFIG_KEY) === '0') {
$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();
$stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ? AND `calendartype` = ?');
$stmt->execute([$calendarId, $objectUri, $calendarType]);
$this->purgeProperties($calendarId, $data['id']);
@@ -43,7 +43,7 @@ class PublicLinkCheckPlugin extends ServerPlugin {
}
public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
// verify that the owner didn't have their share permissions revoked
// verify that the initiator didn't have their share permissions revoked
if ($this->fileInfo && !$this->fileInfo->isShareable()) {
throw new NotFound();
}
@@ -0,0 +1,37 @@
<?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,4 +1881,43 @@ 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);
$remoteShare = $this->getShareFromExternalShareTable($share->getShareOwner(), $share->getTarget());
} catch (ShareNotFound $e) {
$remoteShare = null;
}
if ($remoteShare) {
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) {
$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 !== '') {
$this->updateSuccessfulReshare($shareId, $token);
$this->storeRemoteId($shareId, $remoteId);
} else {
$this->removeShareFromTable($share);
$this->removeShareFromTable($shareId);
$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->removeShareFromTableById($shareId);
$this->removeShareFromTable($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,45 +225,17 @@ 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(IShare $share) {
protected function getShareFromExternalShareTable(string $owner, string $target) {
$query = $this->dbConnection->getQueryBuilder();
$query->select('*')->from($this->externalShareTable)
->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
->where($query->expr()->eq('user', $query->createNamedParameter($owner)))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($target)));
$qResult = $query->executeQuery();
$result = $qResult->fetchAllAssociative();
$qResult->closeCursor();
@@ -468,7 +440,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);
$this->removeShareFromTable($share->getId());
}
/**
@@ -493,19 +465,10 @@ 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.
*/
private function removeShareFromTableById(string $shareId): void {
public function removeShareFromTable(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);
$this->federatedShareProvider->removeShareFromTable($share->getId());
$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);
$this->federatedShareProvider->removeShareFromTable($share->getId());
return [];
}
@@ -249,18 +249,18 @@ class FederatedShareProviderReshareRemoteTest extends \Test\TestCase {
$qb6->method('executeQuery')->willReturn($result6);
$queryBuilderMatcher = $this->exactly(8);
$queryBuilderMatcher = $this->exactly(7);
$this->connection
->expects($queryBuilderMatcher)
->method('getQueryBuilder')
->willReturnCallback(function () use ($queryBuilderMatcher, $qb1, $qb2, $qb3, $qb4, $qb5, $qb6) {
return match ($queryBuilderMatcher->numberOfInvocations()) {
1, 2 => $qb1,
3, 5 => $qb2,
3 => $qb2,
4 => $qb3,
6 => $qb4,
7 => $qb5,
8 => $qb6,
5 => $qb4,
6 => $qb5,
7 => $qb6,
default => throw new LogicException('Unexpected number of invocations for getQueryBuilder')
};
});
@@ -133,7 +133,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setExpirationDate($expirationDate)
->setNode($node);
->setNode($node)
->setTarget('');
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -215,7 +216,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -268,7 +270,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -359,7 +362,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->tokenHandler->method('generateToken')->willReturn('token');
@@ -431,7 +435,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setExpirationDate(new \DateTime('2019-02-01T01:02:03'))
->setNode($node);
->setNode($node)
->setTarget('');
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->addressHandler->expects($this->any())->method('generateRemoteURL')
@@ -504,7 +509,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);
$share2 = $this->shareManager->newShare();
@@ -513,7 +519,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('sharedBy', IShare::TYPE_REMOTE, null, false, -1, 0);
@@ -548,7 +555,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);
$node2 = $this->getMockBuilder(File::class)->getMock();
@@ -561,7 +569,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node2);
->setNode($node2)
->setTarget('');
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('sharedBy', IShare::TYPE_REMOTE, $node2, false, -1, 0);
@@ -595,7 +604,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);
$share2 = $this->shareManager->newShare();
@@ -604,7 +614,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_REMOTE, null, true, -1, 0);
@@ -645,7 +656,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);
$share2 = $this->shareManager->newShare();
@@ -654,7 +666,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share2);
$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_REMOTE, null, true, 1, 1);
@@ -835,7 +848,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1);
->setNode($file1)
->setTarget('');
$this->provider->create($share1);
$share2 = $this->shareManager->newShare();
@@ -844,7 +858,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file2);
->setNode($file2)
->setTarget('');
$this->provider->create($share2);
$result = $this->provider->getSharesInFolder($u1->getUID(), $folder1, false);
@@ -895,7 +910,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1);
->setNode($file1)
->setTarget('');
$this->provider->create($share1);
$share2 = $this->shareManager->newShare();
@@ -904,7 +920,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setShareOwner($u1->getUID())
->setPermissions(Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1);
->setNode($file1)
->setTarget('');
$this->provider->create($share2);
$result = $this->provider->getAccessList([$file1], true);
+4
View File
@@ -122,6 +122,7 @@ 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",
@@ -131,6 +132,8 @@ 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",
@@ -139,6 +142,7 @@ 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,6 +120,7 @@
"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",
@@ -129,6 +130,8 @@
"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",
@@ -137,6 +140,7 @@
"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,10 +104,7 @@ class DeleteOrphanedFilesTest extends TestCase {
$this->assertEquals(1, $this->getMountsCount($numericStorageId), 'Asserts that mount is still available');
$qb = $this->connection->getQueryBuilder();
$deletedRows = $qb->delete('storages')
->where($qb->expr()->eq('id', $qb->createNamedParameter($storageId)))
->executeStatement();
$deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]);
$this->assertNotNull($deletedRows, 'Asserts that storage got deleted');
$this->assertSame(1, $deletedRows, 'Asserts that storage got deleted');
+3
View File
@@ -165,6 +165,7 @@ 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})",
@@ -247,6 +248,7 @@ 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",
@@ -255,6 +257,7 @@ 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,6 +163,7 @@
"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})",
@@ -245,6 +246,7 @@
"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",
@@ -253,6 +255,7 @@
"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",
@@ -1390,6 +1390,8 @@ class ShareAPIController extends OCSController {
} catch (HintException $e) {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\InvalidArgumentException $e) {
throw new OCSBadRequestException($e->getMessage(), $e);
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSBadRequestException('Failed to update share.', $e);
@@ -70,7 +70,7 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase {
$this->connection = Server::get(IDBConnection::class);
// clear occasional leftover shares from other tests
$this->connection->getQueryBuilder()->delete('share')->executeStatement();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
$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->getQueryBuilder()->delete('share')->executeStatement();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
$userManager = Server::get(IUserManager::class);
$user1 = $userManager->get($this->user1);
@@ -104,10 +104,7 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase {
private function getShares() {
$shares = [];
$result = $this->connection->getQueryBuilder()
->select('*')
->from('share')
->executeQuery();
$result = $this->connection->executeQuery('SELECT * FROM `*PREFIX*share`');
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->getQueryBuilder()->delete('share')->executeStatement();
$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
$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->getQueryBuilder()->delete('share')->executeStatement();
$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
$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->getQueryBuilder()->delete('files_trash')->executeStatement();
$connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`');
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",
+44 -35
View File
@@ -8,6 +8,7 @@
namespace OCA\User_LDAP\Mapping;
use Doctrine\DBAL\Exception;
use OCP\DB\IPreparedStatement;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IAppConfig;
use OCP\ICache;
@@ -153,6 +154,23 @@ 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.
@@ -181,16 +199,13 @@ abstract class AbstractMapping {
*/
public function setDNbyUUID($fdn, $uuid) {
$oldDn = $this->getDnByUUID($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;
}
$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]);
if ($r) {
if (is_string($oldDn) && isset($this->cache[$oldDn])) {
$userId = $this->cache[$oldDn];
@@ -216,17 +231,15 @@ 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]);
$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;
}
return $this->modify($statement, [$uuid, $this->getDNHash($fdn)]);
}
/**
@@ -320,14 +333,14 @@ abstract class AbstractMapping {
* @return string[]
*/
public function getNamesBySearch(string $search, string $prefixMatch = '', string $postfixMatch = ''): array {
$qb = $this->dbc->getQueryBuilder();
$statement = $this->dbc->prepare('
SELECT `owncloud_name`
FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` LIKE ?
');
try {
$res = $qb->select('owncloud_name')
->from($this->getTableName(false))
->where($qb->expr()->like('owncloud_name', $qb->createNamedParameter(
$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch
)))
->executeQuery();
$res = $statement->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]);
} catch (Exception $e) {
return [];
}
@@ -335,7 +348,6 @@ abstract class AbstractMapping {
while ($row = $res->fetchAssociative()) {
$names[] = $row['owncloud_name'];
}
$res->closeCursor();
return $names;
}
@@ -431,20 +443,17 @@ 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);
$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;
}
return $this->modify($statement, [$name]);
}
/**
+1
View File
@@ -204,6 +204,7 @@ 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,6 +202,7 @@
"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->fetchAssociative();
$row = $result->fetch();
$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->fetchAssociative();
$row = $result->fetch();
$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->fetchAllAssociative();
$accountData = $result->fetchAll();
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$matches[$row['uid']] = $row['value'];
}
$result->closeCursor();
+1 -1
View File
@@ -1360,7 +1360,7 @@ class AppConfig implements IAppConfig {
}
$result = $qb->executeQuery();
$rows = $result->fetchAllAssociative();
$rows = $result->fetchAll();
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,6 +14,7 @@ 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;
@@ -280,6 +281,9 @@ 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->fetchAssociative();
$data = $result->fetch();
$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->fetchAssociative();
$data = $result->fetch();
$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->fetchAllAssociative();
$data = $result->fetchAll();
$result->closeCursor();
$entities = array_map(function ($row) {
@@ -178,7 +178,7 @@ class PublicKeyTokenMapper extends QBMapper {
->setMaxResults(1);
$cursor = $qb->executeQuery();
$data = $cursor->fetchAllAssociative();
$data = $cursor->fetchAll();
$cursor->closeCursor();
return count($data) === 1;
@@ -242,7 +242,7 @@ class PublicKeyTokenMapper extends QBMapper {
->orderBy('id');
$result = $qb->executeQuery();
$data = $result->fetchAssociative();
$data = $result->fetch();
$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->fetchAllAssociative() as $row) {
foreach ($result->fetchAll() 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->fetchAllAssociative();
$rows = $selectResult->fetchAll();
$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->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
return (bool)$row;
@@ -158,7 +158,7 @@ class JobList implements IJobList {
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$job = $this->buildJob($row);
if ($job) {
yield $job;
@@ -190,7 +190,7 @@ class JobList implements IJobList {
}
$result = $query->executeQuery();
$row = $result->fetchAssociative();
$row = $result->fetch();
$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->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
@@ -407,7 +407,7 @@ class JobList implements IJobList {
try {
$result = $query->executeQuery();
$hasReservedJobs = $result->fetchAssociative() !== false;
$hasReservedJobs = $result->fetch() !== false;
$result->closeCursor();
return $hasReservedJobs;
} catch (Exception $e) {
@@ -429,7 +429,7 @@ class JobList implements IJobList {
$jobs = [];
while (($row = $result->fetchAssociative()) !== false) {
while (($row = $result->fetch()) !== 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->fetchAllAssociative();
$rows = $result->fetchAll();
$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->fetchAllAssociative();
$rows = $result->fetchAll();
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative();
$row = $result->fetch();
$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->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if (!$row) {
@@ -120,7 +120,7 @@ class Manager implements IManager {
$collections = [];
$foundResults = 0;
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if (!$row) {
@@ -216,7 +216,7 @@ class Manager implements IManager {
$resources = [];
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
if ($row = $result->fetch()) {
$hasAccess = (bool)$row['access'];
}
$result->closeCursor();
@@ -330,7 +330,7 @@ class Manager implements IManager {
$hasAccess = null;
$result = $query->executeQuery();
if ($row = $result->fetchAssociative()) {
if ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchNumeric();
$data = $resultStatement->fetch(\PDO::FETCH_NUM);
$resultStatement->closeCursor();
$children = (int)$data[0];
@@ -255,7 +255,7 @@ class Manager implements ICommentsManager {
->setParameter('id', $id, IQueryBuilder::PARAM_INT)
->executeQuery();
$data = $resultStatement->fetchAssociative();
$data = $resultStatement->fetch();
$resultStatement->closeCursor();
if (!$data) {
throw new NotFoundException();
@@ -290,7 +290,7 @@ class Manager implements ICommentsManager {
}
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetchAssociative()) {
while ($data = $resultStatement->fetch()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$tree['replies'][] = [
@@ -349,7 +349,7 @@ class Manager implements ICommentsManager {
}
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetchAssociative()) {
while ($data = $resultStatement->fetch()) {
$comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
@@ -511,7 +511,7 @@ class Manager implements ICommentsManager {
}
$resultStatement = $query->executeQuery();
while ($data = $resultStatement->fetchAssociative()) {
while ($data = $resultStatement->fetch()) {
$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->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if ($row) {
@@ -609,7 +609,7 @@ class Manager implements ICommentsManager {
$comments = [];
$result = $query->executeQuery();
while ($data = $result->fetchAssociative()) {
while ($data = $result->fetch()) {
$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->fetchAssociative()) {
while ($data = $resultStatement->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$unreadComments[$row['object_id']] = (int)$row['num_comments'];
}
$result->closeCursor();
@@ -743,7 +743,7 @@ class Manager implements ICommentsManager {
}
$result = $query->executeQuery();
$data = $result->fetchAssociative();
$data = $result->fetch();
$result->closeCursor();
return (int)($data['num_messages'] ?? 0);
@@ -771,7 +771,7 @@ class Manager implements ICommentsManager {
}
$result = $query->executeQuery();
$data = $result->fetchAssociative();
$data = $result->fetch();
$result->closeCursor();
return (int)($data['id'] ?? 0);
@@ -808,7 +808,7 @@ class Manager implements ICommentsManager {
->groupBy('actor_id');
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($data = $result->fetch()) {
$commentIds[] = $data['message_id'];
}
@@ -1006,7 +1006,7 @@ class Manager implements ICommentsManager {
->executeQuery();
$commentIds = [];
while ($data = $result->fetchAssociative()) {
while ($data = $result->fetch()) {
$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->fetchAssociative()) {
while ($data = $result->fetch()) {
$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->fetchAssociative();
$data = $resultStatement->fetch();
$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->fetchAllAssociative();
$rows = $result->fetchAll();
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
yield $row['userid'];
}
}
@@ -1773,7 +1773,7 @@ class UserConfig implements IUserConfig {
}
$result = $qb->executeQuery();
$rows = $result->fetchAllAssociative();
$rows = $result->fetchAll();
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->executeStatement('LOCK TABLE `' . $tableName . '` IN EXCLUSIVE MODE');
$this->conn->executeUpdate('LOCK TABLE `' . $tableName . '` IN EXCLUSIVE MODE');
}
/**
@@ -99,7 +99,7 @@ class Adapter {
$query .= ' HAVING COUNT(*) = 0';
try {
return $this->conn->executeStatement($query, $inserts);
return $this->conn->executeUpdate($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->executeStatement('LOCK TABLES `' . $tableName . '` WRITE');
$this->conn->executeUpdate('LOCK TABLES `' . $tableName . '` WRITE');
}
public function unlockTable() {
$this->conn->executeStatement('UNLOCK TABLES');
$this->conn->executeUpdate('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->executeStatement($queryString, $builder->getParameters(), $builder->getParameterTypes());
return $this->conn->executeUpdate($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->executeStatement('BEGIN EXCLUSIVE TRANSACTION');
$this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION');
}
public function unlockTable() {
$this->conn->executeStatement('COMMIT TRANSACTION');
$this->conn->executeUpdate('COMMIT TRANSACTION');
}
public function fixupStatement($statement) {
@@ -67,7 +67,7 @@ class AdapterSqlite extends Adapter {
$query .= ')';
try {
return $this->conn->executeStatement($query, $inserts);
return $this->conn->executeUpdate($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
+16 -9
View File
@@ -65,35 +65,42 @@ class ArrayResult implements IResult {
#[Override]
public function fetchOne() {
$row = array_shift($this->rows);
return $row !== null ? current($row) : false;
$row = $this->fetch();
if ($row) {
return current($row);
}
return false;
}
#[Override]
public function fetchAssociative(): array|false {
$row = array_shift($this->rows);
return $row !== null ? $row : false;
$row = $this->fetch();
if ($row) {
return $row;
}
return false;
}
#[Override]
public function fetchNumeric(): array|false {
$row = array_shift($this->rows);
return $row !== null ? array_values($row) : false;
return $this->fetch(PDO::FETCH_NUM);
}
#[Override]
public function fetchAllNumeric(): array {
return array_map(static fn (array $row): array => array_values($row), $this->rows);
return $this->fetchAll(PDO::FETCH_NUM);
}
#[Override]
public function fetchAllAssociative(): array {
return $this->rows;
return $this->fetchAll();
}
#[Override]
public function fetchFirstColumn(): array {
return array_map(static fn (array $row): mixed => current($row), $this->rows);
return $this->fetchAll(PDO::FETCH_COLUMN);
}
#[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->executeStatement($sql, $params, $types);
return $this->inner->executeUpdate($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->fetchFirstColumn();
$rows = $result->fetchAll(\PDO::FETCH_COLUMN);
$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->fetchAssociative();
$row = $result->fetch();
$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->fetchOne());
$row = strtolower($result->fetchColumn());
$result->closeCursor();
if ($row === false) {
+3 -13
View File
@@ -42,21 +42,11 @@ class PreparedStatement implements IPreparedStatement {
}
public function fetch(int $fetchMode = PDO::FETCH_ASSOC) {
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),
};
return $this->getResult()->fetch($fetchMode);
}
public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array {
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),
};
return $this->getResult()->fetchAll($fetchMode);
}
public function fetchColumn() {
@@ -76,7 +66,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()->fetchAllAssociative();
$partitionedRows = $this->query->executeQuery()->fetchAll();
$columns = $this->query->getOutputColumns();
$nullResult = array_combine($columns, array_fill(0, count($columns), null));
@@ -43,36 +43,6 @@ 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();
@@ -81,7 +51,7 @@ class PartitionedResult extends ArrayResult {
private function fetchRows(): void {
if (!$this->fetched) {
$this->fetched = true;
$this->rows = $this->result->fetchAllAssociative();
$this->rows = $this->result->fetchAll();
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()->fetchAllAssociative());
$results = array_merge($results, $query->executeQuery()->fetchAll());
}
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()->fetchAllAssociative();
$query->executeQuery()->fetchAll();
}
/**
@@ -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->fetchAllAssociative());
$results = array_merge($results, $subResult->fetchAll());
$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->fetchAllAssociative();
$rows = $subResult->fetchAll();
$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()->executeStatement('PRAGMA case_sensitive_like = ' . $sensitive);
$args->getConnection()->executeStatement('PRAGMA journal_mode = ' . $this->journalMode);
$args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive);
$args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode);
/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
$connection = $args->getConnection()->getWrappedConnection();
$pdo = $connection->getWrappedConnection();
+2 -1
View File
@@ -6,6 +6,7 @@
*/
namespace OC\DirectEditing;
use Doctrine\DBAL\FetchMode;
use OCA\Encryption\Util;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
@@ -197,7 +198,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->fetchAssociative()) {
if ($tokenRow = $result->fetch(FetchMode::ASSOCIATIVE)) {
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->fetchAssociative();
$data = $result->fetch();
$result->closeCursor();
if ($data !== false) {
@@ -231,7 +231,7 @@ class Cache implements ICache {
$metadataQuery = $query->selectMetadata();
$result = $query->executeQuery();
$files = $result->fetchAllAssociative();
$files = $result->fetchAll();
$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()->fetchFirstColumn();
return $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
}
/**
@@ -1038,7 +1038,7 @@ class Cache implements ICache {
}
$result = $query->executeQuery();
$rows = $result->fetchAllAssociative();
$rows = $result->fetchAll();
$result->closeCursor();
if ($rows) {
@@ -1112,7 +1112,7 @@ class Cache implements ICache {
->whereStorageId($this->getNumericStorageId());
$result = $query->executeQuery();
$files = $result->fetchFirstColumn();
$files = $result->fetchAll(\PDO::FETCH_COLUMN);
$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->fetchAssociative();
$row = $result->fetch();
$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()->fetchAssociative();
$row = $query->executeQuery()->fetch();
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()->fetchAllAssociative();
$rows = $query->executeQuery()->fetchAll();
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()->fetchAllAssociative();
$rows = $query->executeQuery()->fetchAll();
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->fetchAssociative();
$root = $result->fetch();
$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->fetchAssociative())) {
while (count($rows) < 1000 && ($row = $files->fetch())) {
$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->fetchAllAssociative();
$parentRows = $result->fetchAll();
$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->fetchAssociative());
} while ($rows[] = $files->fetch());
} else {
while (
/** @var array */
$row = $files->fetchAssociative()
$row = $files->fetch()
) {
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->fetchAssociative()
$row = $result->fetch()
) {
$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()->fetchAssociative();
$root = $qb->executeQuery()->fetch();
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->fetchAllAssociative();
$tags = $result->fetchAll();
$result->closeCursor();
return $tags;
}
@@ -172,7 +172,7 @@ class QuerySearchHelper {
$this->applySearchConstraints($query, $searchQuery, $caches, $metadataQuery);
$result = $query->executeQuery();
$files = $result->fetchAllAssociative();
$files = $result->fetchAll();
$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()->fetchFirstColumn();
$storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
$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->fetchAssociative()) !== false) {
while (($row = $result->fetch()) !== 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->fetchAssociative();
$row = $result->fetch();
$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->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if ($row !== false) {
+24 -46
View File
@@ -7,10 +7,8 @@
*/
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;
@@ -167,25 +165,15 @@ class UserMountCache implements IUserMountCache {
private function addToCache(ICachedMountInfo $mount) {
if ($mount->getStorageId() !== -1) {
$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;
}
}
$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(),
]);
} else {
// in some cases this is legitimate, like orphaned shares
$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
@@ -267,7 +255,7 @@ class UserMountCache implements IUserMountCache {
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userUID)));
$result = $query->executeQuery();
$rows = $result->fetchAllAssociative();
$rows = $result->fetchAll();
$result->closeCursor();
/** @var array<string, ICachedMountInfo> $mounts */
@@ -312,7 +300,7 @@ class UserMountCache implements IUserMountCache {
}
$result = $query->executeQuery();
$rows = $result->fetchAllAssociative();
$rows = $result->fetchAll();
$result->closeCursor();
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
@@ -330,7 +318,7 @@ class UserMountCache implements IUserMountCache {
->where($builder->expr()->eq('root_id', $builder->createNamedParameter($rootFileId, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$rows = $result->fetchAllAssociative();
$rows = $result->fetchAll();
$result->closeCursor();
return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
@@ -349,7 +337,7 @@ class UserMountCache implements IUserMountCache {
->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$result = $query->executeQuery();
$row = $result->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if (is_array($row)) {
@@ -408,7 +396,7 @@ class UserMountCache implements IUserMountCache {
$result = $query->executeQuery();
$mounts = [];
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
if ($user === null && !$this->userManager->userExists($row['user_id'])) {
continue;
}
@@ -481,7 +469,7 @@ class UserMountCache implements IUserMountCache {
$result = $query->executeQuery();
$results = [];
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$results[$row['user_id']] = $row['size'];
}
$result->closeCursor();
@@ -539,25 +527,15 @@ class UserMountCache implements IUserMountCache {
}
public function addMount(IUser $user, string $mountPoint, ICacheEntry $rootCacheEntry, string $mountProvider, ?int $mountId = null): void {
$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;
}
}
$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
]);
}
/**
+1 -1
View File
@@ -131,7 +131,7 @@ class Loader implements IMimeTypeLoader {
->from('mimetypes');
$result = $qb->executeQuery();
$results = $result->fetchAllAssociative();
$results = $result->fetchAll();
$result->closeCursor();
foreach ($results as $row) {
+32 -20
View File
@@ -96,12 +96,15 @@ class View {
}
/**
* @param ?string $path
* Returns an absolute path in Nextcloud's virtual filesystem for this view.
*
* The returned path is scoped by this view's fake root.
*
* @psalm-template S as string|null
* @psalm-param S $path
* @psalm-return (S is string ? string : null)
*/
public function getAbsolutePath($path = '/'): ?string {
public function getAbsolutePath(?string $path = '/'): ?string {
if ($path === null) {
return null;
}
@@ -185,33 +188,42 @@ class View {
}
/**
* Resolve a path to a storage and internal path
* Resolve a path to a storage and internal path.
*
* @param string $path
* @return array{?IStorage, string} an array consisting of the storage and the 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]
*/
public function resolvePath($path): array {
$a = $this->getAbsolutePath($path);
$p = Filesystem::normalizePath($a);
return Filesystem::resolvePath($p);
public function resolvePath(string $path): array {
$absolutePath = $this->getAbsolutePath($path);
$normalizedPath = Filesystem::normalizePath($absolutePath);
return Filesystem::resolvePath($normalizedPath);
}
/**
* 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
* Return the path to a local representation of a file.
*
* @param string $path
* 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
*/
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 {
public function getLocalFile(string $path): string|false {
$parentPath = dirname($path);
if (!Filesystem::isValidPath($parentPath)) {
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 = (int)$query->executeQuery()->fetchOne();
$storageId = $query->executeQuery()->fetchColumn();
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->fetchAssociative();
$data = $result->fetch();
$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->fetchAssociative()) {
while ($data = $result->fetch()) {
$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->fetchAssociative();
$result = $cursor->fetch();
$cursor->closeCursor();
return $result ? true : false;
@@ -221,7 +221,7 @@ class Database extends ABackend implements
->executeQuery();
$groups = [];
while ($row = $cursor->fetchAssociative()) {
while ($row = $cursor->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative();
$result = $cursor->fetch();
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$details[(string)$row['gid']] = ['displayName' => (string)$row['displayname']];
$this->groupCache[(string)$row['gid']] = [
'displayname' => (string)$row['displayname'],
+2 -2
View File
@@ -83,7 +83,7 @@ class BackgroundCleanupJob extends TimedJob {
}
$cursor = $qb->executeQuery();
while ($row = $cursor->fetchAssociative()) {
while ($row = $cursor->fetch()) {
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()->fetchFirstColumn();
$found = $qb->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$orphanItems[] = (int)$row[$deleteId];
}
+2 -2
View File
@@ -87,7 +87,7 @@ class Collation implements IRepairStep {
. " AND TABLE_NAME LIKE '*PREFIX*%'",
[$dbName]
);
$rows = $statement->fetchAllAssociative();
$rows = $statement->fetchAll();
$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->fetchAllAssociative();
$rows = $statement->fetchAll();
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->fetchAssociative()) {
while ($row = $result->fetch()) {
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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAllAssociative();
$identifiers = $result->fetchAll();
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
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->fetchAssociative()) {
while ($entry = $result->fetch()) {
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->fetchAssociative();
$data = $result->fetch();
$result->closeCursor();
return (int)$data['total'];
@@ -166,7 +166,7 @@ class RemoveLinkShares implements IRepairStep {
$output->startProgress($total);
$shareResult = $this->getShares();
while ($data = $shareResult->fetchAssociative()) {
while ($data = $shareResult->fetch()) {
$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->fetchAssociative()) {
while ($share = $statement->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$deletedInLastChunk++;
$deletedEntries += $deleteQuery->setParameter('parent', (int)$row['parent'])
->executeStatement();
@@ -43,7 +43,7 @@ class DatabaseBackend implements IBackend {
}
$result = $query->executeQuery();
$row = $result->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
return (int)$row['attempts'];
+1 -1
View File
@@ -61,7 +61,7 @@ class CredentialsManager implements ICredentialsManager {
}
$qResult = $qb->executeQuery();
$result = $qResult->fetchAssociative();
$result = $qResult->fetch();
$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->executeStatement($query);
$connection->executeUpdate($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->executeStatement($query);
$connection->executeUpdate($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->fetchAllAssociative();
$data = $result->fetchAll();
$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->fetchAssociative();
$data = $stmt->fetch();
$stmt->closeCursor();
/*
@@ -392,7 +392,7 @@ class DefaultShareProvider implements
->orderBy('id');
$cursor = $qb->executeQuery();
while ($data = $cursor->fetchAssociative()) {
while ($data = $cursor->fetch()) {
$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->fetchAssociative();
$data = $stmt->fetch();
/*
* 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->fetchAssociative();
$data = $cursor->fetch();
$cursor->closeCursor();
$originalPermission = $data['permissions'];
@@ -577,7 +577,7 @@ class DefaultShareProvider implements
->setMaxResults(1)
->executeQuery();
$data = $stmt->fetchAssociative();
$data = $stmt->fetch();
$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->fetchAssociative()) {
while ($data = $cursor->fetch()) {
$shares[$data['fileid']][] = $this->createShare($data);
}
$cursor->closeCursor();
@@ -736,7 +736,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
$shares = [];
while ($data = $cursor->fetchAssociative()) {
while ($data = $cursor->fetch()) {
$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->fetchAssociative();
$data = $cursor->fetch();
$cursor->closeCursor();
if ($data === false) {
@@ -805,7 +805,7 @@ class DefaultShareProvider implements
->executeQuery();
$shares = [];
while ($data = $cursor->fetchAssociative()) {
while ($data = $cursor->fetch()) {
$shares[] = $this->createShare($data);
}
$cursor->closeCursor();
@@ -927,7 +927,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
while ($data = $cursor->fetchAssociative()) {
while ($data = $cursor->fetch()) {
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->fetchAssociative()) {
while ($data = $cursor->fetch()) {
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->fetchAssociative();
$data = $cursor->fetch();
if ($data === false) {
throw new ShareNotFound();
@@ -1176,7 +1176,7 @@ class DefaultShareProvider implements
$stmt = $query->executeQuery();
while ($data = $stmt->fetchAssociative()) {
while ($data = $stmt->fetch()) {
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->fetchAssociative()) {
while ($row = $cursor->fetch()) {
$ids[] = (int)$row['id'];
}
$cursor->closeCursor();
@@ -1320,7 +1320,7 @@ class DefaultShareProvider implements
$cursor = $qb->executeQuery();
$ids = [];
while ($row = $cursor->fetchAssociative()) {
while ($row = $cursor->fetch()) {
$ids[] = (int)$row['id'];
}
$cursor->closeCursor();
@@ -1423,7 +1423,7 @@ class DefaultShareProvider implements
$users = [];
$link = false;
while ($row = $cursor->fetchAssociative()) {
while ($row = $cursor->fetch()) {
$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->fetchAssociative()) {
while ($data = $cursor->fetch()) {
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->fetchAssociative()) {
while ($data = $cursor->fetch()) {
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->fetchAssociative()) {
while ($row = $result->fetch()) {
$groups[] = $row['gid'];
}
$result->closeCursor();
@@ -139,7 +139,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->executeQuery();
$users = [];
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative();
$fetch = $result->fetch();
$result->closeCursor();
$result = !empty($fetch) ? true : false;
@@ -226,7 +226,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->setMaxResults(1)
->executeQuery();
$isSubAdmin = $result->fetchAssociative();
$isSubAdmin = $result->fetch();
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$tags[$row['id']] = $this->createSystemTagFromRow($row);
}
@@ -139,7 +139,7 @@ class SystemTagManager implements ISystemTagManager {
->setParameter('editable', $userAssignable ? 1 : 0)
->executeQuery();
$row = $result->fetchAssociative();
$row = $result->fetch();
$result->closeCursor();
if (!$row) {
throw new TagNotFoundException(
@@ -452,7 +452,7 @@ class SystemTagManager implements ISystemTagManager {
->orderBy('gid');
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$objectId = $row['objectid'];
$mapping[$objectId][] = (string)$row['systemtagid'];
}
@@ -99,7 +99,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$objectIds = [];
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAllAssociative();
$rows = $result->fetchAll();
$existingTags = [];
foreach ($rows as $row) {
$existingTags[] = $row['systemtagid'];
@@ -259,7 +259,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
->setParameter('objecttype', $objectType);
$result = $query->executeQuery();
$row = $result->fetchNumeric();
$row = $result->fetch(\PDO::FETCH_NUM);
$result->closeCursor();
if ($all) {
@@ -376,7 +376,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$result = $query->executeQuery();
$objectTypes = [];
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchFirstColumn();
$users = $result->fetchAll(\PDO::FETCH_COLUMN);
$result->closeCursor();
return $users;
@@ -106,7 +106,7 @@ class TagManager implements ITagManager, IEventListener {
return;
}
$tagsIds = array_map(fn (array $row) => (int)$row['id'], $result->fetchAllAssociative());
$tagsIds = array_map(fn (array $row) => (int)$row['id'], $result->fetchAll());
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
$objId = (int)$row['objid'];
if (!isset($entries[$objId])) {
$entries[$objId] = [];
@@ -223,7 +223,7 @@ class Tags implements ITags {
return false;
}
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative() !== false;
$hasRunningTasks = $result->fetch() !== 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->fetchAssociative()) {
while ($row = $result->fetch()) {
$displayNames[(string)$row['uid']] = (string)$row['displayname'];
}
@@ -328,7 +328,7 @@ class Database extends ABackend implements
$result = $query->executeQuery();
$displayNames = [];
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$displayNames[(string)$row['uid']] = (string)$row['displayname'];
}
@@ -389,7 +389,7 @@ class Database extends ABackend implements
)
);
$result = $qb->executeQuery();
$row = $result->fetchAssociative();
$row = $result->fetch();
$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->fetchAssociative()) {
while ($row = $query->fetch()) {
$result[] = $row['userid'];
}
@@ -774,7 +774,7 @@ class Manager extends PublicEmitter implements IUserManager {
}
/** @var list<string> */
$list = $queryBuilder->executeQuery()->fetchFirstColumn();
$list = $queryBuilder->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
return $list;
}
+4 -4
View File
@@ -275,7 +275,7 @@ abstract class QBMapper {
protected function findOneQuery(IQueryBuilder $query): array {
$result = $query->executeQuery();
$row = $result->fetchAssociative();
$row = $result->fetch();
if ($row === false) {
$result->closeCursor();
$msg = $this->buildDebugMessage(
@@ -284,7 +284,7 @@ abstract class QBMapper {
throw new DoesNotExistException($msg);
}
$row2 = $result->fetchAssociative();
$row2 = $result->fetch();
$result->closeCursor();
if ($row2 !== false) {
$msg = $this->buildDebugMessage(
@@ -336,7 +336,7 @@ abstract class QBMapper {
$result = $query->executeQuery();
try {
$entities = [];
while ($row = $result->fetchAssociative()) {
while ($row = $result->fetch()) {
$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->fetchAssociative()) {
while ($row = $result->fetch()) {
yield $this->mapRowToEntity($row);
}
} finally {
+154 -101
View File
@@ -23,43 +23,6 @@ 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);
@@ -79,21 +42,30 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig();
// preparation - add something to the database
$this->insertPreferenceRow('userDelete', 'appDelete', 'keyDelete', 'valueDelete');
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, '
. '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
['userDelete', 'appDelete', 'keyDelete', 'valueDelete']
);
$config->deleteUserValue('userDelete', 'appDelete', 'keyDelete');
$actualCount = count($this->getPreferenceRows('userDelete'));
$result = $this->connection->executeQuery(
'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?',
['userDelete']
)->fetchAssociative();
$actualCount = $result['count'];
$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->getPreferenceRows('userSet');
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -106,7 +78,7 @@ class AllConfigTest extends \Test\TestCase {
// test if the method overwrites existing database entries
$config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet2');
$result = $this->getPreferenceRows('userSet');
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -125,11 +97,12 @@ 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->getPreferenceRows('userSet');
$result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -143,9 +116,11 @@ 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->getPreferenceRows('userPreCond');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -158,7 +133,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->getPreferenceRows('userPreCond');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -198,9 +173,11 @@ 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->getPreferenceRows('userPreCond1');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -213,7 +190,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->getPreferenceRows('userPreCond1');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -232,9 +209,11 @@ 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->getPreferenceRows('userPreCond1');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$this->assertCount(1, $result);
$this->assertEquals([
@@ -247,7 +226,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->getPreferenceRows('userPreCond1');
$result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative();
$this->assertCount(1, $result);
$this->assertEquals([
@@ -268,7 +247,7 @@ class AllConfigTest extends \Test\TestCase {
$resultMock = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')
->disableOriginalConstructor()->getMock();
$resultMock->expects($this->once())
->method('fetchOne')
->method('fetchColumn')
->willReturn('valueSetUnchanged');
$connectionMock = $this->createMock(IDBConnection::class);
@@ -279,7 +258,7 @@ class AllConfigTest extends \Test\TestCase {
$this->equalTo(['userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged']))
->willReturn($resultMock);
$connectionMock->expects($this->never())
->method('executeStatement');
->method('executeUpdate');
$config = $this->getConfig(null, $connectionMock);
@@ -295,7 +274,10 @@ class AllConfigTest extends \Test\TestCase {
$this->assertEquals('valueGet', $value);
$result = $this->getPreferenceRows('userGet');
$result = $this->connection->executeQuery(
'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
['userGet']
)->fetchAllAssociative();
$this->assertEquals(1, count($result));
$this->assertEquals([
@@ -306,30 +288,41 @@ class AllConfigTest extends \Test\TestCase {
], $result[0]);
// drop data from database - but the config option should be cached in the config object
$qb = $this->connection->getQueryBuilder();
$qb->delete('preferences')
->where($qb->expr()->eq('userid', $qb->createNamedParameter('userGet')))
->executeStatement();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?', ['userGet']);
// testing the caching mechanism
$value = $config->getUserValue('userGet', 'appGet', 'keyGet');
$this->assertEquals('valueGet', $value);
$this->assertEquals(0, count($this->getPreferenceRows('userGet')));
$result = $this->connection->executeQuery(
'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?',
['userGet']
)->fetchAllAssociative();
$this->assertEquals(0, count($result));
}
public function testGetUserKeys(): void {
$config = $this->getConfig();
// preparation - add something to the database
$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');
$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
);
}
$value = $config->getUserKeys('userFetch', 'appFetch1');
$this->assertEquals(['keyFetch1', 'keyFetch2', 'keyFetch4'], $value);
@@ -338,15 +331,24 @@ class AllConfigTest extends \Test\TestCase {
$this->assertEquals(['keyFetch1'], $value);
// cleanup
$this->clearPreferences();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testGetUserKeysAllInts(): void {
$config = $this->getConfig();
// preparation - add something to the database
$this->insertPreferenceRow('userFetch8', 'appFetch1', '123', 'value');
$this->insertPreferenceRow('userFetch8', 'appFetch1', '456', 'value');
$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
);
}
$value = $config->getUserKeys('userFetch8', 'appFetch1');
$this->assertEquals(['123', '456'], $value);
@@ -354,7 +356,7 @@ class AllConfigTest extends \Test\TestCase {
$this->assertIsString($value[1]);
// cleanup
$this->clearPreferences();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testGetUserValueDefault(): void {
@@ -369,13 +371,22 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig();
// preparation - add something to the database
$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');
$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
);
}
$value = $config->getUserValueForUsers('appFetch2', 'keyFetch1',
['userFetch1', 'userFetch2', 'userFetch3', 'userFetch5']);
@@ -394,51 +405,84 @@ class AllConfigTest extends \Test\TestCase {
], $value, 'userFetch9 is an non-existent user and should not be shown.');
// cleanup
$this->clearPreferences();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testDeleteAllUserValues(): void {
$config = $this->getConfig();
// preparation - add something to the database
$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');
$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
);
}
$config->deleteAllUserValues('userFetch3');
$this->assertEquals(1, $this->countPreferenceRows(), 'After removing `userFetch3` there should be exactly 1 entry left.');
$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.');
// cleanup
$this->clearPreferences();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testDeleteAppFromAllUsers(): void {
$config = $this->getConfig();
// preparation - add something to the database
$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');
$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
);
}
$config->deleteAppFromAllUsers('appFetch1');
$this->assertEquals(4, $this->countPreferenceRows(), 'After removing `appFetch1` there should be exactly 4 entries left.');
$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.');
$config->deleteAppFromAllUsers('appFetch2');
$this->assertEquals(2, $this->countPreferenceRows(), 'After removing `appFetch2` there should be exactly 2 entries left.');
$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.');
// cleanup
$this->clearPreferences();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testGetUsersForUserValue(): void {
@@ -449,17 +493,26 @@ class AllConfigTest extends \Test\TestCase {
$config = $this->getConfig($systemConfig);
// preparation - add something to the database
$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');
$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
);
}
$value = $config->getUsersForUserValue('appFetch9', 'keyFetch9', 'value9');
$this->assertEquals(['user1', 'user2', 'user6'], $value);
// cleanup
$this->clearPreferences();
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
}
+1 -1
View File
@@ -149,7 +149,7 @@ class AppConfigTest extends TestCase {
]);
$result = $this->createMock(IResult::class);
$result->method('fetchAllAssociative')->willReturn([
$result->method('fetchAll')->willReturn([
['lazy' => 1, 'appid' => 'appid', 'configkey' => 'lazy-key', 'configvalue' => 'lazy value'],
]);
$expression = $this->createMock(IExpressionBuilder::class);
-14
View File
@@ -595,20 +595,6 @@ 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('fetchAssociative')
->method('fetch')
->willReturnCallback(function () use (&$shareResultData) {
return array_pop($shareResultData) ?? false;
return array_pop($shareResultData);
});
$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('fetchAssociative')
$result->method('fetch')
->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('fetchAssociative')
$result->method('fetch')
->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('fetchAssociative')
$result->method('fetch')
->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('fetchAssociative')
$result->method('fetch')
->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],
+16 -15
View File
@@ -10,7 +10,6 @@ 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;
@@ -29,11 +28,15 @@ use Psr\Log\LoggerInterface;
#[\PHPUnit\Framework\Attributes\Group('DB')]
class TagsTest extends \Test\TestCase {
protected $objectType;
protected IUser $user;
protected IUserSession $userSession;
/** @var IUser */
protected $user;
/** @var IUserSession */
protected $userSession;
protected $backupGlobals = false;
protected TagMapper $tagMapper;
protected ITagManager $tagMgr;
/** @var TagMapper */
protected $tagMapper;
/** @var ITagManager */
protected $tagMgr;
protected IRootFolder $rootFolder;
protected function setUp(): void {
@@ -72,8 +75,8 @@ class TagsTest extends \Test\TestCase {
protected function tearDown(): void {
$conn = Server::get(IDBConnection::class);
$conn->getQueryBuilder()->delete('vcategory_to_object')->executeStatement();
$conn->getQueryBuilder()->delete('vcategory')->executeStatement();
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`');
$conn->executeQuery('DELETE FROM `*PREFIX*vcategory`');
parent::tearDown();
}
@@ -211,18 +214,16 @@ 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++) {
$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();
$statement->execute([$i, $tagId, $tagType]);
$idsArray[] = $i;
}