Skip to content

Commit

Permalink
Merge pull request #40012 from nextcloud/techdebt/noid/prepare-doctri…
Browse files Browse the repository at this point in the history
…ne-update
  • Loading branch information
kesselb authored Aug 23, 2023
2 parents 590b1d9 + 5a1fcdb commit ac47eb9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
20 changes: 12 additions & 8 deletions apps/files_sharing/lib/Command/CleanupRemoteStorages.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public function countFiles($numericId, OutputInterface $output) {
$queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
IQueryBuilder::PARAM_STR)
);
$result = $queryBuilder->execute();
$result = $queryBuilder->executeQuery();
$count = $result->fetchOne();
$result->closeCursor();
$output->writeln("$count files can be deleted for storage $numericId");
}

Expand All @@ -127,7 +128,7 @@ public function deleteStorage($id, $numericId, OutputInterface $output) {
IQueryBuilder::PARAM_STR)
);
$output->write("deleting $id [$numericId] ... ");
$count = $queryBuilder->execute();
$count = $queryBuilder->executeStatement();
$output->writeln("deleted $count storage");
$this->deleteFiles($numericId, $output);
}
Expand All @@ -141,7 +142,7 @@ public function deleteFiles($numericId, OutputInterface $output) {
IQueryBuilder::PARAM_STR)
);
$output->write("deleting files for storage $numericId ... ");
$count = $queryBuilder->execute();
$count = $queryBuilder->executeStatement();
$output->writeln("deleted $count files");
}

Expand All @@ -160,14 +161,16 @@ public function getRemoteStorages() {
// but not the ones starting with a '/', they are for normal shares
$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'),
IQueryBuilder::PARAM_STR)
)->orderBy('numeric_id');
$query = $queryBuilder->execute();
)
->orderBy('numeric_id');
$result = $queryBuilder->executeQuery();

$remoteStorages = [];

while ($row = $query->fetch()) {
while ($row = $result->fetch()) {
$remoteStorages[$row['id']] = $row['numeric_id'];
}
$result->closeCursor();

return $remoteStorages;
}
Expand All @@ -176,16 +179,17 @@ public function getRemoteShareIds() {
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->select(['id', 'share_token', 'owner', 'remote'])
->from('share_external');
$query = $queryBuilder->execute();
$result = $queryBuilder->executeQuery();

$remoteShareIds = [];

while ($row = $query->fetch()) {
while ($row = $result->fetch()) {
$cloudId = $this->cloudIdManager->getCloudId($row['owner'], $row['remote']);
$remote = $cloudId->getRemote();

$remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $remote);
}
$result->closeCursor();

return $remoteShareIds;
}
Expand Down
28 changes: 16 additions & 12 deletions apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ protected function setUp(): void {
$shareExternalQuery->insert('share_external')
->setValue('share_token', '?')
->setValue('remote', '?')
->setValue('name', '?')->setParameter(2, 'irrelevant')
->setValue('owner', '?')->setParameter(3, 'irrelevant')
->setValue('name', '?')
->setValue('owner', '?')
->setValue('user', '?')
->setValue('mountpoint', '?')->setParameter(5, 'irrelevant')
->setValue('mountpoint_hash', '?')->setParameter(6, 'irrelevant');
->setValue('mountpoint', '?')
->setValue('mountpoint_hash', '?');

$filesQuery = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$filesQuery->insert('filecache')
Expand All @@ -95,23 +95,27 @@ protected function setUp(): void {
if (isset($storage['id'])) {
$storageQuery->setParameter(0, $storage['id']);
$storageQuery->execute();
$storage['numeric_id'] = $this->connection->lastInsertId('*PREFIX*storages');
$storage['numeric_id'] = $storageQuery->getLastInsertId();
}

if (isset($storage['share_token'])) {
$shareExternalQuery
->setParameter(0, $storage['share_token'])
->setParameter(1, $storage['remote'])
->setParameter(4, $storage['user']);
$shareExternalQuery->execute();
->setParameter(2, 'irrelevant')
->setParameter(3, 'irrelevant')
->setParameter(4, $storage['user'])
->setParameter(5, 'irrelevant')
->setParameter(6, 'irrelevant');
$shareExternalQuery->executeStatement();
}

if (isset($storage['files_count'])) {
for ($i = 0; $i < $storage['files_count']; $i++) {
$filesQuery->setParameter(0, $storage['numeric_id']);
$filesQuery->setParameter(1, 'file' . $i);
$filesQuery->setParameter(2, md5('file' . $i));
$filesQuery->execute();
$filesQuery->executeStatement();
}
}
}
Expand Down Expand Up @@ -153,8 +157,8 @@ private function doesStorageExist($numericId) {
->from('storages')
->where($qb->expr()->eq('numeric_id', $qb->createNamedParameter($numericId)));

$qResult = $qb->execute();
$result = $qResult->fetchAll();
$qResult = $qb->executeQuery();
$result = $qResult->fetch();
$qResult->closeCursor();
if (!empty($result)) {
return true;
Expand All @@ -165,8 +169,8 @@ private function doesStorageExist($numericId) {
->from('filecache')
->where($qb->expr()->eq('storage', $qb->createNamedParameter($numericId)));

$qResult = $qb->execute();
$result = $qResult->fetchAll();
$qResult = $qb->executeQuery();
$result = $qResult->fetch();
$qResult->closeCursor();
if (!empty($result)) {
return true;
Expand Down
11 changes: 6 additions & 5 deletions lib/public/DB/QueryBuilder/IQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace OCP\DB\QueryBuilder;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use OCP\DB\Exception;
use OCP\DB\IResult;

Expand All @@ -41,23 +42,23 @@ interface IQueryBuilder {
/**
* @since 9.0.0
*/
public const PARAM_NULL = \PDO::PARAM_NULL;
public const PARAM_NULL = ParameterType::NULL;
/**
* @since 9.0.0
*/
public const PARAM_BOOL = \PDO::PARAM_BOOL;
public const PARAM_BOOL = ParameterType::BOOLEAN;
/**
* @since 9.0.0
*/
public const PARAM_INT = \PDO::PARAM_INT;
public const PARAM_INT = ParameterType::INTEGER;
/**
* @since 9.0.0
*/
public const PARAM_STR = \PDO::PARAM_STR;
public const PARAM_STR = ParameterType::STRING;
/**
* @since 9.0.0
*/
public const PARAM_LOB = \PDO::PARAM_LOB;
public const PARAM_LOB = ParameterType::LARGE_OBJECT;
/**
* @since 9.0.0
*/
Expand Down

0 comments on commit ac47eb9

Please sign in to comment.