Skip to content

Commit

Permalink
chore(db): Correctly apply query types
Browse files Browse the repository at this point in the history
fix: psalm

fix: error

fix: add batch

fix: fatal error

fix: add batch

chore: add batch

chore: add batch

fix: psalm

fix: typo

fix: psalm

fix: return bool

fix: revert Manager
  • Loading branch information
solracsf committed Oct 16, 2024
1 parent 94e1241 commit 70db9dc
Show file tree
Hide file tree
Showing 28 changed files with 194 additions and 334 deletions.
8 changes: 4 additions & 4 deletions apps/contactsinteraction/lib/Db/CardSearchDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use function stream_get_contents;

class CardSearchDao {
private IDBConnection $db;

public function __construct(IDBConnection $db) {
$this->db = $db;
public function __construct(
private IDBConnection $db,
) {
}

public function findExisting(IUser $user,
Expand Down Expand Up @@ -65,7 +65,7 @@ public function findExisting(IUser $user,
->where($cardQuery->expr()->in('id', $cardQuery->createFunction($propQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY))
->andWhere($cardQuery->expr()->in('addressbookid', $cardQuery->createFunction($addressbooksQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY))
->setMaxResults(1);
$result = $cardQuery->execute();
$result = $cardQuery->executeQuery();
/** @var string|resource|false $card */
$card = $result->fetchOne();

Expand Down
28 changes: 9 additions & 19 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@

class IMipService {

private URLGenerator $urlGenerator;
private IConfig $config;
private IDBConnection $db;
private ISecureRandom $random;
private L10NFactory $l10nFactory;
private IL10N $l10n;
private ITimeFactory $timeFactory;

/** @var string[] */
private const STRING_DIFF = [
Expand All @@ -43,20 +37,16 @@ class IMipService {
'meeting_location' => 'LOCATION'
];

public function __construct(URLGenerator $urlGenerator,
IConfig $config,
IDBConnection $db,
ISecureRandom $random,
L10NFactory $l10nFactory,
ITimeFactory $timeFactory) {
$this->urlGenerator = $urlGenerator;
$this->config = $config;
$this->db = $db;
$this->random = $random;
$this->l10nFactory = $l10nFactory;
public function __construct(
private URLGenerator $urlGenerator,
private IConfig $config,
private IDBConnection $db,
private ISecureRandom $random,
private L10NFactory $l10nFactory,
private ITimeFactory $timeFactory,
) {
$default = $this->l10nFactory->findGenericLanguage();
$this->l10n = $this->l10nFactory->get('dav', $default);
$this->timeFactory = $timeFactory;
}

/**
Expand Down Expand Up @@ -912,7 +902,7 @@ public function createInvitationToken(Message $iTipMessage, VEvent $vevent, int
'expiration' => $query->createNamedParameter($lastOccurrence),
'uid' => $query->createNamedParameter($uid)
])
->execute();
->executeStatement();

return $token;
}
Expand Down
28 changes: 14 additions & 14 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function getUsersOwnAddressBooks($principalUri) {

$addressBooks = [];

$result = $query->execute();
$result = $query->executeQuery();
while ($row = $result->fetch()) {
$addressBooks[$row['id']] = [
'id' => $row['id'],
Expand Down Expand Up @@ -395,7 +395,7 @@ public function createAddressBook($principalUri, $url, array $properties) {
'synctoken' => $query->createParameter('synctoken'),
])
->setParameters($values)
->execute();
->executeStatement();

$addressBookId = $query->getLastInsertId();
return [
Expand Down Expand Up @@ -479,7 +479,7 @@ public function getCards($addressbookId) {

$cards = [];

$result = $query->execute();
$result = $query->executeQuery();
while ($row = $result->fetch()) {
$row['etag'] = '"' . $row['etag'] . '"';

Expand Down Expand Up @@ -516,7 +516,7 @@ public function getCard($addressBookId, $cardUri) {
->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
->setMaxResults(1);

$result = $query->execute();
$result = $query->executeQuery();
$row = $result->fetch();
if (!$row) {
return false;
Expand Down Expand Up @@ -560,7 +560,7 @@ public function getMultipleCards($addressBookId, array $uris) {

foreach ($chunks as $uris) {
$query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->execute();
$result = $query->executeQuery();

while ($row = $result->fetch()) {
$row['etag'] = '"' . $row['etag'] . '"';
Expand Down Expand Up @@ -634,7 +634,7 @@ public function createCard($addressBookId, $cardUri, $cardData, bool $checkAlrea
'etag' => $query->createNamedParameter($etag),
'uid' => $query->createNamedParameter($uid),
])
->execute();
->executeStatement();

$etagCacheKey = "$addressBookId#$cardUri";
$this->etagCache[$etagCacheKey] = $etag;
Expand Down Expand Up @@ -697,7 +697,7 @@ public function updateCard($addressBookId, $cardUri, $cardData) {
->set('uid', $query->createNamedParameter($uid))
->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->execute();
->executeStatement();

$this->etagCache[$etagCacheKey] = $etag;

Expand Down Expand Up @@ -1165,7 +1165,7 @@ private function searchByAddressBookIds(array $addressBookIds,
*/
}

$result = $query2->execute();
$result = $query2->executeQuery();
$matches = $result->fetchAll();
$result->closeCursor();
$matches = array_map(function ($match) {
Expand Down Expand Up @@ -1207,7 +1207,7 @@ public function collectCardProperties($bookId, $name) {
->from($this->dbCardsPropertiesTable)
->where($query->expr()->eq('name', $query->createNamedParameter($name)))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($bookId)))
->execute();
->executeQuery();

$all = $result->fetchAll(PDO::FETCH_COLUMN);
$result->closeCursor();
Expand All @@ -1227,7 +1227,7 @@ public function getCardUri($id) {
->where($query->expr()->eq('id', $query->createParameter('id')))
->setParameter('id', $id);

$result = $query->execute();
$result = $query->executeQuery();
$uri = $result->fetch();
$result->closeCursor();

Expand All @@ -1251,7 +1251,7 @@ public function getContact($addressBookId, $uri) {
$query->select('*')->from($this->dbCardsTable)
->where($query->expr()->eq('uri', $query->createNamedParameter($uri)))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
$queryResult = $query->execute();
$queryResult = $query->executeQuery();
$contact = $queryResult->fetch();
$queryResult->closeCursor();

Expand Down Expand Up @@ -1324,7 +1324,7 @@ protected function updateProperties($addressBookId, $cardUri, $vCardSerialized)
$query->setParameter('name', $property->name);
$query->setParameter('value', mb_strcut($property->getValue(), 0, 254));
$query->setParameter('preferred', $preferred);
$query->execute();
$query->executeStatement();
}
}, $this->db);
}
Expand All @@ -1350,7 +1350,7 @@ protected function purgeProperties($addressBookId, $cardId) {
$query->delete($this->dbCardsPropertiesTable)
->where($query->expr()->eq('cardid', $query->createNamedParameter($cardId)))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
$query->execute();
$query->executeStatement();
}

/**
Expand All @@ -1362,7 +1362,7 @@ protected function getCardId(int $addressBookId, string $uri): int {
->where($query->expr()->eq('uri', $query->createNamedParameter($uri)))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));

$result = $query->execute();
$result = $query->executeQuery();
$cardIds = $result->fetch();
$result->closeCursor();

Expand Down
27 changes: 6 additions & 21 deletions apps/dav/lib/Migration/BuildCalendarSearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,11 @@

class BuildCalendarSearchIndex implements IRepairStep {

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

/** @var IJobList */
private $jobList;

/** @var IConfig */
private $config;

/**
* @param IDBConnection $db
* @param IJobList $jobList
* @param IConfig $config
*/
public function __construct(IDBConnection $db,
IJobList $jobList,
IConfig $config) {
$this->db = $db;
$this->jobList = $jobList;
$this->config = $config;
public function __construct(
private IDBConnection $db,
private IJobList $jobList,
private IConfig $config,
) {
}

/**
Expand All @@ -55,7 +40,7 @@ public function run(IOutput $output) {
$query = $this->db->getQueryBuilder();
$query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
->from('calendarobjects');
$result = $query->execute();
$result = $query->executeQuery();
$maxId = (int)$result->fetchOne();
$result->closeCursor();

Expand Down
22 changes: 6 additions & 16 deletions apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
*/
class RegisterBuildReminderIndexBackgroundJob implements IRepairStep {

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

/** @var IJobList */
private $jobList;

/** @var IConfig */
private $config;

/** @var string */
private const CONFIG_KEY = 'buildCalendarReminderIndex';

Expand All @@ -39,12 +30,11 @@ class RegisterBuildReminderIndexBackgroundJob implements IRepairStep {
* @param IJobList $jobList
* @param IConfig $config
*/
public function __construct(IDBConnection $db,
IJobList $jobList,
IConfig $config) {
$this->db = $db;
$this->jobList = $jobList;
$this->config = $config;
public function __construct(
private IDBConnection $db,
private IJobList $jobList,
private IConfig $config,
) {
}

/**
Expand All @@ -67,7 +57,7 @@ public function run(IOutput $output) {
$query = $this->db->getQueryBuilder();
$query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')'))
->from('calendarobjects');
$result = $query->execute();
$result = $query->executeQuery();
$maxId = (int)$result->fetchOne();
$result->closeCursor();

Expand Down
Loading

0 comments on commit 70db9dc

Please sign in to comment.