1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : moveitems.php |
---|
4 | * Project : Z-Push |
---|
5 | * Descr : Provides the MOVEITEMS command |
---|
6 | * |
---|
7 | * Created : 16.02.2012 |
---|
8 | * |
---|
9 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
10 | * |
---|
11 | * This program is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
13 | * as published by the Free Software Foundation with the following additional |
---|
14 | * term according to sec. 7: |
---|
15 | * |
---|
16 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
17 | * the terms of the AGPL are supplemented with the following terms: |
---|
18 | * |
---|
19 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
20 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
21 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
22 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
23 | * |
---|
24 | * However, if you propagate an unmodified version of the Program you are |
---|
25 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
26 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
27 | * the intended purpose of a product or service provided you use it in accordance |
---|
28 | * with honest practices in industrial or commercial matters. |
---|
29 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
30 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
31 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
32 | * |
---|
33 | * This program is distributed in the hope that it will be useful, |
---|
34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
36 | * GNU Affero General Public License for more details. |
---|
37 | * |
---|
38 | * You should have received a copy of the GNU Affero General Public License |
---|
39 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
40 | * |
---|
41 | * Consult LICENSE file for details |
---|
42 | ************************************************/ |
---|
43 | |
---|
44 | class MoveItems extends RequestProcessor { |
---|
45 | |
---|
46 | /** |
---|
47 | * Handles the MoveItems command |
---|
48 | * |
---|
49 | * @param int $commandCode |
---|
50 | * |
---|
51 | * @access public |
---|
52 | * @return boolean |
---|
53 | */ |
---|
54 | public function Handle($commandCode) { |
---|
55 | if(!self::$decoder->getElementStartTag(SYNC_MOVE_MOVES)) |
---|
56 | return false; |
---|
57 | |
---|
58 | $moves = array(); |
---|
59 | while(self::$decoder->getElementStartTag(SYNC_MOVE_MOVE)) { |
---|
60 | $move = array(); |
---|
61 | if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCMSGID)) { |
---|
62 | $move["srcmsgid"] = self::$decoder->getElementContent(); |
---|
63 | if(!self::$decoder->getElementEndTag()) |
---|
64 | break; |
---|
65 | } |
---|
66 | if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCFLDID)) { |
---|
67 | $move["srcfldid"] = self::$decoder->getElementContent(); |
---|
68 | if(!self::$decoder->getElementEndTag()) |
---|
69 | break; |
---|
70 | } |
---|
71 | if(self::$decoder->getElementStartTag(SYNC_MOVE_DSTFLDID)) { |
---|
72 | $move["dstfldid"] = self::$decoder->getElementContent(); |
---|
73 | if(!self::$decoder->getElementEndTag()) |
---|
74 | break; |
---|
75 | } |
---|
76 | array_push($moves, $move); |
---|
77 | |
---|
78 | if(!self::$decoder->getElementEndTag()) |
---|
79 | return false; |
---|
80 | } |
---|
81 | |
---|
82 | if(!self::$decoder->getElementEndTag()) |
---|
83 | return false; |
---|
84 | |
---|
85 | self::$encoder->StartWBXML(); |
---|
86 | |
---|
87 | self::$encoder->startTag(SYNC_MOVE_MOVES); |
---|
88 | |
---|
89 | foreach($moves as $move) { |
---|
90 | self::$encoder->startTag(SYNC_MOVE_RESPONSE); |
---|
91 | self::$encoder->startTag(SYNC_MOVE_SRCMSGID); |
---|
92 | self::$encoder->content($move["srcmsgid"]); |
---|
93 | self::$encoder->endTag(); |
---|
94 | |
---|
95 | $status = SYNC_MOVEITEMSSTATUS_SUCCESS; |
---|
96 | $result = false; |
---|
97 | try { |
---|
98 | // if the source folder is an additional folder the backend has to be setup correctly |
---|
99 | if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($move["srcfldid"]))) |
---|
100 | throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id '%s'", $move["srcfldid"]), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
---|
101 | |
---|
102 | $importer = self::$backend->GetImporter($move["srcfldid"]); |
---|
103 | if ($importer === false) |
---|
104 | throw new StatusException(sprintf("HandleMoveItems() could not get an importer for folder id '%s'", $move["srcfldid"]), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID); |
---|
105 | |
---|
106 | $result = $importer->ImportMessageMove($move["srcmsgid"], $move["dstfldid"]); |
---|
107 | // We discard the importer state for now. |
---|
108 | } |
---|
109 | catch (StatusException $stex) { |
---|
110 | if ($stex->getCode() == SYNC_STATUS_FOLDERHIERARCHYCHANGED) // same as SYNC_FSSTATUS_CODEUNKNOWN |
---|
111 | $status = SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID; |
---|
112 | else |
---|
113 | $status = $stex->getCode(); |
---|
114 | } |
---|
115 | |
---|
116 | self::$topCollector->AnnounceInformation(sprintf("Operation status: %s", $status), true); |
---|
117 | |
---|
118 | self::$encoder->startTag(SYNC_MOVE_STATUS); |
---|
119 | self::$encoder->content($status); |
---|
120 | self::$encoder->endTag(); |
---|
121 | |
---|
122 | self::$encoder->startTag(SYNC_MOVE_DSTMSGID); |
---|
123 | self::$encoder->content( (($result !== false ) ? $result : $move["srcmsgid"])); |
---|
124 | self::$encoder->endTag(); |
---|
125 | self::$encoder->endTag(); |
---|
126 | } |
---|
127 | |
---|
128 | self::$encoder->endTag(); |
---|
129 | return true; |
---|
130 | } |
---|
131 | } |
---|
132 | ?> |
---|