[7589] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : backend/combined/importer.php |
---|
| 4 | * Project : Z-Push |
---|
| 5 | * Descr : Importer class for the combined backend. |
---|
| 6 | * |
---|
| 7 | * Created : 11.05.2010 |
---|
| 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 ImportChangesCombined implements IImportChanges { |
---|
| 45 | private $backend; |
---|
| 46 | private $folderid; |
---|
| 47 | private $icc; |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * Constructor of the ImportChangesCombined class |
---|
| 51 | * |
---|
| 52 | * @param object $backend |
---|
| 53 | * @param string $folderid |
---|
| 54 | * @param object $importer |
---|
| 55 | * |
---|
| 56 | * @access public |
---|
| 57 | */ |
---|
| 58 | public function ImportChangesCombined(&$backend, $folderid = false, $icc = false) { |
---|
| 59 | $this->backend = $backend; |
---|
| 60 | $this->folderid = $folderid; |
---|
| 61 | $this->icc = &$icc; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * Loads objects which are expected to be exported with the state |
---|
| 66 | * Before importing/saving the actual message from the mobile, a conflict detection should be done |
---|
| 67 | * |
---|
| 68 | * @param ContentParameters $contentparameters class of objects |
---|
| 69 | * @param string $state |
---|
| 70 | * |
---|
| 71 | * @access public |
---|
| 72 | * @return boolean |
---|
| 73 | * @throws StatusException |
---|
| 74 | */ |
---|
| 75 | public function LoadConflicts($contentparameters, $state) { |
---|
| 76 | if (!$this->icc) { |
---|
| 77 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->LoadConflicts() icc not configured"); |
---|
| 78 | return false; |
---|
| 79 | } |
---|
| 80 | $this->icc->LoadConflicts($contentparameters, $state); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * Imports a single message |
---|
| 85 | * |
---|
| 86 | * @param string $id |
---|
| 87 | * @param SyncObject $message |
---|
| 88 | * |
---|
| 89 | * @access public |
---|
| 90 | * @return boolean/string failure / id of message |
---|
| 91 | */ |
---|
| 92 | public function ImportMessageChange($id, $message) { |
---|
| 93 | if (!$this->icc) { |
---|
| 94 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageChange() icc not configured"); |
---|
| 95 | return false; |
---|
| 96 | } |
---|
| 97 | return $this->icc->ImportMessageChange($id, $message); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * Imports a deletion. This may conflict if the local object has been modified |
---|
| 102 | * |
---|
| 103 | * @param string $id |
---|
| 104 | * |
---|
| 105 | * @access public |
---|
| 106 | * @return boolean |
---|
| 107 | */ |
---|
| 108 | public function ImportMessageDeletion($id) { |
---|
| 109 | if (!$this->icc) { |
---|
| 110 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageDeletion() icc not configured"); |
---|
| 111 | return false; |
---|
| 112 | } |
---|
| 113 | return $this->icc->ImportMessageDeletion($id); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /** |
---|
| 117 | * Imports a change in 'read' flag |
---|
| 118 | * This can never conflict |
---|
| 119 | * |
---|
| 120 | * @param string $id |
---|
| 121 | * @param int $flags |
---|
| 122 | * |
---|
| 123 | * @access public |
---|
| 124 | * @return boolean |
---|
| 125 | */ |
---|
| 126 | public function ImportMessageReadFlag($id, $flags) { |
---|
| 127 | if (!$this->icc) { |
---|
| 128 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageReadFlag() icc not configured"); |
---|
| 129 | return false; |
---|
| 130 | } |
---|
| 131 | return $this->icc->ImportMessageReadFlag($id, $flags); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * Imports a move of a message. This occurs when a user moves an item to another folder |
---|
| 136 | * |
---|
| 137 | * @param string $id |
---|
| 138 | * @param string $newfolder |
---|
| 139 | * |
---|
| 140 | * @access public |
---|
| 141 | * @return boolean |
---|
| 142 | */ |
---|
| 143 | public function ImportMessageMove($id, $newfolder) { |
---|
| 144 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesCombined->ImportMessageMove('%s', '%s')", $id, $newfolder)); |
---|
| 145 | if (!$this->icc) { |
---|
| 146 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageMove icc not configured"); |
---|
| 147 | return false; |
---|
| 148 | } |
---|
| 149 | if($this->backend->GetBackendId($this->folderid) != $this->backend->GetBackendId($newfolder)){ |
---|
| 150 | ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportMessageMove() cannot move message between two backends"); |
---|
| 151 | return false; |
---|
| 152 | } |
---|
| 153 | return $this->icc->ImportMessageMove($id, $this->backend->GetBackendFolder($newfolder)); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | /**---------------------------------------------------------------------------------------------------------- |
---|
| 158 | * Methods to import hierarchy |
---|
| 159 | */ |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | * Imports a change on a folder |
---|
| 163 | * |
---|
| 164 | * @param object $folder SyncFolder |
---|
| 165 | * |
---|
| 166 | * @access public |
---|
| 167 | * @return boolean/string status/id of the folder |
---|
| 168 | */ |
---|
| 169 | public function ImportFolderChange($folder) { |
---|
| 170 | $id = $folder->serverid; |
---|
| 171 | $parent = $folder->parentid; |
---|
| 172 | ZLog::Write(LOGLEVEL_DEBUG, "ImportChangesCombined->ImportFolderChange() ".print_r($folder, 1)); |
---|
| 173 | if($parent == '0') { |
---|
| 174 | if($id) { |
---|
| 175 | $backendid = $this->backend->GetBackendId($id); |
---|
| 176 | } |
---|
| 177 | else { |
---|
| 178 | $backendid = $this->backend->config['rootcreatefolderbackend']; |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | else { |
---|
| 182 | $backendid = $this->backend->GetBackendId($parent); |
---|
| 183 | $parent = $this->backend->GetBackendFolder($parent); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | if(!empty($this->backend->config['backends'][$backendid]['subfolder']) && $id == $backendid.$this->backend->config['delimiter'].'0') { |
---|
| 187 | ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportFolderChange() cannot change static folder"); |
---|
| 188 | return false; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | if($id != false) { |
---|
| 192 | if($backendid != $this->backend->GetBackendId($id)) { |
---|
| 193 | ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportFolderChange() cannot move folder between two backends"); |
---|
| 194 | return false; |
---|
| 195 | } |
---|
| 196 | $id = $this->backend->GetBackendFolder($id); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | $this->icc = $this->backend->getBackend($backendid)->GetImporter(); |
---|
| 200 | $res = $this->icc->ImportFolderChange($folder); |
---|
| 201 | ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->ImportFolderChange() success'); |
---|
| 202 | return $backendid.$this->backend->config['delimiter'].$res; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | /** |
---|
| 206 | * Imports a folder deletion |
---|
| 207 | * |
---|
| 208 | * @param string $id |
---|
| 209 | * @param string $parent id |
---|
| 210 | * |
---|
| 211 | * @access public |
---|
| 212 | * @return boolean/int success/SYNC_FOLDERHIERARCHY_STATUS |
---|
| 213 | */ |
---|
| 214 | public function ImportFolderDeletion($id, $parent = false) { |
---|
| 215 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesCombined->ImportFolderDeletion('%s', '%s'), $id, $parent")); |
---|
| 216 | $backendid = $this->backend->GetBackendId($id); |
---|
| 217 | if(!empty($this->backend->config['backends'][$backendid]['subfolder']) && $id == $backendid.$this->backend->config['delimiter'].'0') { |
---|
| 218 | ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportFolderDeletion() cannot change static folder"); |
---|
| 219 | return false; //we can not change a static subfolder |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | $backend = $this->backend->GetBackend($id); |
---|
| 223 | $id = $this->backend->GetBackendFolder($id); |
---|
| 224 | |
---|
| 225 | if($parent != '0') |
---|
| 226 | $parent = $this->backend->GetBackendFolder($parent); |
---|
| 227 | |
---|
| 228 | $this->icc = $backend->GetImporter(); |
---|
| 229 | $res = $this->icc->ImportFolderDeletion($id, $parent); |
---|
| 230 | ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->ImportFolderDeletion() success'); |
---|
| 231 | return $res; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | /** |
---|
| 236 | * Initializes the state and flags |
---|
| 237 | * |
---|
| 238 | * @param string $state |
---|
| 239 | * @param int $flags |
---|
| 240 | * |
---|
| 241 | * @access public |
---|
| 242 | * @return boolean status flag |
---|
| 243 | */ |
---|
| 244 | public function Config($state, $flags = 0) { |
---|
| 245 | ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->Config(...)'); |
---|
| 246 | if (!$this->icc) { |
---|
| 247 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->Config() icc not configured"); |
---|
| 248 | return false; |
---|
| 249 | } |
---|
| 250 | $this->icc->Config($state, $flags); |
---|
| 251 | ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->Config() success'); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | /** |
---|
| 255 | * Reads and returns the current state |
---|
| 256 | * |
---|
| 257 | * @access public |
---|
| 258 | * @return string |
---|
| 259 | */ |
---|
| 260 | public function GetState() { |
---|
| 261 | if (!$this->icc) { |
---|
| 262 | ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->GetState() icc not configured"); |
---|
| 263 | return false; |
---|
| 264 | } |
---|
| 265 | return $this->icc->GetState(); |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | /** |
---|
| 271 | * The ImportHierarchyChangesCombinedWrap class wraps the importer given in ExportChangesCombined->Config. |
---|
| 272 | * It prepends the backendid to all folderids and checks foldertypes. |
---|
| 273 | */ |
---|
| 274 | |
---|
| 275 | class ImportHierarchyChangesCombinedWrap { |
---|
| 276 | private $ihc; |
---|
| 277 | private $backend; |
---|
| 278 | private $backendid; |
---|
| 279 | |
---|
| 280 | /** |
---|
| 281 | * Constructor of the ImportChangesCombined class |
---|
| 282 | * |
---|
| 283 | * @param string $backendid |
---|
| 284 | * @param object $backend |
---|
| 285 | * @param object $ihc |
---|
| 286 | * |
---|
| 287 | * @access public |
---|
| 288 | */ |
---|
| 289 | public function ImportHierarchyChangesCombinedWrap($backendid, &$backend, &$ihc) { |
---|
| 290 | ZLog::Write(LOGLEVEL_DEBUG, "ImportHierarchyChangesCombinedWrap->ImportHierarchyChangesCombinedWrap('$backendid',...)"); |
---|
| 291 | $this->backendid = $backendid; |
---|
| 292 | $this->backend =& $backend; |
---|
| 293 | $this->ihc = &$ihc; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | /** |
---|
| 297 | * Imports a change on a folder |
---|
| 298 | * |
---|
| 299 | * @param object $folder SyncFolder |
---|
| 300 | * |
---|
| 301 | * @access public |
---|
| 302 | * @return boolean/string status/id of the folder |
---|
| 303 | */ |
---|
| 304 | public function ImportFolderChange($folder) { |
---|
| 305 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportHierarchyChangesCombinedWrap->ImportFolderChange('%s')", $folder->serverid)); |
---|
| 306 | $folder->serverid = $this->backendid.$this->backend->config['delimiter'].$folder->serverid; |
---|
| 307 | if($folder->parentid != '0' || !empty($this->backend->config['backends'][$this->backendid]['subfolder'])){ |
---|
| 308 | $folder->parentid = $this->backendid.$this->backend->config['delimiter'].$folder->parentid; |
---|
| 309 | } |
---|
| 310 | if(isset($this->backend->config['folderbackend'][$folder->type]) && $this->backend->config['folderbackend'][$folder->type] != $this->backendid){ |
---|
| 311 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("not using folder: '%s' ('%s')", $folder->displayname, $folder->serverid)); |
---|
| 312 | return true; |
---|
| 313 | } |
---|
| 314 | ZLog::Write(LOGLEVEL_DEBUG, "ImportHierarchyChangesCombinedWrap->ImportFolderChange() success"); |
---|
| 315 | return $this->ihc->ImportFolderChange($folder); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | /** |
---|
| 319 | * Imports a folder deletion |
---|
| 320 | * |
---|
| 321 | * @param string $id |
---|
| 322 | * |
---|
| 323 | * @access public |
---|
| 324 | * |
---|
| 325 | * @return boolean/int success/SYNC_FOLDERHIERARCHY_STATUS |
---|
| 326 | */ |
---|
| 327 | public function ImportFolderDeletion($id) { |
---|
| 328 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportHierarchyChangesCombinedWrap->ImportFolderDeletion('%s')", $id)); |
---|
| 329 | return $this->ihc->ImportFolderDeletion($this->backendid.$this->backend->config['delimiter'].$id); |
---|
| 330 | } |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | ?> |
---|