Back to index

d-push  2.0
importer.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   backend/combined/importer.php
00004 * Project   :   Z-Push
00005 * Descr     :   Importer class for the combined backend.
00006 *
00007 * Created   :   11.05.2010
00008 *
00009 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00010 *
00011 * This program is free software: you can redistribute it and/or modify
00012 * it under the terms of the GNU Affero General Public License, version 3,
00013 * as published by the Free Software Foundation with the following additional
00014 * term according to sec. 7:
00015 *
00016 * According to sec. 7 of the GNU Affero General Public License, version 3,
00017 * the terms of the AGPL are supplemented with the following terms:
00018 *
00019 * "Zarafa" is a registered trademark of Zarafa B.V.
00020 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00021 * The licensing of the Program under the AGPL does not imply a trademark license.
00022 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00023 *
00024 * However, if you propagate an unmodified version of the Program you are
00025 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00026 * Furthermore you may use our trademarks where it is necessary to indicate
00027 * the intended purpose of a product or service provided you use it in accordance
00028 * with honest practices in industrial or commercial matters.
00029 * If you want to propagate modified versions of the Program under the name "Z-Push",
00030 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00031 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00032 *
00033 * This program is distributed in the hope that it will be useful,
00034 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00036 * GNU Affero General Public License for more details.
00037 *
00038 * You should have received a copy of the GNU Affero General Public License
00039 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00040 *
00041 * Consult LICENSE file for details
00042 ************************************************/
00043 
00044 class ImportChangesCombined implements IImportChanges {
00045     private $backend;
00046     private $folderid;
00047     private $icc;
00048 
00058     public function ImportChangesCombined(&$backend, $folderid = false, $icc = false) {
00059         $this->backend = $backend;
00060         $this->folderid = $folderid;
00061         $this->icc = &$icc;
00062     }
00063 
00075     public function LoadConflicts($contentparameters, $state) {
00076         if (!$this->icc) {
00077             ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->LoadConflicts() icc not configured");
00078             return false;
00079         }
00080         $this->icc->LoadConflicts($contentparameters, $state);
00081     }
00082 
00092     public function ImportMessageChange($id, $message) {
00093         if (!$this->icc) {
00094             ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageChange() icc not configured");
00095             return false;
00096         }
00097         return $this->icc->ImportMessageChange($id, $message);
00098     }
00099 
00108     public function ImportMessageDeletion($id) {
00109         if (!$this->icc) {
00110             ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageDeletion() icc not configured");
00111             return false;
00112         }
00113         return $this->icc->ImportMessageDeletion($id);
00114     }
00115 
00126     public function ImportMessageReadFlag($id, $flags) {
00127         if (!$this->icc) {
00128             ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageReadFlag() icc not configured");
00129             return false;
00130         }
00131         return $this->icc->ImportMessageReadFlag($id, $flags);
00132     }
00133 
00143     public function ImportMessageMove($id, $newfolder) {
00144         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesCombined->ImportMessageMove('%s', '%s')", $id, $newfolder));
00145         if (!$this->icc) {
00146             ZLog::Write(LOGLEVEL_ERROR, "ImportChangesCombined->ImportMessageMove icc not configured");
00147             return false;
00148         }
00149         if($this->backend->GetBackendId($this->folderid) != $this->backend->GetBackendId($newfolder)){
00150             ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportMessageMove() cannot move message between two backends");
00151             return false;
00152         }
00153         return $this->icc->ImportMessageMove($id, $this->backend->GetBackendFolder($newfolder));
00154     }
00155 
00156 
00169     public function ImportFolderChange($folder) {
00170         $id = $folder->serverid;
00171         $parent = $folder->parentid;
00172         ZLog::Write(LOGLEVEL_DEBUG, "ImportChangesCombined->ImportFolderChange() ".print_r($folder, 1));
00173         if($parent == '0') {
00174             if($id) {
00175                 $backendid = $this->backend->GetBackendId($id);
00176             }
00177             else {
00178                 $backendid = $this->backend->config['rootcreatefolderbackend'];
00179             }
00180         }
00181         else {
00182             $backendid = $this->backend->GetBackendId($parent);
00183             $parent = $this->backend->GetBackendFolder($parent);
00184         }
00185 
00186         if(!empty($this->backend->config['backends'][$backendid]['subfolder']) && $id == $backendid.$this->backend->config['delimiter'].'0') {
00187             ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportFolderChange() cannot change static folder");
00188             return false;
00189         }
00190 
00191         if($id != false) {
00192             if($backendid != $this->backend->GetBackendId($id)) {
00193                 ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportFolderChange() cannot move folder between two backends");
00194                 return false;
00195             }
00196             $id = $this->backend->GetBackendFolder($id);
00197         }
00198 
00199         $importer = $this->backend->getBackend($backendid)->GetImporter();
00200 
00201         if(isset($this->syncstates[$backendid])) {
00202             $state = $this->syncstates[$backendid];
00203         }
00204         else {
00205             $state = '';
00206         }
00207 
00208         $importer->Config($state);
00209         $res = $importer->ImportFolderChange($folder);
00210         $this->syncstates[$backendid] = $importer->GetState();
00211         ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->ImportFolderChange() success');
00212         return $backendid.$this->backend->config['delimiter'].$res;
00213     }
00214 
00224     public function ImportFolderDeletion($id, $parent = false) {
00225         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesCombined->ImportFolderDeletion('%s', '%s'), $id, $parent"));
00226         $backendid = $this->backend->GetBackendId($id);
00227         if(!empty($this->backend->config['backends'][$backendid]['subfolder']) && $id == $backendid.$this->backend->config['delimiter'].'0') {
00228             ZLog::Write(LOGLEVEL_WARN, "ImportChangesCombined->ImportFolderDeletion() cannot change static folder");
00229             return false; //we can not change a static subfolder
00230         }
00231 
00232         $backend = $this->backend->GetBackend($id);
00233         $id = $this->backend->GetBackendFolder($id);
00234 
00235         if($parent != '0')
00236             $parent = $this->backend->GetBackendFolder($parent);
00237 
00238         $importer = $backend->GetImporter();
00239 
00240         if(isset($this->syncstates[$backendid])) {
00241             $state = $this->syncstates[$backendid];
00242         }
00243         else {
00244             $state = '';
00245         }
00246 
00247         $importer->Config($state);
00248         $res = $importer->ImportFolderDeletion($id, $parent);
00249         $this->syncstates[$backendid] = $importer->GetState();
00250         ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->ImportFolderDeletion() success');
00251         return $res;
00252     }
00253 
00254 
00264     public function Config($state, $flags = 0) {
00265         ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->Config(...)');
00266         $this->syncstates = $state;
00267         if(!is_array($this->syncstates))
00268             $this->syncstates = array();
00269         ZLog::Write(LOGLEVEL_DEBUG, 'ImportChangesCombined->Config() success');
00270     }
00271 
00278     public function GetState() {
00279         return $this->syncstates;
00280     }
00281 }
00282 
00283 
00289 class ImportHierarchyChangesCombinedWrap {
00290     private $ihc;
00291     private $backend;
00292     private $backendid;
00293 
00303     public function ImportHierarchyChangesCombinedWrap($backendid, &$backend, &$ihc) {
00304         ZLog::Write(LOGLEVEL_DEBUG, "ImportHierarchyChangesCombinedWrap->ImportHierarchyChangesCombinedWrap('$backendid',...)");
00305         $this->backendid = $backendid;
00306         $this->backend =& $backend;
00307         $this->ihc = &$ihc;
00308     }
00309 
00318     public function ImportFolderChange($folder) {
00319         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportHierarchyChangesCombinedWrap->ImportFolderChange('%s')", $folder->serverid));
00320         $folder->serverid = $this->backendid.$this->backend->config['delimiter'].$folder->serverid;
00321         if($folder->parentid != '0' || !empty($this->backend->config['backends'][$this->backendid]['subfolder'])){
00322             $folder->parentid = $this->backendid.$this->backend->config['delimiter'].$folder->parentid;
00323         }
00324         if(isset($this->backend->config['folderbackend'][$folder->type]) && $this->backend->config['folderbackend'][$folder->type] != $this->backendid){
00325             ZLog::Write(LOGLEVEL_DEBUG, sprintf("not ussing folder: '%s' ('%s')", $folder->displayname, $folder->serverid));
00326             return true;
00327         }
00328         ZLog::Write(LOGLEVEL_DEBUG, "ImportHierarchyChangesCombinedWrap->ImportFolderChange() success");
00329         return $this->ihc->ImportFolderChange($folder);
00330     }
00331 
00341     public function ImportFolderDeletion($id) {
00342         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportHierarchyChangesCombinedWrap->ImportFolderDeletion('%s')", $id));
00343         return $this->ihc->ImportFolderDeletion($this->backendid.$this->backend->config['delimiter'].$id);
00344     }
00345 }
00346 
00347 ?>