Skip to content

Commit

Permalink
chore(db): Correctly apply query types
Browse files Browse the repository at this point in the history
  • Loading branch information
solracsf committed Oct 16, 2024
1 parent 94e1241 commit b473774
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 80 deletions.
6 changes: 3 additions & 3 deletions apps/files/lib/Command/DeleteOrphanedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ private function cleanupOrphanedMounts(): int {
$deletedInLastChunk = self::CHUNK_SIZE;
while ($deletedInLastChunk === self::CHUNK_SIZE) {
$deletedInLastChunk = 0;
$result = $query->execute();
while ($row = $result->fetch()) {
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
$deletedInLastChunk++;
$deletedEntries += $deleteQuery->setParameter('storageid', (int)$row['storage_id'])
->execute();
->executeStatement();
}
$result->closeCursor();
}
Expand Down
38 changes: 19 additions & 19 deletions apps/workflowengine/lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function getAllConfiguredEvents() {
->where($query->expr()->neq('events', $query->createNamedParameter('[]'), IQueryBuilder::PARAM_STR))
->groupBy('class', 'entity', $query->expr()->castColumn('events', IQueryBuilder::PARAM_STR));

$result = $query->execute();
$result = $query->executeQuery();
$operations = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$eventNames = \json_decode($row['events']);

$operation = $row['class'];
Expand Down Expand Up @@ -145,10 +145,10 @@ public function getAllConfiguredScopesForOperation(string $operationClass): arra
->where($query->expr()->eq('o.class', $query->createParameter('operationClass')));

$query->setParameters(['operationClass' => $operationClass]);
$result = $query->execute();
$result = $query->executeQuery();

$scopesByOperation[$operationClass] = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$scope = new ScopeContext($row['type'], $row['value']);

if (!$operation->isAvailableForScope((int)$row['type'])) {
Expand Down Expand Up @@ -180,10 +180,10 @@ public function getAllOperations(ScopeContext $scopeContext): array {
}

$query->setParameters(['scope' => $scopeContext->getScope(), 'scopeId' => $scopeContext->getScopeId()]);
$result = $query->execute();
$result = $query->executeQuery();

$this->operations[$scopeContext->getHash()] = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
try {
/** @var IOperation $operation */
$operation = $this->container->query($row['class']);
Expand Down Expand Up @@ -221,8 +221,8 @@ protected function getOperation($id) {
$query->select('*')
->from('flow_operations')
->where($query->expr()->eq('id', $query->createNamedParameter($id)));
$result = $query->execute();
$row = $result->fetch();
$result = $query->executeQuery();
$row = $result->fetchAssociative();
$result->closeCursor();

if ($row) {
Expand Down Expand Up @@ -250,7 +250,7 @@ protected function insertOperation(
'entity' => $query->createNamedParameter($entity),
'events' => $query->createNamedParameter(json_encode($events))
]);
$query->execute();
$query->executeStatement();

$this->cacheFactory->createDistributed('flow')->remove('events');

Expand Down Expand Up @@ -313,7 +313,7 @@ protected function canModify(int $id, ScopeContext $scopeContext):bool {
}

$qb->setParameters(['scope' => $scopeContext->getScope(), 'scopeId' => $scopeContext->getScopeId()]);
$result = $qb->execute();
$result = $qb->executeQuery();

$operations = [];
while (($opId = $result->fetchOne()) !== false) {
Expand Down Expand Up @@ -365,7 +365,7 @@ public function updateOperation(
->set('entity', $query->createNamedParameter($entity))
->set('events', $query->createNamedParameter(json_encode($events)))
->where($query->expr()->eq('id', $query->createNamedParameter($id)));
$query->execute();
$query->executeStatement();
$this->connection->commit();
} catch (Exception $e) {
$this->connection->rollBack();
Expand Down Expand Up @@ -393,12 +393,12 @@ public function deleteOperation($id, ScopeContext $scopeContext) {
$this->connection->beginTransaction();
$result = (bool)$query->delete('flow_operations')
->where($query->expr()->eq('id', $query->createNamedParameter($id)))
->execute();
->executeStatement();
if ($result) {
$qb = $this->connection->getQueryBuilder();
$result &= (bool)$qb->delete('flow_operations_scope')
->where($qb->expr()->eq('operation_id', $qb->createNamedParameter($id)))
->execute();
->executeStatement();
}
$this->connection->commit();
} catch (Exception $e) {
Expand Down Expand Up @@ -537,9 +537,9 @@ public function getChecks(array $checkIds) {
$query->select('*')
->from('flow_checks')
->where($query->expr()->in('id', $query->createNamedParameter($checkIds, IQueryBuilder::PARAM_INT_ARRAY)));
$result = $query->execute();
$result = $query->executeQuery();

while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$this->checks[(int)$row['id']] = $row;
$checks[(int)$row['id']] = $row;
}
Expand Down Expand Up @@ -568,9 +568,9 @@ protected function addCheck($class, $operator, $value) {
$query->select('id')
->from('flow_checks')
->where($query->expr()->eq('hash', $query->createNamedParameter($hash)));
$result = $query->execute();
$result = $query->executeQuery();

if ($row = $result->fetch()) {
if ($row = $result->fetchAssociative()) {
$result->closeCursor();
return (int)$row['id'];
}
Expand All @@ -583,7 +583,7 @@ protected function addCheck($class, $operator, $value) {
'value' => $query->createNamedParameter($value),
'hash' => $query->createNamedParameter($hash),
]);
$query->execute();
$query->executeStatement();

return $query->getLastInsertId();
}
Expand All @@ -597,7 +597,7 @@ protected function addScope(int $operationId, ScopeContext $scope): void {
'type' => $query->createNamedParameter($scope->getScope()),
'value' => $query->createNamedParameter($scope->getScopeId()),
]);
$insertQuery->execute();
$insertQuery->executeStatement();
}

public function formatOperation(array $operation): array {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Repair/OldGroupMembershipShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function run(IOutput $output) {
$deleteQuery->delete('share')
->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));

$result = $query->execute();
while ($row = $result->fetch()) {
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
if (!$this->isMember($row['group'], $row['user'])) {
$deletedEntries += $deleteQuery->setParameter('share', (int)$row['id'])
->execute();
Expand Down
27 changes: 10 additions & 17 deletions lib/private/Repair/RepairInvalidShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,19 @@

use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OCP\IConfig;
use OCP\IDBConnection;

/**
* Repairs shares with invalid data
*/
class RepairInvalidShares implements IRepairStep {
public const CHUNK_SIZE = 200;

/** @var \OCP\IConfig */
protected $config;

/** @var \OCP\IDBConnection */
protected $connection;

/**
* @param \OCP\IConfig $config
* @param \OCP\IDBConnection $connection
*/
public function __construct($config, $connection) {
$this->connection = $connection;
$this->config = $config;
public function __construct(
protected IConfig $config;
protected IDBConnection $connection,
) {
}

public function getName() {
Expand All @@ -49,7 +42,7 @@ private function adjustFileSharePermissions(IOutput $out) {
->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
->andWhere($builder->expr()->neq('permissions', $permsFunc));

$updatedEntries = $builder->execute();
$updatedEntries = $builder->executeStatement();
if ($updatedEntries > 0) {
$out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
}
Expand Down Expand Up @@ -77,11 +70,11 @@ private function removeSharesNonExistingParent(IOutput $out) {
$deletedInLastChunk = self::CHUNK_SIZE;
while ($deletedInLastChunk === self::CHUNK_SIZE) {
$deletedInLastChunk = 0;
$result = $query->execute();
while ($row = $result->fetch()) {
$result = $query->executeQuery();
while ($row = $result->fetchAssociative()) {
$deletedInLastChunk++;
$deletedEntries += $deleteQuery->setParameter('parent', (int)$row['parent'])
->execute();
->executeStatement();
}
$result->closeCursor();
}
Expand Down
58 changes: 19 additions & 39 deletions lib/private/SubAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,12 @@
use OCP\IUserManager;

class SubAdmin extends PublicEmitter implements ISubAdmin {
/** @var IUserManager */
private $userManager;

/** @var IGroupManager */
private $groupManager;

/** @var IDBConnection */
private $dbConn;

/** @var IEventDispatcher */
private $eventDispatcher;

/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IDBConnection $dbConn
*/
public function __construct(IUserManager $userManager,
IGroupManager $groupManager,
IDBConnection $dbConn,
IEventDispatcher $eventDispatcher) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->dbConn = $dbConn;
$this->eventDispatcher = $eventDispatcher;

public function __construct(
private IUserManager $userManager,
private IGroupManager $groupManager,
private IDBConnection $dbConn,
private IEventDispatcher $eventDispatcher
) {
$this->userManager->listen('\OC\User', 'postDelete', function ($user) {
$this->post_deleteUser($user);
});
Expand All @@ -66,7 +46,7 @@ public function createSubAdmin(IUser $user, IGroup $group): void {
'gid' => $qb->createNamedParameter($group->getGID()),
'uid' => $qb->createNamedParameter($user->getUID())
])
->execute();
->executeStatement();

/** @deprecated 21.0.0 - use type SubAdminAddedEvent instead */
$this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
Expand All @@ -85,7 +65,7 @@ public function deleteSubAdmin(IUser $user, IGroup $group): void {
$qb->delete('group_admin')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->execute();
->executeStatement();

/** @deprecated 21.0.0 - use type SubAdminRemovedEvent instead */
$this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
Expand Down Expand Up @@ -123,10 +103,10 @@ public function getSubAdminsGroupIds(IUser $user): array {
$result = $qb->select('gid')
->from('group_admin')
->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->execute();
->executeQuery();

$groups = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$groups[] = $row['gid'];
}
$result->closeCursor();
Expand Down Expand Up @@ -156,10 +136,10 @@ public function getGroupsSubAdmins(IGroup $group): array {
$result = $qb->select('uid')
->from('group_admin')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
->execute();
->executeQuery();

$users = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$user = $this->userManager->get($row['uid']);
if (!is_null($user)) {
$users[] = $user;
Expand All @@ -179,10 +159,10 @@ public function getAllSubAdmins(): array {

$result = $qb->select('*')
->from('group_admin')
->execute();
->executeQuery();

$subadmins = [];
while ($row = $result->fetch()) {
while ($row = $result->fetchAssociative()) {
$user = $this->userManager->get($row['uid']);
$group = $this->groupManager->get($row['gid']);
if (!is_null($user) && !is_null($group)) {
Expand Down Expand Up @@ -213,9 +193,9 @@ public function isSubAdminOfGroup(IUser $user, IGroup $group): bool {
->from('group_admin')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->execute();
->executeQuery();

$fetch = $result->fetch();
$fetch = $result->fetchAssociative();
$result->closeCursor();
$result = !empty($fetch) ? true : false;

Expand Down Expand Up @@ -244,7 +224,7 @@ public function isSubAdmin(IUser $user): bool {
->from('group_admin')
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->setMaxResults(1)
->execute();
->executeQuery();

$isSubAdmin = $result->fetch();
$result->closeCursor();
Expand Down Expand Up @@ -284,7 +264,7 @@ private function post_deleteUser(IUser $user) {

$qb->delete('group_admin')
->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->execute();
->executeStatement();
}

/**
Expand All @@ -296,6 +276,6 @@ private function post_deleteGroup(IGroup $group) {

$qb->delete('group_admin')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
->execute();
->executeStatement();
}
}

0 comments on commit b473774

Please sign in to comment.