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