Back to index

d-push  2.0
syncparameters.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   syncparameters.php
00004 * Project   :   Z-Push
00005 * Descr     :   Transportation container for
00006 *               requested content parameters and information
00007 *               about the container and states
00008 *
00009 * Created   :   11.04.2011
00010 *
00011 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00012 *
00013 * This program is free software: you can redistribute it and/or modify
00014 * it under the terms of the GNU Affero General Public License, version 3,
00015 * as published by the Free Software Foundation with the following additional
00016 * term according to sec. 7:
00017 *
00018 * According to sec. 7 of the GNU Affero General Public License, version 3,
00019 * the terms of the AGPL are supplemented with the following terms:
00020 *
00021 * "Zarafa" is a registered trademark of Zarafa B.V.
00022 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00023 * The licensing of the Program under the AGPL does not imply a trademark license.
00024 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00025 *
00026 * However, if you propagate an unmodified version of the Program you are
00027 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00028 * Furthermore you may use our trademarks where it is necessary to indicate
00029 * the intended purpose of a product or service provided you use it in accordance
00030 * with honest practices in industrial or commercial matters.
00031 * If you want to propagate modified versions of the Program under the name "Z-Push",
00032 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00033 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00034 *
00035 * This program is distributed in the hope that it will be useful,
00036 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00037 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00038 * GNU Affero General Public License for more details.
00039 *
00040 * You should have received a copy of the GNU Affero General Public License
00041 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00042 *
00043 * Consult LICENSE file for details
00044 ************************************************/
00045 
00046 class SyncParameters extends StateObject {
00047     const DEFAULTOPTIONS = "DEFAULT";
00048     const SMSOPTIONS = "SMS";
00049 
00050     private $synckeyChanged = false;
00051     private $currentCPO = self::DEFAULTOPTIONS;
00052 
00053     protected $unsetdata = array(
00054                                     'uuid' => false,
00055                                     'uuidcounter' => false,
00056                                     'uuidnewcounter' => false,
00057                                     'folderid' => false,
00058                                     'referencelifetime' => 10,
00059                                     'lastsynctime' => false,
00060                                     'referencepolicykey' => true,
00061                                     'pingableflag' => false,
00062                                     'contentclass' => false,
00063                                     'deletesasmoves' => false,
00064                                     'conversationmode' => false,
00065                                     'windowsize' => 5,
00066                                     'contentparameters' => array()
00067                                 );
00068 
00072     public function SyncParameters() {
00073         // initialize ContentParameters for the current option
00074         $this->checkCPO();
00075     }
00076 
00077 
00091     public function GetSyncKey() {
00092         if (isset($this->uuid) && isset($this->uuidCounter))
00093             return StateManager::BuildStateKey($this->uuid, $this->uuidCounter);
00094 
00095         return false;
00096     }
00097 
00108     public function SetSyncKey($synckey) {
00109         list($this->uuid, $this->uuidCounter) = StateManager::ParseStateKey($synckey);
00110 
00111         // remove newSyncKey
00112         unset($this->uuidNewCounter);
00113 
00114         return true;
00115     }
00116 
00123     public function HasSyncKey() {
00124         return (isset($this->uuid) && isset($this->uuidCounter));
00125     }
00126 
00138     public function SetNewSyncKey($synckey) {
00139         list($uuid, $uuidNewCounter) = StateManager::ParseStateKey($synckey);
00140         if (!$this->HasSyncKey()) {
00141             $this->uuid = $uuid;
00142             $this->uuidCounter = $uuidNewCounter;
00143         }
00144         else if ($uuid !== $this->uuid)
00145             throw new FatalException("SyncParameters->SetNewSyncKey(): new SyncKey must have the same UUID as current SyncKey");
00146 
00147         $this->uuidNewCounter = $uuidNewCounter;
00148         $this->synckeyChanged = true;
00149     }
00150 
00157     public function GetNewSyncKey() {
00158         if (isset($this->uuid) && isset($this->uuidNewCounter))
00159             return StateManager::BuildStateKey($this->uuid, $this->uuidNewCounter);
00160 
00161         return false;
00162     }
00163 
00170     public function HasNewSyncKey() {
00171         return (isset($this->uuid) && isset($this->uuidNewCounter));
00172     }
00173 
00182     public function GetLatestSyncKey() {
00183         // New becomes old
00184         if ($this->HasUuidNewCounter()) {
00185             $this->uuidCounter = $this->uuidNewCounter;
00186             unset($this->uuidNewCounter);
00187         }
00188 
00189         ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncParameters->GetLastestSyncKey(): '%s'", $this->GetSyncKey()));
00190         return $this->GetSyncKey();
00191     }
00192 
00199     public function RemoveSyncKey() {
00200         if (isset($this->uuid))
00201             unset($this->uuid);
00202 
00203         if (isset($this->uuidCounter))
00204             unset($this->uuidCounter);
00205 
00206         if (isset($this->uuidNewCounter))
00207             unset($this->uuidNewCounter);
00208 
00209         ZLog::Write(LOGLEVEL_DEBUG, "SyncParameters->RemoveSyncKey(): saved sync key removed");
00210         return true;
00211     }
00212 
00213 
00230     public function GetCPO($options = self::DEFAULTOPTIONS) {
00231         if ($options !== self::DEFAULTOPTIONS && $options !== self::SMSOPTIONS)
00232             throw new FatalNotImplementedException(sprintf("SyncParameters->GetCPO('%s') ContentParameters is invalid. Such type is not available.", $options));
00233 
00234         $this->checkCPO($options);
00235 
00236         // copy contentclass and conversationmode to the CPO
00237         $this->contentParameters[$options]->SetContentClass($this->contentclass);
00238         $this->contentParameters[$options]->SetConversationMode($this->conversationmode);
00239 
00240         return $this->contentParameters[$options];
00241     }
00242 
00252     public function UseCPO($options = self::DEFAULTOPTIONS) {
00253         if ($options !== self::DEFAULTOPTIONS && $options !== self::SMSOPTIONS)
00254             throw new FatalNotImplementedException(sprintf("SyncParameters->UseCPO('%s') ContentParameters is invalid. Such type is not available.", $options));
00255 
00256         ZLOG::Write(LOGLEVEL_DEBUG, sprintf("SyncParameters->UseCPO('%s')", $options));
00257         $this->currentCPO = $options;
00258         $this->checkCPO($this->currentCPO);
00259     }
00260 
00270     private function checkCPO($options = self::DEFAULTOPTIONS) {
00271         if (!isset($this->contentParameters[$options])) {
00272             $a = $this->contentParameters;
00273             $a[$options] = new ContentParameters();
00274             $this->contentParameters = $a;
00275         }
00276 
00277         return true;
00278     }
00279 
00291     public function __call($name, $arguments) {
00292         $lowname = strtolower($name);
00293         $operator = substr($lowname, 0,3);
00294         $var = substr($lowname,3);
00295 
00296         if (array_key_exists($var, $this->unsetdata)) {
00297             return parent::__call($name, $arguments);
00298         }
00299 
00300         return $this->contentParameters[$this->currentCPO]->__call($name, $arguments);
00301     }
00302 
00303 
00314     protected function preSerialize() {
00315         parent::preSerialize();
00316 
00317         if ($this->changed === true && $this->synckeyChanged)
00318             $this->lastsynctime = time();
00319 
00320         return true;
00321     }
00322 
00329     protected function postUnserialize() {
00330         // init with default options
00331         $this->UseCPO();
00332 
00333         return true;
00334     }
00335 }
00336 
00337 ?>