Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,12 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se
}

if ($forceDeletePermanently || $this->config->getAppValue(Application::APP_ID, RetentionService::RETENTION_CONFIG_KEY) === '0') {
$stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ? AND `calendartype` = ?');
$stmt->execute([$calendarId, $objectUri, $calendarType]);
$qb = $this->db->getQueryBuilder();
$qb->delete('calendarobjects')
->where($qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId)))
->andWhere($qb->expr()->eq('uri', $qb->createNamedParameter($objectUri)))
->andWhere($qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType)))
->executeStatement();

$this->purgeProperties($calendarId, $data['id']);

Expand Down
5 changes: 4 additions & 1 deletion apps/files/tests/Command/DeleteOrphanedFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public function testClearFiles(): void {
$this->assertEquals(1, $this->getMountsCount($numericStorageId), 'Asserts that mount is still available');


$deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]);
$qb = $this->connection->getQueryBuilder();
$deletedRows = $qb->delete('storages')
->where($qb->expr()->eq('id', $qb->createNamedParameter($storageId)))
->executeStatement();
$this->assertNotNull($deletedRows, 'Asserts that storage got deleted');
$this->assertSame(1, $deletedRows, 'Asserts that storage got deleted');

Expand Down
9 changes: 6 additions & 3 deletions apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function setUp(): void {

$this->connection = Server::get(IDBConnection::class);
// clear occasional leftover shares from other tests
$this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->connection->getQueryBuilder()->delete('share')->executeStatement();

$this->user1 = $this->getUniqueID('user1_');
$this->user2 = $this->getUniqueID('user2_');
Expand All @@ -85,7 +85,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
$this->connection->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->connection->getQueryBuilder()->delete('share')->executeStatement();

$userManager = Server::get(IUserManager::class);
$user1 = $userManager->get($this->user1);
Expand All @@ -104,7 +104,10 @@ protected function tearDown(): void {

private function getShares() {
$shares = [];
$result = $this->connection->executeQuery('SELECT * FROM `*PREFIX*share`');
$result = $this->connection->getQueryBuilder()
->select('*')
->from('share')
->executeQuery();
while ($row = $result->fetchAssociative()) {
$shares[] = $row;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/tests/SharesReminderJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function setUp(): void {
$this->mailer = $this->createMock(IMailer::class);

// Clear occasional leftover shares from other tests
$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->db->getQueryBuilder()->delete('share')->executeStatement();

$this->user1 = $this->getUniqueID('user1_');
$this->user2 = $this->getUniqueID('user2_');
Expand All @@ -78,7 +78,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
$this->db->getQueryBuilder()->delete('share')->executeStatement();

$userManager = Server::get(IUserManager::class);
$user1 = $userManager->get($this->user1);
Expand Down
2 changes: 1 addition & 1 deletion apps/files_trashbin/tests/TrashbinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function tearDown(): void {

// clear trash table
$connection = Server::get(IDBConnection::class);
$connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`');
$connection->getQueryBuilder()->delete('files_trash')->executeStatement();

parent::tearDown();
}
Expand Down
79 changes: 35 additions & 44 deletions apps/user_ldap/lib/Mapping/AbstractMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace OCA\User_LDAP\Mapping;

use Doctrine\DBAL\Exception;
use OCP\DB\IPreparedStatement;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IAppConfig;
use OCP\ICache;
Expand Down Expand Up @@ -154,23 +153,6 @@ protected function getXbyY($fetchCol, $compareCol, $search) {
}
}

/**
* 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.
Expand Down Expand Up @@ -199,13 +181,16 @@ public function getDNByName(string $name): string|false {
*/
public function setDNbyUUID($fdn, $uuid) {
$oldDn = $this->getDnByUUID($uuid);
$statement = $this->dbc->prepare('
UPDATE `' . $this->getTableName() . '`
SET `ldap_dn_hash` = ?, `ldap_dn` = ?
WHERE `directory_uuid` = ?
');

$r = $this->modify($statement, [$this->getDNHash($fdn), $fdn, $uuid]);
$qb = $this->dbc->getQueryBuilder();
try {
$r = $qb->update($this->getTableName(false))
->set('ldap_dn_hash', $qb->createNamedParameter($this->getDNHash($fdn)))
->set('ldap_dn', $qb->createNamedParameter($fdn))
->where($qb->expr()->eq('directory_uuid', $qb->createNamedParameter($uuid)))
->executeStatement() > 0;
} catch (Exception $e) {
$r = false;
}
if ($r) {
if (is_string($oldDn) && isset($this->cache[$oldDn])) {
$userId = $this->cache[$oldDn];
Expand All @@ -231,15 +216,17 @@ public function setDNbyUUID($fdn, $uuid) {
* @return bool
*/
public function setUUIDbyDN($uuid, $fdn): bool {
$statement = $this->dbc->prepare('
UPDATE `' . $this->getTableName() . '`
SET `directory_uuid` = ?
WHERE `ldap_dn_hash` = ?
');

unset($this->cache[$fdn]);

return $this->modify($statement, [$uuid, $this->getDNHash($fdn)]);
$qb = $this->dbc->getQueryBuilder();
try {
return $qb->update($this->getTableName(false))
->set('directory_uuid', $qb->createNamedParameter($uuid))
->where($qb->expr()->eq('ldap_dn_hash', $qb->createNamedParameter($this->getDNHash($fdn))))
->executeStatement() > 0;
} catch (Exception $e) {
return false;
}
}

/**
Expand Down Expand Up @@ -333,21 +320,22 @@ public function getListOfIdsByDn(array $fdns): array {
* @return string[]
*/
public function getNamesBySearch(string $search, string $prefixMatch = '', string $postfixMatch = ''): array {
$statement = $this->dbc->prepare('
SELECT `owncloud_name`
FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` LIKE ?
');

$qb = $this->dbc->getQueryBuilder();
try {
$res = $statement->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]);
$res = $qb->select('owncloud_name')
->from($this->getTableName(false))
->where($qb->expr()->like('owncloud_name', $qb->createNamedParameter(
$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch
)))
->executeQuery();
} catch (Exception $e) {
return [];
}
$names = [];
while ($row = $res->fetchAssociative()) {
$names[] = $row['owncloud_name'];
}
$res->closeCursor();
return $names;
}

Expand Down Expand Up @@ -443,17 +431,20 @@ public function map($fdn, $name, $uuid) {
* @return bool
*/
public function unmap($name) {
$statement = $this->dbc->prepare('
DELETE FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` = ?');

$dn = array_search($name, $this->cache, true);
if ($dn !== false) {
unset($this->cache[$dn]);
}
$this->localNameToDnCache?->remove($name);

return $this->modify($statement, [$name]);
$qb = $this->dbc->getQueryBuilder();
try {
return $qb->delete($this->getTableName(false))
->where($qb->expr()->eq('owncloud_name', $qb->createNamedParameter($name)))
->executeStatement() > 0;
} catch (Exception $e) {
return false;
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void {
$result = $qb->select($qb->func()->count('*', 'user_count'))
->from('ldap_user_mapping')
->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();

$tooBig = ($row['user_count'] > 50);
Expand All @@ -280,7 +280,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void {
$result = $qb->select($qb->func()->count('*', 'user_count'))
->from('user_saml_users')
->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();

$tooBig = ($row['user_count'] > 50);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected function getUser(IUser $user, bool $insertIfNotExists = true): array {
->where($query->expr()->eq('uid', $query->createParameter('uid')))
->setParameter('uid', $uid);
$result = $query->executeQuery();
$accountData = $result->fetchAll();
$accountData = $result->fetchAllAssociative();
$result->closeCursor();

if (empty($accountData)) {
Expand Down Expand Up @@ -233,7 +233,7 @@ public function searchUsers(string $property, array $values): array {
$query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->executeQuery();

while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$matches[$row['uid']] = $row['value'];
}
$result->closeCursor();
Expand Down
2 changes: 1 addition & 1 deletion lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ private function loadConfig(?string $app = null, bool $lazy = false): void {
}

$result = $qb->executeQuery();
$rows = $result->fetchAll();
$rows = $result->fetchAllAssociative();
foreach ($rows as $row) {
// most of the time, 'lazy' is not in the select because its value is already known
if ($lazy && ((int)$row['lazy']) === 1) {
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Authentication/Token/PublicKeyTokenMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getToken(string $token): PublicKeyToken {
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->executeQuery();

$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data === false) {
throw new DoesNotExistException('token does not exist');
Expand All @@ -97,7 +97,7 @@ public function getTokenById(int $id): PublicKeyToken {
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->executeQuery();

$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data === false) {
throw new DoesNotExistException('token does not exist');
Expand All @@ -123,7 +123,7 @@ public function getTokenByUser(string $uid): array {
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT)))
->setMaxResults(1000);
$result = $qb->executeQuery();
$data = $result->fetchAll();
$data = $result->fetchAllAssociative();
$result->closeCursor();

$entities = array_map(function ($row) {
Expand Down Expand Up @@ -178,7 +178,7 @@ public function hasExpiredTokens(string $uid): bool {
->setMaxResults(1);

$cursor = $qb->executeQuery();
$data = $cursor->fetchAll();
$data = $cursor->fetchAllAssociative();
$cursor->closeCursor();

return count($data) === 1;
Expand Down Expand Up @@ -242,7 +242,7 @@ public function getFirstTokenForUser(string $userId): ?PublicKeyToken {
->orderBy('id');
$result = $qb->executeQuery();

$data = $result->fetch();
$data = $result->fetchAssociative();
$result->closeCursor();
if ($data === false) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getState(string $uid): array {
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
$result = $query->executeQuery();
$providers = [];
foreach ($result->fetchAll() as $row) {
foreach ($result->fetchAllAssociative() as $row) {
$providers[(string)$row['provider_id']] = (int)$row['enabled'] === 1;
}
$result->closeCursor();
Expand Down Expand Up @@ -80,7 +80,7 @@ public function deleteByUser(string $uid): array {
->from(self::TABLE_NAME)
->where($qb1->expr()->eq('uid', $qb1->createNamedParameter($uid)));
$selectResult = $selectQuery->executeQuery();
$rows = $selectResult->fetchAll();
$rows = $selectResult->fetchAllAssociative();
$selectResult->closeCursor();

$qb2 = $this->conn->getQueryBuilder();
Expand Down
12 changes: 6 additions & 6 deletions lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function has(IJob|string $job, mixed $argument): bool {
->setMaxResults(1);

$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();

return (bool)$row;
Expand Down Expand Up @@ -158,7 +158,7 @@ public function getJobsIterator(IJob|string|null $job, ?int $limit, int $offset)

$result = $query->executeQuery();

while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$job = $this->buildJob($row);
if ($job) {
yield $job;
Expand Down Expand Up @@ -190,7 +190,7 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu
}

$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();

if ($row) {
Expand Down Expand Up @@ -293,7 +293,7 @@ public function getDetailsById(string $id): ?array {
->from('jobs')
->where($query->expr()->eq('id', $query->createNamedParameter($id)));
$result = $query->executeQuery();
$row = $result->fetch();
$row = $result->fetchAssociative();
$result->closeCursor();

if ($row) {
Expand Down Expand Up @@ -407,7 +407,7 @@ public function hasReservedJob(?string $className = null): bool {

try {
$result = $query->executeQuery();
$hasReservedJobs = $result->fetch() !== false;
$hasReservedJobs = $result->fetchAssociative() !== false;
$result->closeCursor();
return $hasReservedJobs;
} catch (Exception $e) {
Expand All @@ -429,7 +429,7 @@ public function countByClass(): array {

$jobs = [];

while (($row = $result->fetch()) !== false) {
while (($row = $result->fetchAssociative()) !== false) {
/**
* @var array{count:int, class:class-string<IJob>} $row
*/
Expand Down
Loading
Loading