ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MockSyncCollection.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\DAV\Sync;
4
5use Sabre\DAV;
6
18
19 public $changeLog = [];
20
21 public $token = null;
22
32 function getSyncToken() {
33
34 // Will be 'null' in the first round, and will increment ever after.
35 return $this->token;
36
37 }
38
39 function addChange(array $added, array $modified, array $deleted) {
40
41 $this->token++;
42 $this->changeLog[$this->token] = [
43 'added' => $added,
44 'modified' => $modified,
45 'deleted' => $deleted,
46 ];
47
48 }
49
102 function getChanges($syncToken, $syncLevel, $limit = null) {
103
104 // This is an initial sync
105 if (is_null($syncToken)) {
106 return [
107 'added' => array_map(
108 function($item) {
109 return $item->getName();
110 }, $this->getChildren()
111 ),
112 'modified' => [],
113 'deleted' => [],
114 'syncToken' => $this->getSyncToken(),
115 ];
116 }
117
118 if (!is_int($syncToken) && !ctype_digit($syncToken)) {
119
120 return null;
121
122 }
123 if (is_null($this->token)) return null;
124
125 $added = [];
126 $modified = [];
127 $deleted = [];
128
129 foreach ($this->changeLog as $token => $change) {
130
131 if ($token > $syncToken) {
132
133 $added = array_merge($added, $change['added']);
134 $modified = array_merge($modified, $change['modified']);
135 $deleted = array_merge($deleted, $change['deleted']);
136
137 if ($limit) {
138 // If there's a limit, we may need to cut things off.
139 // This alghorithm is weird and stupid, but it works.
140 $left = $limit - (count($modified) + count($deleted));
141 if ($left > 0) continue;
142 if ($left === 0) break;
143 if ($left < 0) {
144 $modified = array_slice($modified, 0, $left);
145 }
146 $left = $limit - (count($modified) + count($deleted));
147 if ($left === 0) break;
148 if ($left < 0) {
149 $deleted = array_slice($deleted, 0, $left);
150 }
151 break;
152
153 }
154
155 }
156
157 }
158
159 return [
160 'syncToken' => $this->token,
161 'added' => $added,
162 'modified' => $modified,
163 'deleted' => $deleted,
164 ];
165
166 }
167
168
169}
An exception for terminatinating execution or to throw for unit testing.
getChildren()
Returns a list of children for this collection.
This mocks a ISyncCollection, for unittesting.
getChanges($syncToken, $syncLevel, $limit=null)
The getChanges method returns all the changes that have happened, since the specified syncToken and t...
getSyncToken()
This method returns the current sync-token for this collection.
addChange(array $added, array $modified, array $deleted)
If a class extends ISyncCollection, it supports WebDAV-sync.