1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : backend/combined/exporter.php |
---|
4 | * Project : Z-Push |
---|
5 | * Descr : Exporter 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 | /** |
---|
45 | * the ExportChangesCombined class is returned from GetExporter for changes. |
---|
46 | * It combines the changes from all backends and prepends all folderids with the backendid |
---|
47 | */ |
---|
48 | |
---|
49 | class ExportChangesCombined implements IExportChanges { |
---|
50 | private $backend; |
---|
51 | private $syncstates; |
---|
52 | private $exporters; |
---|
53 | private $importer; |
---|
54 | private $importwraps; |
---|
55 | |
---|
56 | public function ExportChangesCombined(&$backend) { |
---|
57 | $this->backend =& $backend; |
---|
58 | $this->exporters = array(); |
---|
59 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined constructed"); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Initializes the state and flags |
---|
64 | * |
---|
65 | * @param string $state |
---|
66 | * @param int $flags |
---|
67 | * |
---|
68 | * @access public |
---|
69 | * @return boolean status flag |
---|
70 | */ |
---|
71 | public function Config($syncstate, $flags = 0) { |
---|
72 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Config(...)"); |
---|
73 | $this->syncstates = $syncstate; |
---|
74 | if(!is_array($this->syncstates)){ |
---|
75 | $this->syncstates = array(); |
---|
76 | } |
---|
77 | |
---|
78 | foreach($this->backend->backends as $i => $b){ |
---|
79 | if(isset($this->syncstates[$i])){ |
---|
80 | $state = $this->syncstates[$i]; |
---|
81 | } else { |
---|
82 | $state = ''; |
---|
83 | } |
---|
84 | |
---|
85 | $this->exporters[$i] = $this->backend->backends[$i]->GetExporter(); |
---|
86 | $this->exporters[$i]->Config($state, $flags); |
---|
87 | } |
---|
88 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Config() success"); |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Returns the amount of changes to be exported |
---|
93 | * |
---|
94 | * @access public |
---|
95 | * @return int |
---|
96 | */ |
---|
97 | public function GetChangeCount() { |
---|
98 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetChangeCount()"); |
---|
99 | $c = 0; |
---|
100 | foreach($this->exporters as $i => $e){ |
---|
101 | $c += $this->exporters[$i]->GetChangeCount(); |
---|
102 | } |
---|
103 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetChangeCount() success"); |
---|
104 | return $c; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * Synchronizes a change to the configured importer |
---|
109 | * |
---|
110 | * @access public |
---|
111 | * @return array with status information |
---|
112 | */ |
---|
113 | public function Synchronize() { |
---|
114 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Synchronize()"); |
---|
115 | foreach($this->exporters as $i => $e){ |
---|
116 | if(!empty($this->backend->config['backends'][$i]['subfolder']) && !isset($this->syncstates[$i])){ |
---|
117 | // first sync and subfolder backend |
---|
118 | $f = new SyncFolder(); |
---|
119 | $f->serverid = $i.$this->backend->config['delimiter'].'0'; |
---|
120 | $f->parentid = '0'; |
---|
121 | $f->displayname = $this->backend->config['backends'][$i]['subfolder']; |
---|
122 | $f->type = SYNC_FOLDER_TYPE_OTHER; |
---|
123 | $this->importer->ImportFolderChange($f); |
---|
124 | } |
---|
125 | while(is_array($this->exporters[$i]->Synchronize())); |
---|
126 | } |
---|
127 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->Synchronize() success"); |
---|
128 | return true; |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | * Reads and returns the current state |
---|
133 | * |
---|
134 | * @access public |
---|
135 | * @return string |
---|
136 | */ |
---|
137 | public function GetState() { |
---|
138 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetState()"); |
---|
139 | foreach($this->exporters as $i => $e){ |
---|
140 | $this->syncstates[$i] = $this->exporters[$i]->GetState(); |
---|
141 | } |
---|
142 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->GetState() success"); |
---|
143 | return $this->syncstates; |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * Configures additional parameters used for content synchronization |
---|
148 | * |
---|
149 | * @param ContentParameters $contentparameters |
---|
150 | * |
---|
151 | * @access public |
---|
152 | * @return boolean |
---|
153 | * @throws StatusException |
---|
154 | */ |
---|
155 | public function ConfigContentParameters($contentparameters) { |
---|
156 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->ConfigContentParameters()"); |
---|
157 | foreach($this->exporters as $i => $e){ |
---|
158 | //call the ConfigContentParameters() of each exporter |
---|
159 | $e->ConfigContentParameters($contentparameters); |
---|
160 | } |
---|
161 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->ConfigContentParameters() success"); |
---|
162 | } |
---|
163 | |
---|
164 | /** |
---|
165 | * Sets the importer where the exporter will sent its changes to |
---|
166 | * This exporter should also be ready to accept calls after this |
---|
167 | * |
---|
168 | * @param object &$importer Implementation of IImportChanges |
---|
169 | * |
---|
170 | * @access public |
---|
171 | * @return boolean |
---|
172 | */ |
---|
173 | public function InitializeExporter(&$importer) { |
---|
174 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->InitializeExporter(...)"); |
---|
175 | foreach ($this->exporters as $i => $e) { |
---|
176 | if(!isset($this->_importwraps[$i])){ |
---|
177 | $this->importwraps[$i] = new ImportHierarchyChangesCombinedWrap($i, $this->backend, $importer); |
---|
178 | } |
---|
179 | $e->InitializeExporter($this->importwraps[$i]); |
---|
180 | } |
---|
181 | ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesCombined->InitializeExporter(...) success"); |
---|
182 | } |
---|
183 | } |
---|
184 | ?> |
---|