You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -886,22 +915,31 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel,
886
915
)
887
916
)->orderBy('synctoken');
888
917
889
-
if (is_int($limit) && $limit > 0) {
918
+
if ($limit > 0) {
890
919
$qb->setMaxResults($limit);
891
920
}
892
921
893
922
// Fetching all changes
894
923
$stmt = $qb->executeQuery();
924
+
$rowCount = $stmt->rowCount();
895
925
896
926
$changes = [];
927
+
$highestSyncToken = 0;
897
928
898
929
// This loop ensures that any duplicates are overwritten, only the
899
930
// last change on a node is relevant.
900
931
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
901
932
$changes[$row['uri']] = $row['operation'];
933
+
$highestSyncToken = $row['synctoken'];
902
934
}
935
+
903
936
$stmt->closeCursor();
904
937
938
+
// No changes found, use current token
939
+
if (empty($changes)) {
940
+
$result['syncToken'] = $currentToken;
941
+
}
942
+
905
943
foreach ($changesas$uri => $operation) {
906
944
switch ($operation) {
907
945
case1:
@@ -915,16 +953,43 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel,
915
953
break;
916
954
}
917
955
}
956
+
957
+
/*
958
+
* The synctoken in oc_addressbooks is always the highest synctoken in oc_addressbookchanges for a given addressbook plus one (see addChange).
959
+
*
960
+
* For truncated results, it is expected that we return the highest token from the response, so the client can continue from the latest change.
961
+
*
962
+
* For non-truncated results, it is expected to return the currentToken. If we return the highest token, as with truncated results, the client will always think it is one change behind.
963
+
*
964
+
* Therefore, we differentiate between truncated and non-truncated results when returning the synctoken.
965
+
*/
966
+
if ($rowCount === $limit && $highestSyncToken < $currentToken) {
0 commit comments