Back to index

d-push  2.0
exporter.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   backend/combined/exporter.php
00004 * Project   :   Z-Push
00005 * Descr     :   Exporter 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 
00049 class ExportChangesCombined implements IExportChanges {
00050     private $backend;
00051     private $syncstates;
00052     private $exporters;
00053     private $importer;
00054     private $importwraps;
00055 
00056     public function ExportChangesCombined(&$backend) {
00057         $this->backend =& $backend;
00058         $this->exporters = array();
00059         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined constructed");
00060     }
00061 
00071     public function Config($syncstate, $flags = 0) {
00072         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Config(...)");
00073         $this->syncstates = $syncstate;
00074         if(!is_array($this->syncstates)){
00075             $this->syncstates = array();
00076         }
00077 
00078         foreach($this->backend->backends as $i => $b){
00079             if(isset($this->syncstates[$i])){
00080                 $state = $this->syncstates[$i];
00081             } else {
00082                 $state = '';
00083             }
00084 
00085             $this->exporters[$i] = $this->backend->backends[$i]->GetExporter();
00086             $this->exporters[$i]->Config($state, $flags);
00087         }
00088         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Config() success");
00089     }
00090 
00097     public function GetChangeCount() {
00098         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetChangeCount()");
00099         $c = 0;
00100         foreach($this->exporters as $i => $e){
00101             $c += $this->exporters[$i]->GetChangeCount();
00102         }
00103         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetChangeCount() success");
00104         return $c;
00105     }
00106 
00113     public function Synchronize() {
00114         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Synchronize()");
00115         foreach($this->exporters as $i => $e){
00116             if(!empty($this->backend->config['backends'][$i]['subfolder']) && !isset($this->syncstates[$i])){
00117                 // first sync and subfolder backend
00118                 $f = new SyncFolder();
00119                 $f->serverid = $i.$this->backend->config['delimiter'].'0';
00120                 $f->parentid = '0';
00121                 $f->displayname = $this->backend->config['backends'][$i]['subfolder'];
00122                 $f->type = SYNC_FOLDER_TYPE_OTHER;
00123                 $this->importer->ImportFolderChange($f);
00124             }
00125             while(is_array($this->exporters[$i]->Synchronize()));
00126         }
00127         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Synchronize() success");
00128         return true;
00129     }
00130 
00137     public function GetState() {
00138         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetState()");
00139         foreach($this->exporters as $i => $e){
00140             $this->syncstates[$i] = $this->exporters[$i]->GetState();
00141         }
00142         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetState() success");
00143         return $this->syncstates;
00144     }
00145 
00155     public function ConfigContentParameters($contentparameters) {
00156         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->ConfigContentParameters()");
00157         foreach($this->exporters as $i => $e){
00158             //call the ConfigContentParameters() of each exporter
00159             $e->ConfigContentParameters($contentparameters);
00160         }
00161         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->ConfigContentParameters() success");
00162     }
00163 
00173     public function InitializeExporter(&$importer) {
00174         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->InitializeExporter(...)");
00175         foreach ($this->exporters as $i => $e) {
00176             if(!isset($this->_importwraps[$i])){
00177                 $this->importwraps[$i] = new ImportHierarchyChangesCombinedWrap($i, $this->backend, $importer);
00178             }
00179             $e->InitializeExporter($this->importwraps[$i]);
00180         }
00181         ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->InitializeExporter(...) success");
00182     }
00183 }
00184 ?>