| @@ 929-992 (lines=64) @@ | ||
| 926 | * @param int $limit |
|
| 927 | * @return array |
|
| 928 | */ |
|
| 929 | function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
| 930 | // Current synctoken |
|
| 931 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
| 932 | $stmt->execute([ $calendarId ]); |
|
| 933 | $currentToken = $stmt->fetchColumn(0); |
|
| 934 | ||
| 935 | if (is_null($currentToken)) { |
|
| 936 | return null; |
|
| 937 | } |
|
| 938 | ||
| 939 | $result = [ |
|
| 940 | 'syncToken' => $currentToken, |
|
| 941 | 'added' => [], |
|
| 942 | 'modified' => [], |
|
| 943 | 'deleted' => [], |
|
| 944 | ]; |
|
| 945 | ||
| 946 | if ($syncToken) { |
|
| 947 | ||
| 948 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
| 949 | if ($limit>0) { |
|
| 950 | $query.= " `LIMIT` " . (int)$limit; |
|
| 951 | } |
|
| 952 | ||
| 953 | // Fetching all changes |
|
| 954 | $stmt = $this->db->prepare($query); |
|
| 955 | $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
| 956 | ||
| 957 | $changes = []; |
|
| 958 | ||
| 959 | // This loop ensures that any duplicates are overwritten, only the |
|
| 960 | // last change on a node is relevant. |
|
| 961 | while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 962 | ||
| 963 | $changes[$row['uri']] = $row['operation']; |
|
| 964 | ||
| 965 | } |
|
| 966 | ||
| 967 | foreach($changes as $uri => $operation) { |
|
| 968 | ||
| 969 | switch($operation) { |
|
| 970 | case 1 : |
|
| 971 | $result['added'][] = $uri; |
|
| 972 | break; |
|
| 973 | case 2 : |
|
| 974 | $result['modified'][] = $uri; |
|
| 975 | break; |
|
| 976 | case 3 : |
|
| 977 | $result['deleted'][] = $uri; |
|
| 978 | break; |
|
| 979 | } |
|
| 980 | ||
| 981 | } |
|
| 982 | } else { |
|
| 983 | // No synctoken supplied, this is the initial sync. |
|
| 984 | $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
| 985 | $stmt = $this->db->prepare($query); |
|
| 986 | $stmt->execute([$calendarId]); |
|
| 987 | ||
| 988 | $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
| 989 | } |
|
| 990 | return $result; |
|
| 991 | ||
| 992 | } |
|
| 993 | ||
| 994 | /** |
|
| 995 | * Returns a list of subscriptions for a principal. |
|
| @@ 669-729 (lines=61) @@ | ||
| 666 | * @param int $limit |
|
| 667 | * @return array |
|
| 668 | */ |
|
| 669 | function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { |
|
| 670 | // Current synctoken |
|
| 671 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?'); |
|
| 672 | $stmt->execute([ $addressBookId ]); |
|
| 673 | $currentToken = $stmt->fetchColumn(0); |
|
| 674 | ||
| 675 | if (is_null($currentToken)) return null; |
|
| 676 | ||
| 677 | $result = [ |
|
| 678 | 'syncToken' => $currentToken, |
|
| 679 | 'added' => [], |
|
| 680 | 'modified' => [], |
|
| 681 | 'deleted' => [], |
|
| 682 | ]; |
|
| 683 | ||
| 684 | if ($syncToken) { |
|
| 685 | ||
| 686 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`"; |
|
| 687 | if ($limit>0) { |
|
| 688 | $query .= " `LIMIT` " . (int)$limit; |
|
| 689 | } |
|
| 690 | ||
| 691 | // Fetching all changes |
|
| 692 | $stmt = $this->db->prepare($query); |
|
| 693 | $stmt->execute([$syncToken, $currentToken, $addressBookId]); |
|
| 694 | ||
| 695 | $changes = []; |
|
| 696 | ||
| 697 | // This loop ensures that any duplicates are overwritten, only the |
|
| 698 | // last change on a node is relevant. |
|
| 699 | while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 700 | ||
| 701 | $changes[$row['uri']] = $row['operation']; |
|
| 702 | ||
| 703 | } |
|
| 704 | ||
| 705 | foreach($changes as $uri => $operation) { |
|
| 706 | ||
| 707 | switch($operation) { |
|
| 708 | case 1: |
|
| 709 | $result['added'][] = $uri; |
|
| 710 | break; |
|
| 711 | case 2: |
|
| 712 | $result['modified'][] = $uri; |
|
| 713 | break; |
|
| 714 | case 3: |
|
| 715 | $result['deleted'][] = $uri; |
|
| 716 | break; |
|
| 717 | } |
|
| 718 | ||
| 719 | } |
|
| 720 | } else { |
|
| 721 | // No synctoken supplied, this is the initial sync. |
|
| 722 | $query = "SELECT `uri` FROM `*PREFIX*cards` WHERE `addressbookid` = ?"; |
|
| 723 | $stmt = $this->db->prepare($query); |
|
| 724 | $stmt->execute([$addressBookId]); |
|
| 725 | ||
| 726 | $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
| 727 | } |
|
| 728 | return $result; |
|
| 729 | } |
|
| 730 | ||
| 731 | /** |
|
| 732 | * Adds a change record to the addressbookchanges table. |
|