Back to index

d-push  2.0
moveitems.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   moveitems.php
00004 * Project   :   Z-Push
00005 * Descr     :   Provides the MOVEITEMS command
00006 *
00007 * Created   :   16.02.2012
00008 *
00009 * Copyright 2007 - 2012 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 MoveItems extends RequestProcessor {
00045 
00054     public function Handle($commandCode) {
00055         if(!self::$decoder->getElementStartTag(SYNC_MOVE_MOVES))
00056             return false;
00057 
00058         $moves = array();
00059         while(self::$decoder->getElementStartTag(SYNC_MOVE_MOVE)) {
00060             $move = array();
00061             if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCMSGID)) {
00062                 $move["srcmsgid"] = self::$decoder->getElementContent();
00063                 if(!self::$decoder->getElementEndTag())
00064                     break;
00065             }
00066             if(self::$decoder->getElementStartTag(SYNC_MOVE_SRCFLDID)) {
00067                 $move["srcfldid"] = self::$decoder->getElementContent();
00068                 if(!self::$decoder->getElementEndTag())
00069                     break;
00070             }
00071             if(self::$decoder->getElementStartTag(SYNC_MOVE_DSTFLDID)) {
00072                 $move["dstfldid"] = self::$decoder->getElementContent();
00073                 if(!self::$decoder->getElementEndTag())
00074                     break;
00075             }
00076             array_push($moves, $move);
00077 
00078             if(!self::$decoder->getElementEndTag())
00079                 return false;
00080         }
00081 
00082         if(!self::$decoder->getElementEndTag())
00083             return false;
00084 
00085         self::$encoder->StartWBXML();
00086 
00087         self::$encoder->startTag(SYNC_MOVE_MOVES);
00088 
00089         foreach($moves as $move) {
00090             self::$encoder->startTag(SYNC_MOVE_RESPONSE);
00091             self::$encoder->startTag(SYNC_MOVE_SRCMSGID);
00092             self::$encoder->content($move["srcmsgid"]);
00093             self::$encoder->endTag();
00094 
00095             $status = SYNC_MOVEITEMSSTATUS_SUCCESS;
00096             $result = false;
00097             try {
00098                 // if the source folder is an additional folder the backend has to be setup correctly
00099                 if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($move["srcfldid"])))
00100                     throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id '%s'", $move["srcfldid"]), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
00101 
00102                 $importer = self::$backend->GetImporter($move["srcfldid"]);
00103                 if ($importer === false)
00104                     throw new StatusException(sprintf("HandleMoveItems() could not get an importer for folder id '%s'", $move["srcfldid"]), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
00105 
00106                 $result = $importer->ImportMessageMove($move["srcmsgid"], $move["dstfldid"]);
00107                 // We discard the importer state for now.
00108             }
00109             catch (StatusException $stex) {
00110                 if ($stex->getCode() == SYNC_STATUS_FOLDERHIERARCHYCHANGED) // same as SYNC_FSSTATUS_CODEUNKNOWN
00111                     $status = SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID;
00112                 else
00113                     $status = $stex->getCode();
00114             }
00115 
00116             self::$topCollector->AnnounceInformation(sprintf("Operation status: %s", $status), true);
00117 
00118             self::$encoder->startTag(SYNC_MOVE_STATUS);
00119             self::$encoder->content($status);
00120             self::$encoder->endTag();
00121 
00122             self::$encoder->startTag(SYNC_MOVE_DSTMSGID);
00123             self::$encoder->content( (($result !== false ) ? $result : $move["srcmsgid"]));
00124             self::$encoder->endTag();
00125             self::$encoder->endTag();
00126         }
00127 
00128         self::$encoder->endTag();
00129         return true;
00130     }
00131 }
00132 ?>