Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Bug fix: Select the correct table based on CALENDAR_TYPE_CALENDAR #43800

Merged
merged 1 commit into from Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Expand Up @@ -2341,86 +2341,88 @@
* @return array
*/
public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null, $calendarType = self::CALENDAR_TYPE_CALENDAR) {
return $this->atomic(function () use ($calendarId, $syncToken, $syncLevel, $limit, $calendarType) {
$table = $calendarType === self::CALENDAR_TYPE_CALENDAR ? 'calendars': 'calendarsubscriptions';

return $this->atomic(function () use ($calendarId, $syncToken, $syncLevel, $limit, $calendarType, $table) {
// Current synctoken
$qb = $this->db->getQueryBuilder();
$qb->select('synctoken')
->from('calendars')
->from($table)
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($calendarId))
);
$stmt = $qb->executeQuery();
$currentToken = $stmt->fetchOne();

if ($currentToken === false) {
return null;
}

$result = [
'syncToken' => $currentToken,
'added' => [],
'modified' => [],
'deleted' => [],
];

if ($syncToken) {
$qb = $this->db->getQueryBuilder();

$qb->select('uri', 'operation')
->from('calendarchanges')
->where(
$qb->expr()->andX(
$qb->expr()->gte('synctoken', $qb->createNamedParameter($syncToken)),
$qb->expr()->lt('synctoken', $qb->createNamedParameter($currentToken)),
$qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId)),
$qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType))
)
)->orderBy('synctoken');
if (is_int($limit) && $limit > 0) {
$qb->setMaxResults($limit);
}

// Fetching all changes
$stmt = $qb->executeQuery();
$changes = [];

// This loop ensures that any duplicates are overwritten, only the
// last change on a node is relevant.
while ($row = $stmt->fetch()) {
$changes[$row['uri']] = $row['operation'];
}
$stmt->closeCursor();

foreach ($changes as $uri => $operation) {
switch ($operation) {
case 1:
$result['added'][] = $uri;
break;
case 2:
$result['modified'][] = $uri;
break;
case 3:
$result['deleted'][] = $uri;
break;
}
}
} else {
// No synctoken supplied, this is the initial sync.
$qb = $this->db->getQueryBuilder();
$qb->select('uri')
->from('calendarobjects')
->where(
$qb->expr()->andX(
$qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId)),
$qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType))
)
);
$stmt = $qb->executeQuery();
$result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN);
$stmt->closeCursor();
}
return $result;
}, $this->db);

Check notice

Code scanning / Psalm

NullableReturnStatement Note

The declared return type 'array<array-key, mixed>' for OCA\DAV\CalDAV\CalDavBackend::getChangesForCalendar is not nullable, but the function returns 'array{added: array<array-key, mixed>, deleted: list, modified: list, syncToken: mixed}|null'
}

/**
Expand Down