1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : diffbackend.php |
---|
4 | * Project : Z-Push |
---|
5 | * Descr : This is the abstract differential backend. |
---|
6 | * By implementing this backends there is no need |
---|
7 | * to worry about importers and exporters. Also |
---|
8 | * tracking incremental changes is not necessary, |
---|
9 | * as the DiffState used by the DiffBackend offers |
---|
10 | * this functionality by comparing the list of objects |
---|
11 | * available "last time" with the list of objects |
---|
12 | * available "now". |
---|
13 | * Please note that the differential mechanism |
---|
14 | * can consume a considerable amount of memory and cpu |
---|
15 | * power when synchronizing folders with many items. |
---|
16 | * |
---|
17 | * Created : 02.01.2012 |
---|
18 | * |
---|
19 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
20 | * |
---|
21 | * This program is free software: you can redistribute it and/or modify |
---|
22 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
23 | * as published by the Free Software Foundation with the following additional |
---|
24 | * term according to sec. 7: |
---|
25 | * |
---|
26 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
27 | * the terms of the AGPL are supplemented with the following terms: |
---|
28 | * |
---|
29 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
30 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
31 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
32 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
33 | * |
---|
34 | * However, if you propagate an unmodified version of the Program you are |
---|
35 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
36 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
37 | * the intended purpose of a product or service provided you use it in accordance |
---|
38 | * with honest practices in industrial or commercial matters. |
---|
39 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
40 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
41 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
42 | * |
---|
43 | * This program is distributed in the hope that it will be useful, |
---|
44 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
45 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
46 | * GNU Affero General Public License for more details. |
---|
47 | * |
---|
48 | * You should have received a copy of the GNU Affero General Public License |
---|
49 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
50 | * |
---|
51 | * Consult LICENSE file for details |
---|
52 | ************************************************/ |
---|
53 | |
---|
54 | // default backend |
---|
55 | include_once('lib/default/backend.php'); |
---|
56 | |
---|
57 | // DiffBackend components |
---|
58 | include_once('diffstate.php'); |
---|
59 | include_once('importchangesdiff.php'); |
---|
60 | include_once('exportchangesdiff.php'); |
---|
61 | |
---|
62 | |
---|
63 | abstract class BackendDiff extends Backend { |
---|
64 | protected $store; |
---|
65 | |
---|
66 | /** |
---|
67 | * Setup the backend to work on a specific store or checks ACLs there. |
---|
68 | * If only the $store is submitted, all Import/Export/Fetch/Etc operations should be |
---|
69 | * performed on this store (switch operations store). |
---|
70 | * If the ACL check is enabled, this operation should just indicate the ACL status on |
---|
71 | * the submitted store, without changing the store for operations. |
---|
72 | * For the ACL status, the currently logged on user MUST have access rights on |
---|
73 | * - the entire store - admin access if no folderid is sent, or |
---|
74 | * - on a specific folderid in the store (secretary/full access rights) |
---|
75 | * |
---|
76 | * The ACLcheck MUST fail if a folder of the authenticated user is checked! |
---|
77 | * |
---|
78 | * @param string $store target store, could contain a "domain\user" value |
---|
79 | * @param boolean $checkACLonly if set to true, Setup() should just check ACLs |
---|
80 | * @param string $folderid if set, only ACLs on this folderid are relevant |
---|
81 | * |
---|
82 | * @access public |
---|
83 | * @return boolean |
---|
84 | */ |
---|
85 | public function Setup($store, $checkACLonly = false, $folderid = false) { |
---|
86 | $this->store = $store; |
---|
87 | |
---|
88 | return true; |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Returns an array of SyncFolder types with the entire folder hierarchy |
---|
93 | * on the server (the array itself is flat, but refers to parents via the 'parent' property |
---|
94 | * |
---|
95 | * provides AS 1.0 compatibility |
---|
96 | * |
---|
97 | * @access public |
---|
98 | * @return array SYNC_FOLDER |
---|
99 | */ |
---|
100 | function GetHierarchy() { |
---|
101 | $folders = array(); |
---|
102 | |
---|
103 | $fl = $this->GetFolderList(); |
---|
104 | if (is_array($fl)) |
---|
105 | foreach($fl as $f) |
---|
106 | $folders[] = $this->GetFolder($f['id']); |
---|
107 | |
---|
108 | return $folders; |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * Returns the importer to process changes from the mobile |
---|
113 | * If no $folderid is given, hierarchy importer is expected |
---|
114 | * |
---|
115 | * @param string $folderid (opt) |
---|
116 | * |
---|
117 | * @access public |
---|
118 | * @return object(ImportChanges) |
---|
119 | * @throws StatusException |
---|
120 | */ |
---|
121 | public function GetImporter($folderid = false) { |
---|
122 | return new ImportChangesDiff($this, $folderid); |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * Returns the exporter to send changes to the mobile |
---|
127 | * If no $folderid is given, hierarchy exporter is expected |
---|
128 | * |
---|
129 | * @param string $folderid (opt) |
---|
130 | * |
---|
131 | * @access public |
---|
132 | * @return object(ExportChanges) |
---|
133 | * @throws StatusException |
---|
134 | */ |
---|
135 | public function GetExporter($folderid = false) { |
---|
136 | return new ExportChangesDiff($this, $folderid); |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * Returns all available data of a single message |
---|
141 | * |
---|
142 | * @param string $folderid |
---|
143 | * @param string $id |
---|
144 | * @param ContentParameters $contentparameters flag |
---|
145 | * |
---|
146 | * @access public |
---|
147 | * @return object(SyncObject) |
---|
148 | * @throws StatusException |
---|
149 | */ |
---|
150 | public function Fetch($folderid, $id, $contentparameters) { |
---|
151 | // override truncation |
---|
152 | $contentparameters->SetTruncation(SYNC_TRUNCATION_ALL); |
---|
153 | $msg = $this->GetMessage($folderid, $id, $contentparameters); |
---|
154 | if ($msg === false) |
---|
155 | throw new StatusException("BackendDiff->Fetch('%s','%s'): Error, unable retrieve message from backend", SYNC_STATUS_OBJECTNOTFOUND); |
---|
156 | return $msg; |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * Processes a response to a meeting request. |
---|
161 | * CalendarID is a reference and has to be set if a new calendar item is created |
---|
162 | * |
---|
163 | * @param string $requestid id of the object containing the request |
---|
164 | * @param string $folderid id of the parent folder of $requestid |
---|
165 | * @param string $response |
---|
166 | * |
---|
167 | * @access public |
---|
168 | * @return string id of the created/updated calendar obj |
---|
169 | * @throws StatusException |
---|
170 | */ |
---|
171 | public function MeetingResponse($requestid, $folderid, $response) { |
---|
172 | throw new StatusException(sprintf("BackendDiff->MeetingResponse('%s','%s','%s'): Error, this functionality is not supported by the diff backend", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_MAILBOXERROR); |
---|
173 | } |
---|
174 | |
---|
175 | /**---------------------------------------------------------------------------------------------------------- |
---|
176 | * Abstract DiffBackend methods |
---|
177 | * |
---|
178 | * Need to be implemented in the actual diff backend |
---|
179 | */ |
---|
180 | |
---|
181 | /** |
---|
182 | * Returns a list (array) of folders, each entry being an associative array |
---|
183 | * with the same entries as StatFolder(). This method should return stable information; ie |
---|
184 | * if nothing has changed, the items in the array must be exactly the same. The order of |
---|
185 | * the items within the array is not important though. |
---|
186 | * |
---|
187 | * @access protected |
---|
188 | * @return array/boolean false if the list could not be retrieved |
---|
189 | */ |
---|
190 | public abstract function GetFolderList(); |
---|
191 | |
---|
192 | /** |
---|
193 | * Returns an actual SyncFolder object with all the properties set. Folders |
---|
194 | * are pretty simple, having only a type, a name, a parent and a server ID. |
---|
195 | * |
---|
196 | * @param string $id id of the folder |
---|
197 | * |
---|
198 | * @access public |
---|
199 | * @return object SyncFolder with information |
---|
200 | */ |
---|
201 | public abstract function GetFolder($id); |
---|
202 | |
---|
203 | /** |
---|
204 | * Returns folder stats. An associative array with properties is expected. |
---|
205 | * |
---|
206 | * @param string $id id of the folder |
---|
207 | * |
---|
208 | * @access public |
---|
209 | * @return array |
---|
210 | * Associative array( |
---|
211 | * string "id" The server ID that will be used to identify the folder. It must be unique, and not too long |
---|
212 | * How long exactly is not known, but try keeping it under 20 chars or so. It must be a string. |
---|
213 | * string "parent" The server ID of the parent of the folder. Same restrictions as 'id' apply. |
---|
214 | * long "mod" This is the modification signature. It is any arbitrary string which is constant as long as |
---|
215 | * the folder has not changed. In practice this means that 'mod' can be equal to the folder name |
---|
216 | * as this is the only thing that ever changes in folders. (the type is normally constant) |
---|
217 | * ) |
---|
218 | */ |
---|
219 | public abstract function StatFolder($id); |
---|
220 | |
---|
221 | /** |
---|
222 | * Creates or modifies a folder |
---|
223 | * |
---|
224 | * @param string $folderid id of the parent folder |
---|
225 | * @param string $oldid if empty -> new folder created, else folder is to be renamed |
---|
226 | * @param string $displayname new folder name (to be created, or to be renamed to) |
---|
227 | * @param int $type folder type |
---|
228 | * |
---|
229 | * @access public |
---|
230 | * @return boolean status |
---|
231 | * @throws StatusException could throw specific SYNC_FSSTATUS_* exceptions |
---|
232 | * |
---|
233 | */ |
---|
234 | public abstract function ChangeFolder($folderid, $oldid, $displayname, $type); |
---|
235 | |
---|
236 | /** |
---|
237 | * Deletes a folder |
---|
238 | * |
---|
239 | * @param string $id |
---|
240 | * @param string $parent is normally false |
---|
241 | * |
---|
242 | * @access public |
---|
243 | * @return boolean status - false if e.g. does not exist |
---|
244 | * @throws StatusException could throw specific SYNC_FSSTATUS_* exceptions |
---|
245 | */ |
---|
246 | public abstract function DeleteFolder($id, $parentid); |
---|
247 | |
---|
248 | /** |
---|
249 | * Returns a list (array) of messages, each entry being an associative array |
---|
250 | * with the same entries as StatMessage(). This method should return stable information; ie |
---|
251 | * if nothing has changed, the items in the array must be exactly the same. The order of |
---|
252 | * the items within the array is not important though. |
---|
253 | * |
---|
254 | * The $cutoffdate is a date in the past, representing the date since which items should be shown. |
---|
255 | * This cutoffdate is determined by the user's setting of getting 'Last 3 days' of e-mail, etc. If |
---|
256 | * the cutoffdate is ignored, the user will not be able to select their own cutoffdate, but all |
---|
257 | * will work OK apart from that. |
---|
258 | * |
---|
259 | * @param string $folderid id of the parent folder |
---|
260 | * @param long $cutoffdate timestamp in the past from which on messages should be returned |
---|
261 | * |
---|
262 | * @access public |
---|
263 | * @return array/false array with messages or false if folder is not available |
---|
264 | */ |
---|
265 | public abstract function GetMessageList($folderid, $cutoffdate); |
---|
266 | |
---|
267 | /** |
---|
268 | * Returns the actual SyncXXX object type. The '$folderid' of parent folder can be used. |
---|
269 | * Mixing item types returned is illegal and will be blocked by the engine; ie returning an Email object in a |
---|
270 | * Tasks folder will not do anything. The SyncXXX objects should be filled with as much information as possible, |
---|
271 | * but at least the subject, body, to, from, etc. |
---|
272 | * |
---|
273 | * @param string $folderid id of the parent folder |
---|
274 | * @param string $id id of the message |
---|
275 | * @param ContentParameters $contentparameters parameters of the requested message (truncation, mimesupport etc) |
---|
276 | * |
---|
277 | * @access public |
---|
278 | * @return object/false false if the message could not be retrieved |
---|
279 | */ |
---|
280 | public abstract function GetMessage($folderid, $id, $contentparameters); |
---|
281 | |
---|
282 | /** |
---|
283 | * Returns message stats, analogous to the folder stats from StatFolder(). |
---|
284 | * |
---|
285 | * @param string $folderid id of the folder |
---|
286 | * @param string $id id of the message |
---|
287 | * |
---|
288 | * @access public |
---|
289 | * @return array or boolean if fails |
---|
290 | * Associative array( |
---|
291 | * string "id" Server unique identifier for the message. Again, try to keep this short (under 20 chars) |
---|
292 | * int "flags" simply '0' for unread, '1' for read |
---|
293 | * long "mod" This is the modification signature. It is any arbitrary string which is constant as long as |
---|
294 | * the message has not changed. As soon as this signature changes, the item is assumed to be completely |
---|
295 | * changed, and will be sent to the PDA as a whole. Normally you can use something like the modification |
---|
296 | * time for this field, which will change as soon as the contents have changed. |
---|
297 | * ) |
---|
298 | */ |
---|
299 | public abstract function StatMessage($folderid, $id); |
---|
300 | |
---|
301 | /** |
---|
302 | * Called when a message has been changed on the mobile. The new message must be saved to disk. |
---|
303 | * The return value must be whatever would be returned from StatMessage() after the message has been saved. |
---|
304 | * This way, the 'flags' and the 'mod' properties of the StatMessage() item may change via ChangeMessage(). |
---|
305 | * This method will never be called on E-mail items as it's not 'possible' to change e-mail items. It's only |
---|
306 | * possible to set them as 'read' or 'unread'. |
---|
307 | * |
---|
308 | * @param string $folderid id of the folder |
---|
309 | * @param string $id id of the message |
---|
310 | * @param SyncXXX $message the SyncObject containing a message |
---|
311 | * |
---|
312 | * @access public |
---|
313 | * @return array same return value as StatMessage() |
---|
314 | * @throws StatusException could throw specific SYNC_STATUS_* exceptions |
---|
315 | */ |
---|
316 | public abstract function ChangeMessage($folderid, $id, $message); |
---|
317 | |
---|
318 | /** |
---|
319 | * Changes the 'read' flag of a message on disk. The $flags |
---|
320 | * parameter can only be '1' (read) or '0' (unread). After a call to |
---|
321 | * SetReadFlag(), GetMessageList() should return the message with the |
---|
322 | * new 'flags' but should not modify the 'mod' parameter. If you do |
---|
323 | * change 'mod', simply setting the message to 'read' on the mobile will trigger |
---|
324 | * a full resync of the item from the server. |
---|
325 | * |
---|
326 | * @param string $folderid id of the folder |
---|
327 | * @param string $id id of the message |
---|
328 | * @param int $flags read flag of the message |
---|
329 | * |
---|
330 | * @access public |
---|
331 | * @return boolean status of the operation |
---|
332 | * @throws StatusException could throw specific SYNC_STATUS_* exceptions |
---|
333 | */ |
---|
334 | public abstract function SetReadFlag($folderid, $id, $flags); |
---|
335 | |
---|
336 | /** |
---|
337 | * Called when the user has requested to delete (really delete) a message. Usually |
---|
338 | * this means just unlinking the file its in or somesuch. After this call has succeeded, a call to |
---|
339 | * GetMessageList() should no longer list the message. If it does, the message will be re-sent to the mobile |
---|
340 | * as it will be seen as a 'new' item. This means that if this method is not implemented, it's possible to |
---|
341 | * delete messages on the PDA, but as soon as a sync is done, the item will be resynched to the mobile |
---|
342 | * |
---|
343 | * @param string $folderid id of the folder |
---|
344 | * @param string $id id of the message |
---|
345 | * |
---|
346 | * @access public |
---|
347 | * @return boolean status of the operation |
---|
348 | * @throws StatusException could throw specific SYNC_STATUS_* exceptions |
---|
349 | */ |
---|
350 | public abstract function DeleteMessage($folderid, $id); |
---|
351 | |
---|
352 | /** |
---|
353 | * Called when the user moves an item on the PDA from one folder to another. Whatever is needed |
---|
354 | * to move the message on disk has to be done here. After this call, StatMessage() and GetMessageList() |
---|
355 | * should show the items to have a new parent. This means that it will disappear from GetMessageList() |
---|
356 | * of the sourcefolder and the destination folder will show the new message |
---|
357 | * |
---|
358 | * @param string $folderid id of the source folder |
---|
359 | * @param string $id id of the message |
---|
360 | * @param string $newfolderid id of the destination folder |
---|
361 | * |
---|
362 | * @access public |
---|
363 | * @return boolean status of the operation |
---|
364 | * @throws StatusException could throw specific SYNC_MOVEITEMSSTATUS_* exceptions |
---|
365 | */ |
---|
366 | public abstract function MoveMessage($folderid, $id, $newfolderid); |
---|
367 | |
---|
368 | } |
---|
369 | ?> |
---|