@@ -19,14 +19,17 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function Handle($commandCode) { |
| 21 | 21 | // Parse input |
| 22 | - if(!self::$decoder->getElementStartTag(SYNC_RESOLVERECIPIENTS_RESOLVERECIPIENTS)) |
|
| 23 | - return false; |
|
| 22 | + if(!self::$decoder->getElementStartTag(SYNC_RESOLVERECIPIENTS_RESOLVERECIPIENTS)) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 24 | 25 | |
| 25 | 26 | $resolveRecipients = new SyncResolveRecipients(); |
| 26 | 27 | $resolveRecipients->Decode(self::$decoder); |
| 27 | 28 | |
| 28 | - if(!self::$decoder->getElementEndTag()) |
|
| 29 | - return false; // SYNC_RESOLVERECIPIENTS_RESOLVERECIPIENTS |
|
| 29 | + if(!self::$decoder->getElementEndTag()) { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | + // SYNC_RESOLVERECIPIENTS_RESOLVERECIPIENTS |
|
| 30 | 33 | |
| 31 | 34 | $resolveRecipients = self::$backend->ResolveRecipients($resolveRecipients); |
| 32 | 35 | |
@@ -19,16 +19,19 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function Handle ($commandCode) { |
| 21 | 21 | // Parse input |
| 22 | - if(!self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_FOLDERSYNC)) |
|
| 23 | - return false; |
|
| 22 | + if(!self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_FOLDERSYNC)) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 24 | 25 | |
| 25 | - if(!self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_SYNCKEY)) |
|
| 26 | - return false; |
|
| 26 | + if(!self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_SYNCKEY)) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | $synckey = self::$decoder->getElementContent(); |
| 29 | 31 | |
| 30 | - if(!self::$decoder->getElementEndTag()) |
|
| 31 | - return false; |
|
| 32 | + if(!self::$decoder->getElementEndTag()) { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 32 | 35 | |
| 33 | 36 | // every FolderSync with SyncKey 0 should return the supported AS version & command headers |
| 34 | 37 | if($synckey == "0") { |
@@ -47,11 +50,9 @@ discard block |
||
| 47 | 50 | |
| 48 | 51 | // there are no SyncParameters for the hierarchy, but we use it to save the latest synckeys |
| 49 | 52 | $spa = self::$deviceManager->GetStateManager()->GetSynchedFolderState(false); |
| 50 | - } |
|
| 51 | - catch (StateNotFoundException $snfex) { |
|
| 53 | + } catch (StateNotFoundException $snfex) { |
|
| 52 | 54 | $status = SYNC_FSSTATUS_SYNCKEYERROR; |
| 53 | - } |
|
| 54 | - catch (StateInvalidException $sive) { |
|
| 55 | + } catch (StateInvalidException $sive) { |
|
| 55 | 56 | $status = SYNC_FSSTATUS_SYNCKEYERROR; |
| 56 | 57 | } |
| 57 | 58 | |
@@ -71,22 +72,25 @@ discard block |
||
| 71 | 72 | // Ignore <Count> if present |
| 72 | 73 | if(self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_COUNT)) { |
| 73 | 74 | self::$decoder->getElementContent(); |
| 74 | - if(!self::$decoder->getElementEndTag()) |
|
| 75 | - return false; |
|
| 75 | + if(!self::$decoder->getElementEndTag()) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | // Process the changes (either <Add>, <Modify>, or <Remove>) |
| 79 | 81 | $element = self::$decoder->getElement(); |
| 80 | 82 | |
| 81 | - if($element[EN_TYPE] != EN_TYPE_STARTTAG) |
|
| 82 | - return false; |
|
| 83 | + if($element[EN_TYPE] != EN_TYPE_STARTTAG) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | $importer = false; |
| 85 | 88 | WBXMLDecoder::ResetInWhile("folderSyncIncomingChange"); |
| 86 | 89 | while(WBXMLDecoder::InWhile("folderSyncIncomingChange")) { |
| 87 | 90 | $folder = new SyncFolder(); |
| 88 | - if(!$folder->Decode(self::$decoder)) |
|
| 89 | - break; |
|
| 91 | + if(!$folder->Decode(self::$decoder)) { |
|
| 92 | + break; |
|
| 93 | + } |
|
| 90 | 94 | |
| 91 | 95 | // add the backendId to the SyncFolder object |
| 92 | 96 | $folder->BackendId = self::$deviceManager->GetBackendIdForFolderId($folder->serverid); |
@@ -110,19 +114,18 @@ discard block |
||
| 110 | 114 | $serverid = $changesMem->ImportFolderDeletion($folder); |
| 111 | 115 | break; |
| 112 | 116 | } |
| 113 | - } |
|
| 114 | - else { |
|
| 117 | + } else { |
|
| 115 | 118 | ZLog::Write(LOGLEVEL_WARN, sprintf("Request->HandleFolderSync(): ignoring incoming folderchange for folder '%s' as status indicates problem.", $folder->displayname)); |
| 116 | 119 | self::$topCollector->AnnounceInformation("Incoming change ignored", true); |
| 117 | 120 | } |
| 118 | - } |
|
| 119 | - catch (StatusException $stex) { |
|
| 121 | + } catch (StatusException $stex) { |
|
| 120 | 122 | $status = $stex->getCode(); |
| 121 | 123 | } |
| 122 | 124 | } |
| 123 | 125 | |
| 124 | - if(!self::$decoder->getElementEndTag()) |
|
| 125 | - return false; |
|
| 126 | + if(!self::$decoder->getElementEndTag()) { |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 126 | 129 | } |
| 127 | 130 | // no incoming changes |
| 128 | 131 | else { |
@@ -133,8 +136,9 @@ discard block |
||
| 133 | 136 | } |
| 134 | 137 | } |
| 135 | 138 | |
| 136 | - if(!self::$decoder->getElementEndTag()) |
|
| 137 | - return false; |
|
| 139 | + if(!self::$decoder->getElementEndTag()) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 138 | 142 | |
| 139 | 143 | // We have processed incoming foldersync requests, now send the PIM |
| 140 | 144 | // our changes |
@@ -147,8 +151,9 @@ discard block |
||
| 147 | 151 | if ($status == SYNC_FSSTATUS_SUCCESS) { |
| 148 | 152 | try { |
| 149 | 153 | // do nothing if this is an invalid device id (like the 'validate' Androids internal client sends) |
| 150 | - if (!Request::IsValidDeviceID()) |
|
| 151 | - throw new StatusException(sprintf("Request::IsValidDeviceID() indicated that '%s' is not a valid device id", Request::GetDeviceID()), SYNC_FSSTATUS_SERVERERROR); |
|
| 154 | + if (!Request::IsValidDeviceID()) { |
|
| 155 | + throw new StatusException(sprintf("Request::IsValidDeviceID() indicated that '%s' is not a valid device id", Request::GetDeviceID()), SYNC_FSSTATUS_SERVERERROR); |
|
| 156 | + } |
|
| 152 | 157 | |
| 153 | 158 | // Changes from backend are sent to the MemImporter and processed for the HierarchyCache. |
| 154 | 159 | // The state which is saved is from the backend, as the MemImporter is only a proxy. |
@@ -189,12 +194,12 @@ discard block |
||
| 189 | 194 | |
| 190 | 195 | // get the new state from the backend |
| 191 | 196 | $newsyncstate = (isset($exporter))?$exporter->GetState():""; |
| 192 | - } |
|
| 193 | - catch (StatusException $stex) { |
|
| 194 | - if ($stex->getCode() == SYNC_FSSTATUS_CODEUNKNOWN) |
|
| 195 | - $status = SYNC_FSSTATUS_SYNCKEYERROR; |
|
| 196 | - else |
|
| 197 | - $status = $stex->getCode(); |
|
| 197 | + } catch (StatusException $stex) { |
|
| 198 | + if ($stex->getCode() == SYNC_FSSTATUS_CODEUNKNOWN) { |
|
| 199 | + $status = SYNC_FSSTATUS_SYNCKEYERROR; |
|
| 200 | + } else { |
|
| 201 | + $status = $stex->getCode(); |
|
| 202 | + } |
|
| 198 | 203 | } |
| 199 | 204 | } |
| 200 | 205 | |
@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function Handle($commandCode) { |
| 22 | 22 | // Parse input |
| 23 | - if(!self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_ITEMOPERATIONS)) |
|
| 24 | - return false; |
|
| 23 | + if(!self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_ITEMOPERATIONS)) { |
|
| 24 | + return false; |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | $itemoperations = array(); |
| 27 | 28 | //ItemOperations can either be Fetch, EmptyFolderContents or Move |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | //TODO check if multiple item operations are possible in one request |
| 31 | 32 | $el = self::$decoder->getElement(); |
| 32 | 33 | |
| 33 | - if($el[EN_TYPE] != EN_TYPE_STARTTAG) |
|
| 34 | - return false; |
|
| 34 | + if($el[EN_TYPE] != EN_TYPE_STARTTAG) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $fetch = $efc = $move = false; |
| 37 | 39 | $operation = array(); |
@@ -39,13 +41,11 @@ discard block |
||
| 39 | 41 | $fetch = true; |
| 40 | 42 | $operation['operation'] = SYNC_ITEMOPERATIONS_FETCH; |
| 41 | 43 | self::$topCollector->AnnounceInformation("Fetch", true); |
| 42 | - } |
|
| 43 | - else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS) { |
|
| 44 | + } else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS) { |
|
| 44 | 45 | $efc = true; |
| 45 | 46 | $operation['operation'] = SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS; |
| 46 | 47 | self::$topCollector->AnnounceInformation("Empty Folder", true); |
| 47 | - } |
|
| 48 | - else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_MOVE) { |
|
| 48 | + } else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_MOVE) { |
|
| 49 | 49 | $move = true; |
| 50 | 50 | $operation['operation'] = SYNC_ITEMOPERATIONS_MOVE; |
| 51 | 51 | self::$topCollector->AnnounceInformation("Move", true); |
@@ -66,32 +66,42 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_STORE)) { |
| 68 | 68 | $operation['store'] = self::$decoder->getElementContent(); |
| 69 | - if(!self::$decoder->getElementEndTag()) |
|
| 70 | - return false;//SYNC_ITEMOPERATIONS_STORE |
|
| 69 | + if(!self::$decoder->getElementEndTag()) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + //SYNC_ITEMOPERATIONS_STORE |
|
| 71 | 73 | } |
| 72 | 74 | |
| 73 | 75 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_LONGID)) { |
| 74 | 76 | $operation['longid'] = self::$decoder->getElementContent(); |
| 75 | - if(!self::$decoder->getElementEndTag()) |
|
| 76 | - return false;//SYNC_SEARCH_LONGID |
|
| 77 | + if(!self::$decoder->getElementEndTag()) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + //SYNC_SEARCH_LONGID |
|
| 77 | 81 | } |
| 78 | 82 | |
| 79 | 83 | if(self::$decoder->getElementStartTag(SYNC_FOLDERID)) { |
| 80 | 84 | $operation['folderid'] = self::$decoder->getElementContent(); |
| 81 | - if(!self::$decoder->getElementEndTag()) |
|
| 82 | - return false;//SYNC_FOLDERID |
|
| 85 | + if(!self::$decoder->getElementEndTag()) { |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 88 | + //SYNC_FOLDERID |
|
| 83 | 89 | } |
| 84 | 90 | |
| 85 | 91 | if(self::$decoder->getElementStartTag(SYNC_SERVERENTRYID)) { |
| 86 | 92 | $operation['serverid'] = self::$decoder->getElementContent(); |
| 87 | - if(!self::$decoder->getElementEndTag()) |
|
| 88 | - return false;//SYNC_SERVERENTRYID |
|
| 93 | + if(!self::$decoder->getElementEndTag()) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + //SYNC_SERVERENTRYID |
|
| 89 | 97 | } |
| 90 | 98 | |
| 91 | 99 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_FILEREFERENCE)) { |
| 92 | 100 | $operation['filereference'] = self::$decoder->getElementContent(); |
| 93 | - if(!self::$decoder->getElementEndTag()) |
|
| 94 | - return false;//SYNC_AIRSYNCBASE_FILEREFERENCE |
|
| 101 | + if(!self::$decoder->getElementEndTag()) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + //SYNC_AIRSYNCBASE_FILEREFERENCE |
|
| 95 | 105 | } |
| 96 | 106 | |
| 97 | 107 | if(($el = self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_OPTIONS)) && ($el[EN_FLAGS] & EN_FLAGS_CONTENT)) { |
@@ -116,24 +126,29 @@ discard block |
||
| 116 | 126 | |
| 117 | 127 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) { |
| 118 | 128 | $operation["cpo"]->BodyPreference($bptype)->SetTruncationSize(self::$decoder->getElementContent()); |
| 119 | - if(!self::$decoder->getElementEndTag()) |
|
| 120 | - return false; |
|
| 129 | + if(!self::$decoder->getElementEndTag()) { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 121 | 132 | } |
| 122 | 133 | |
| 123 | 134 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) { |
| 124 | 135 | $operation["cpo"]->BodyPreference($bptype)->SetAllOrNone(self::$decoder->getElementContent()); |
| 125 | - if(!self::$decoder->getElementEndTag()) |
|
| 126 | - return false; |
|
| 136 | + if(!self::$decoder->getElementEndTag()) { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 127 | 139 | } |
| 128 | 140 | |
| 129 | 141 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) { |
| 130 | 142 | $operation["cpo"]->BodyPreference($bptype)->SetPreview(self::$decoder->getElementContent()); |
| 131 | - if(!self::$decoder->getElementEndTag()) |
|
| 132 | - return false; |
|
| 143 | + if(!self::$decoder->getElementEndTag()) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 133 | 146 | } |
| 134 | 147 | |
| 135 | - if(!self::$decoder->getElementEndTag()) |
|
| 136 | - return false;//SYNC_AIRSYNCBASE_BODYPREFERENCE |
|
| 148 | + if(!self::$decoder->getElementEndTag()) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + //SYNC_AIRSYNCBASE_BODYPREFERENCE |
|
| 137 | 152 | } |
| 138 | 153 | |
| 139 | 154 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPARTPREFERENCE)) { |
@@ -147,36 +162,42 @@ discard block |
||
| 147 | 162 | |
| 148 | 163 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) { |
| 149 | 164 | $operation["cpo"]->BodyPartPreference($bpptype)->SetTruncationSize(self::$decoder->getElementContent()); |
| 150 | - if(!self::$decoder->getElementEndTag()) |
|
| 151 | - return false; |
|
| 165 | + if(!self::$decoder->getElementEndTag()) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 152 | 168 | } |
| 153 | 169 | |
| 154 | 170 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) { |
| 155 | 171 | $operation["cpo"]->BodyPartPreference($bpptype)->SetAllOrNone(self::$decoder->getElementContent()); |
| 156 | - if(!self::$decoder->getElementEndTag()) |
|
| 157 | - return false; |
|
| 172 | + if(!self::$decoder->getElementEndTag()) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 158 | 175 | } |
| 159 | 176 | |
| 160 | 177 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) { |
| 161 | 178 | $operation["cpo"]->BodyPartPreference($bpptype)->SetPreview(self::$decoder->getElementContent()); |
| 162 | - if(!self::$decoder->getElementEndTag()) |
|
| 163 | - return false; |
|
| 179 | + if(!self::$decoder->getElementEndTag()) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 164 | 182 | } |
| 165 | 183 | |
| 166 | - if (!self::$decoder->getElementEndTag()) |
|
| 167 | - return false; |
|
| 184 | + if (!self::$decoder->getElementEndTag()) { |
|
| 185 | + return false; |
|
| 186 | + } |
|
| 168 | 187 | } |
| 169 | 188 | |
| 170 | 189 | if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) { |
| 171 | 190 | $operation["cpo"]->SetMimeSupport(self::$decoder->getElementContent()); |
| 172 | - if(!self::$decoder->getElementEndTag()) |
|
| 173 | - return false; |
|
| 191 | + if(!self::$decoder->getElementEndTag()) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 174 | 194 | } |
| 175 | 195 | |
| 176 | 196 | if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_RANGE)) { |
| 177 | 197 | $operation["range"] = self::$decoder->getElementContent(); |
| 178 | - if(!self::$decoder->getElementEndTag()) |
|
| 179 | - return false; |
|
| 198 | + if(!self::$decoder->getElementEndTag()) { |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 180 | 201 | } |
| 181 | 202 | |
| 182 | 203 | if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_SCHEMA)) { |
@@ -195,8 +216,9 @@ discard block |
||
| 195 | 216 | |
| 196 | 217 | if(self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) { |
| 197 | 218 | $operation["cpo"]->SetRmSupport(self::$decoder->getElementContent()); |
| 198 | - if(!self::$decoder->getElementEndTag()) |
|
| 199 | - return false; |
|
| 219 | + if(!self::$decoder->getElementEndTag()) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 200 | 222 | } |
| 201 | 223 | |
| 202 | 224 | //break if it reached the endtag |
@@ -222,16 +244,19 @@ discard block |
||
| 222 | 244 | if ($efc) { |
| 223 | 245 | if(self::$decoder->getElementStartTag(SYNC_FOLDERID)) { |
| 224 | 246 | $operation['folderid'] = self::$decoder->getElementContent(); |
| 225 | - if(!self::$decoder->getElementEndTag()) |
|
| 226 | - return false;//SYNC_FOLDERID |
|
| 247 | + if(!self::$decoder->getElementEndTag()) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + //SYNC_FOLDERID |
|
| 227 | 251 | } |
| 228 | 252 | if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_OPTIONS)) { |
| 229 | 253 | if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_DELETESUBFOLDERS)) { |
| 230 | 254 | $operation['deletesubfolders'] = true; |
| 231 | 255 | if (($dsf = self::$decoder->getElementContent()) !== false) { |
| 232 | 256 | $operation['deletesubfolders'] = (bool)$dsf; |
| 233 | - if(!self::$decoder->getElementEndTag()) |
|
| 234 | - return false; |
|
| 257 | + if(!self::$decoder->getElementEndTag()) { |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 235 | 260 | } |
| 236 | 261 | } |
| 237 | 262 | self::$decoder->getElementEndTag(); |
@@ -292,25 +317,21 @@ discard block |
||
| 292 | 317 | try { |
| 293 | 318 | self::$topCollector->AnnounceInformation("Get attachment data from backend with file reference"); |
| 294 | 319 | $data = self::$backend->GetAttachmentData($operation['filereference']); |
| 295 | - } |
|
| 296 | - catch (StatusException $stex) { |
|
| 320 | + } catch (StatusException $stex) { |
|
| 297 | 321 | $status = $stex->getCode(); |
| 298 | 322 | } |
| 299 | 323 | |
| 300 | - } |
|
| 301 | - else { |
|
| 324 | + } else { |
|
| 302 | 325 | try { |
| 303 | 326 | if (isset($operation['folderid']) && isset($operation['serverid'])) { |
| 304 | 327 | self::$topCollector->AnnounceInformation("Fetching data from backend with item and folder id"); |
| 305 | 328 | $data = self::$backend->Fetch($operation['backendfolderid'], $operation['serverid'], $operation["cpo"]); |
| 306 | - } |
|
| 307 | - else if (isset($operation['longid'])) { |
|
| 329 | + } else if (isset($operation['longid'])) { |
|
| 308 | 330 | self::$topCollector->AnnounceInformation("Fetching data from backend with long id"); |
| 309 | 331 | $tmp = explode(":", $operation['longid']); |
| 310 | 332 | $data = self::$backend->Fetch(self::$deviceManager->GetBackendIdForFolderId($tmp[0]), $tmp[1], $operation["cpo"]); |
| 311 | 333 | } |
| 312 | - } |
|
| 313 | - catch (StatusException $stex) { |
|
| 334 | + } catch (StatusException $stex) { |
|
| 314 | 335 | // the only option to return is that we could not retrieve it |
| 315 | 336 | $status = SYNC_ITEMOPERATIONSSTATUS_CONVERSIONFAILED; |
| 316 | 337 | } |
@@ -374,8 +395,7 @@ discard block |
||
| 374 | 395 | |
| 375 | 396 | // send request to backend |
| 376 | 397 | self::$backend->EmptyFolder($operation['backendfolderid'], $operation['deletesubfolders']); |
| 377 | - } |
|
| 378 | - catch (StatusException $stex) { |
|
| 398 | + } catch (StatusException $stex) { |
|
| 379 | 399 | $status = $stex->getCode(); |
| 380 | 400 | } |
| 381 | 401 | |
@@ -19,8 +19,9 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function Handle($commandCode) { |
| 21 | 21 | $attname = Request::GetGETAttachmentName(); |
| 22 | - if(!$attname) |
|
| 23 | - return false; |
|
| 22 | + if(!$attname) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 24 | 25 | |
| 25 | 26 | try { |
| 26 | 27 | $attachment = self::$backend->GetAttachmentData($attname); |
@@ -28,19 +29,20 @@ discard block |
||
| 28 | 29 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetAttachment(): attachment stream from backend: %s", $stream)); |
| 29 | 30 | |
| 30 | 31 | // need to check for a resource here, as eg. feof('Error') === false and causing infinite loop in while! |
| 31 | - if (!is_resource($stream)) |
|
| 32 | - throw new StatusException(sprintf("HandleGetAttachment(): No stream resource returned by backend for attachment: %s", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 32 | + if (!is_resource($stream)) { |
|
| 33 | + throw new StatusException(sprintf("HandleGetAttachment(): No stream resource returned by backend for attachment: %s", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | header("Content-Type: application/octet-stream"); |
| 35 | 37 | self::$topCollector->AnnounceInformation("Starting attachment streaming", true); |
| 36 | 38 | $l = fpassthru($stream); |
| 37 | 39 | fclose($stream); |
| 38 | - if ($l === false) |
|
| 39 | - throw new FatalException("HandleGetAttachment(): fpassthru === false !!!"); |
|
| 40 | + if ($l === false) { |
|
| 41 | + throw new FatalException("HandleGetAttachment(): fpassthru === false !!!"); |
|
| 42 | + } |
|
| 40 | 43 | self::$topCollector->AnnounceInformation(sprintf("Streamed %d KB attachment", round($l/1024)), true); |
| 41 | 44 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleGetAttachment(): attachment with %d KB sent to mobile", round($l/1024))); |
| 42 | - } |
|
| 43 | - catch (StatusException $s) { |
|
| 45 | + } catch (StatusException $s) { |
|
| 44 | 46 | // StatusException already logged so we just need to pass it upwards to send a HTTP error |
| 45 | 47 | throw new HTTPReturnCodeException($s->getMessage(), HTTP_CODE_500, null, LOGLEVEL_DEBUG); |
| 46 | 48 | } |
@@ -22,11 +22,13 @@ discard block |
||
| 22 | 22 | public function Handle($commandCode) { |
| 23 | 23 | $sc = new SyncCollections(); |
| 24 | 24 | |
| 25 | - if(!self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE)) |
|
| 26 | - return false; |
|
| 25 | + if(!self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE)) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | - if(!self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERS)) |
|
| 29 | - return false; |
|
| 29 | + if(!self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERS)) { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 30 | 32 | |
| 31 | 33 | while(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDER)) { |
| 32 | 34 | $spa = new SyncParameters(); |
@@ -38,22 +40,21 @@ discard block |
||
| 38 | 40 | if(self::$decoder->getElementStartTag(SYNC_SYNCKEY)) { |
| 39 | 41 | try { |
| 40 | 42 | $spa->SetSyncKey(self::$decoder->getElementContent()); |
| 41 | - } |
|
| 42 | - catch (StateInvalidException $siex) { |
|
| 43 | + } catch (StateInvalidException $siex) { |
|
| 43 | 44 | $spastatus = SYNC_GETITEMESTSTATUS_SYNCSTATENOTPRIMED; |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | - if(!self::$decoder->getElementEndTag()) |
|
| 47 | - return false; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - elseif(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERID)) { |
|
| 47 | + if(!self::$decoder->getElementEndTag()) { |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | + } elseif(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERID)) { |
|
| 51 | 51 | $fid = self::$decoder->getElementContent(); |
| 52 | 52 | $spa->SetFolderId($fid); |
| 53 | 53 | $spa->SetBackendFolderId(self::$deviceManager->GetBackendIdForFolderId($fid)); |
| 54 | 54 | |
| 55 | - if(!self::$decoder->getElementEndTag()) |
|
| 56 | - return false; |
|
| 55 | + if(!self::$decoder->getElementEndTag()) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | // conversation mode requested |
@@ -61,8 +62,9 @@ discard block |
||
| 61 | 62 | $spa->SetConversationMode(true); |
| 62 | 63 | if(($conversationmode = self::$decoder->getElementContent()) !== false) { |
| 63 | 64 | $spa->SetConversationMode((bool)$conversationmode); |
| 64 | - if(!self::$decoder->getElementEndTag()) |
|
| 65 | - return false; |
|
| 65 | + if(!self::$decoder->getElementEndTag()) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 66 | 68 | } |
| 67 | 69 | } |
| 68 | 70 | |
@@ -70,16 +72,18 @@ discard block |
||
| 70 | 72 | elseif(self::$decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERTYPE)) { |
| 71 | 73 | $spa->SetContentClass(self::$decoder->getElementContent()); |
| 72 | 74 | |
| 73 | - if(!self::$decoder->getElementEndTag()) |
|
| 74 | - return false; |
|
| 75 | + if(!self::$decoder->getElementEndTag()) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 75 | 78 | } |
| 76 | 79 | |
| 77 | 80 | //TODO AS 2.5 and filtertype not set |
| 78 | 81 | elseif(self::$decoder->getElementStartTag(SYNC_FILTERTYPE)) { |
| 79 | 82 | $spa->SetFilterType(self::$decoder->getElementContent()); |
| 80 | 83 | |
| 81 | - if(!self::$decoder->getElementEndTag()) |
|
| 82 | - return false; |
|
| 84 | + if(!self::$decoder->getElementEndTag()) { |
|
| 85 | + return false; |
|
| 86 | + } |
|
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | while(self::$decoder->getElementStartTag(SYNC_OPTIONS)) { |
@@ -97,8 +101,9 @@ discard block |
||
| 97 | 101 | // set to synchronize all changes. The mobile could overwrite this value |
| 98 | 102 | $spa->SetFilterType(SYNC_FILTERTYPE_ALL); |
| 99 | 103 | |
| 100 | - if(!self::$decoder->getElementEndTag()) |
|
| 101 | - return false; |
|
| 104 | + if(!self::$decoder->getElementEndTag()) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 102 | 107 | } |
| 103 | 108 | // if no foldertype is defined, use default cpo |
| 104 | 109 | else if ($firstOption){ |
@@ -110,14 +115,16 @@ discard block |
||
| 110 | 115 | |
| 111 | 116 | if(self::$decoder->getElementStartTag(SYNC_FILTERTYPE)) { |
| 112 | 117 | $spa->SetFilterType(self::$decoder->getElementContent()); |
| 113 | - if(!self::$decoder->getElementEndTag()) |
|
| 114 | - return false; |
|
| 118 | + if(!self::$decoder->getElementEndTag()) { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 115 | 121 | } |
| 116 | 122 | |
| 117 | 123 | if(self::$decoder->getElementStartTag(SYNC_MAXITEMS)) { |
| 118 | 124 | $spa->SetWindowSize($maxitems = self::$decoder->getElementContent()); |
| 119 | - if(!self::$decoder->getElementEndTag()) |
|
| 120 | - return false; |
|
| 125 | + if(!self::$decoder->getElementEndTag()) { |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 121 | 128 | } |
| 122 | 129 | |
| 123 | 130 | $e = self::$decoder->peek(); |
@@ -140,8 +147,7 @@ discard block |
||
| 140 | 147 | if (! $spa->HasContentClass() && $spa->HasFolderId()) { |
| 141 | 148 | try { |
| 142 | 149 | $spa->SetContentClass(self::$deviceManager->GetFolderClassFromCacheByID($spa->GetFolderId())); |
| 143 | - } |
|
| 144 | - catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 150 | + } catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 145 | 151 | $spastatus = SYNC_GETITEMESTSTATUS_COLLECTIONINVALID; |
| 146 | 152 | } |
| 147 | 153 | } |
@@ -156,44 +162,46 @@ discard block |
||
| 156 | 162 | if ($spastatus) { |
| 157 | 163 | // the CPO has a folder id now, so we can set the status |
| 158 | 164 | $sc->AddParameter($spa, "status", $spastatus); |
| 159 | - } |
|
| 160 | - else { |
|
| 165 | + } else { |
|
| 161 | 166 | try { |
| 162 | 167 | $sc->AddParameter($spa, "state", self::$deviceManager->GetStateManager()->GetSyncState($spa->GetSyncKey())); |
| 163 | 168 | |
| 164 | 169 | // if this is an additional folder the backend has to be setup correctly |
| 165 | - if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) |
|
| 166 | - throw new StatusException(sprintf("HandleGetItemEstimate() could not Setup() the backend for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_GETITEMESTSTATUS_COLLECTIONINVALID); |
|
| 167 | - } |
|
| 168 | - catch (StateNotFoundException $snfex) { |
|
| 170 | + if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) { |
|
| 171 | + throw new StatusException(sprintf("HandleGetItemEstimate() could not Setup() the backend for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_GETITEMESTSTATUS_COLLECTIONINVALID); |
|
| 172 | + } |
|
| 173 | + } catch (StateNotFoundException $snfex) { |
|
| 169 | 174 | // ok, the key is invalid. Question is, if the hierarchycache is still ok |
| 170 | 175 | //if not, we have to issue SYNC_GETITEMESTSTATUS_COLLECTIONINVALID which triggers a FolderSync |
| 171 | 176 | try { |
| 172 | 177 | self::$deviceManager->GetFolderClassFromCacheByID($spa->GetFolderId()); |
| 173 | 178 | // we got here, so the HierarchyCache is ok |
| 174 | 179 | $sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_SYNCKKEYINVALID); |
| 175 | - } |
|
| 176 | - catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 180 | + } catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 177 | 181 | $sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_COLLECTIONINVALID); |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | self::$topCollector->AnnounceInformation("StateNotFoundException ". $sc->GetParameter($spa, "status"), true); |
| 181 | - } |
|
| 182 | - catch (StatusException $stex) { |
|
| 183 | - if ($stex->getCode() == SYNC_GETITEMESTSTATUS_COLLECTIONINVALID) |
|
| 184 | - $sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_COLLECTIONINVALID); |
|
| 185 | - else |
|
| 186 | - $sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_SYNCSTATENOTPRIMED); |
|
| 185 | + } catch (StatusException $stex) { |
|
| 186 | + if ($stex->getCode() == SYNC_GETITEMESTSTATUS_COLLECTIONINVALID) { |
|
| 187 | + $sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_COLLECTIONINVALID); |
|
| 188 | + } else { |
|
| 189 | + $sc->AddParameter($spa, "status", SYNC_GETITEMESTSTATUS_SYNCSTATENOTPRIMED); |
|
| 190 | + } |
|
| 187 | 191 | self::$topCollector->AnnounceInformation("StatusException ". $sc->GetParameter($spa, "status"), true); |
| 188 | 192 | } |
| 189 | 193 | } |
| 190 | 194 | |
| 191 | 195 | } |
| 192 | - if(!self::$decoder->getElementEndTag()) |
|
| 193 | - return false; //SYNC_GETITEMESTIMATE_FOLDERS |
|
| 196 | + if(!self::$decoder->getElementEndTag()) { |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + //SYNC_GETITEMESTIMATE_FOLDERS |
|
| 194 | 200 | |
| 195 | - if(!self::$decoder->getElementEndTag()) |
|
| 196 | - return false; //SYNC_GETITEMESTIMATE_GETITEMESTIMATE |
|
| 201 | + if(!self::$decoder->getElementEndTag()) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + //SYNC_GETITEMESTIMATE_GETITEMESTIMATE |
|
| 197 | 205 | |
| 198 | 206 | self::$encoder->startWBXML(); |
| 199 | 207 | self::$encoder->startTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE); |
@@ -203,8 +211,7 @@ discard block |
||
| 203 | 211 | |
| 204 | 212 | try { |
| 205 | 213 | $sc->CountChanges(); |
| 206 | - } |
|
| 207 | - catch (StatusException $ste) { |
|
| 214 | + } catch (StatusException $ste) { |
|
| 208 | 215 | $status = SYNC_GETITEMESTSTATUS_COLLECTIONINVALID; |
| 209 | 216 | } |
| 210 | 217 | $changes = $sc->GetChangedFolderIds(); |
@@ -212,8 +219,9 @@ discard block |
||
| 212 | 219 | foreach($sc as $folderid => $spa) { |
| 213 | 220 | self::$encoder->startTag(SYNC_GETITEMESTIMATE_RESPONSE); |
| 214 | 221 | { |
| 215 | - if ($sc->GetParameter($spa, "status")) |
|
| 216 | - $status = $sc->GetParameter($spa, "status"); |
|
| 222 | + if ($sc->GetParameter($spa, "status")) { |
|
| 223 | + $status = $sc->GetParameter($spa, "status"); |
|
| 224 | + } |
|
| 217 | 225 | |
| 218 | 226 | self::$encoder->startTag(SYNC_GETITEMESTIMATE_STATUS); |
| 219 | 227 | self::$encoder->content($status); |
@@ -234,20 +242,23 @@ discard block |
||
| 234 | 242 | self::$encoder->content($changes[$folderid]); |
| 235 | 243 | self::$encoder->endTag(); |
| 236 | 244 | |
| 237 | - if ($changes[$folderid] > 0) |
|
| 238 | - self::$topCollector->AnnounceInformation(sprintf("%s %d changes", $spa->GetContentClass(), $changes[$folderid]), true); |
|
| 245 | + if ($changes[$folderid] > 0) { |
|
| 246 | + self::$topCollector->AnnounceInformation(sprintf("%s %d changes", $spa->GetContentClass(), $changes[$folderid]), true); |
|
| 247 | + } |
|
| 239 | 248 | |
| 240 | 249 | // update the device data to mark folders as complete when syncing with WM |
| 241 | - if ($changes[$folderid] == 0) |
|
| 242 | - self::$deviceManager->SetFolderSyncStatus($folderid, DeviceManager::FLD_SYNC_COMPLETED); |
|
| 250 | + if ($changes[$folderid] == 0) { |
|
| 251 | + self::$deviceManager->SetFolderSyncStatus($folderid, DeviceManager::FLD_SYNC_COMPLETED); |
|
| 252 | + } |
|
| 243 | 253 | } |
| 244 | 254 | } |
| 245 | 255 | self::$encoder->endTag(); |
| 246 | 256 | } |
| 247 | 257 | self::$encoder->endTag(); |
| 248 | 258 | } |
| 249 | - if (array_sum($changes) == 0) |
|
| 250 | - self::$topCollector->AnnounceInformation("No changes found", true); |
|
| 259 | + if (array_sum($changes) == 0) { |
|
| 260 | + self::$topCollector->AnnounceInformation("No changes found", true); |
|
| 261 | + } |
|
| 251 | 262 | } |
| 252 | 263 | self::$encoder->endTag(); |
| 253 | 264 | |
@@ -37,16 +37,18 @@ discard block |
||
| 37 | 37 | self::$userIsAuthenticated = false; |
| 38 | 38 | |
| 39 | 39 | // when a certificate is sent, allow authentication only as the certificate owner |
| 40 | - if(defined("CERTIFICATE_OWNER_PARAMETER") && isset($_SERVER[CERTIFICATE_OWNER_PARAMETER]) && strtolower($_SERVER[CERTIFICATE_OWNER_PARAMETER]) != strtolower(Request::GetAuthUser())) |
|
| 41 | - throw new AuthenticationRequiredException(sprintf("Access denied. Access is allowed only for the certificate owner '%s'", $_SERVER[CERTIFICATE_OWNER_PARAMETER])); |
|
| 40 | + if(defined("CERTIFICATE_OWNER_PARAMETER") && isset($_SERVER[CERTIFICATE_OWNER_PARAMETER]) && strtolower($_SERVER[CERTIFICATE_OWNER_PARAMETER]) != strtolower(Request::GetAuthUser())) { |
|
| 41 | + throw new AuthenticationRequiredException(sprintf("Access denied. Access is allowed only for the certificate owner '%s'", $_SERVER[CERTIFICATE_OWNER_PARAMETER])); |
|
| 42 | + } |
|
| 42 | 43 | |
| 43 | 44 | if (Request::GetImpersonatedUser() && strcasecmp(Request::GetAuthUser(), Request::GetImpersonatedUser()) !== 0) { |
| 44 | 45 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("RequestProcessor->Authenticate(): Impersonation active - authenticating: '%s' - impersonating '%s'", Request::GetAuthUser(), Request::GetImpersonatedUser())); |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | $backend = ZPush::GetBackend(); |
| 48 | - if($backend->Logon(Request::GetAuthUser(), Request::GetAuthDomain(), Request::GetAuthPassword()) == false) |
|
| 49 | - throw new AuthenticationRequiredException("Access denied. Username or password incorrect"); |
|
| 49 | + if($backend->Logon(Request::GetAuthUser(), Request::GetAuthDomain(), Request::GetAuthPassword()) == false) { |
|
| 50 | + throw new AuthenticationRequiredException("Access denied. Username or password incorrect"); |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | // mark this request as "authenticated" |
| 52 | 54 | self::$userIsAuthenticated = true; |
@@ -59,8 +61,9 @@ discard block |
||
| 59 | 61 | * @return boolean |
| 60 | 62 | */ |
| 61 | 63 | static public function isUserAuthenticated() { |
| 62 | - if (!isset(self::$userIsAuthenticated)) |
|
| 63 | - return false; |
|
| 64 | + if (!isset(self::$userIsAuthenticated)) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 64 | 67 | return self::$userIsAuthenticated; |
| 65 | 68 | } |
| 66 | 69 | |
@@ -75,8 +78,9 @@ discard block |
||
| 75 | 78 | self::$deviceManager = ZPush::GetDeviceManager(false); |
| 76 | 79 | self::$topCollector = ZPush::GetTopCollector(); |
| 77 | 80 | |
| 78 | - if (!ZPush::CommandNeedsPlainInput(Request::GetCommandCode())) |
|
| 79 | - self::$decoder = new WBXMLDecoder(Request::GetInputStream()); |
|
| 81 | + if (!ZPush::CommandNeedsPlainInput(Request::GetCommandCode())) { |
|
| 82 | + self::$decoder = new WBXMLDecoder(Request::GetInputStream()); |
|
| 83 | + } |
|
| 80 | 84 | |
| 81 | 85 | self::$encoder = new WBXMLEncoder(Request::GetOutputStream(), Request::GetGETAcceptMultipart()); |
| 82 | 86 | self::$waitTime = 0; |
@@ -96,8 +100,7 @@ discard block |
||
| 96 | 100 | if (!$handler->Handle(Request::GetCommandCode())) { |
| 97 | 101 | throw new WBXMLException(sprintf("Unknown error in %s->Handle()", get_class($handler))); |
| 98 | 102 | } |
| 99 | - } |
|
| 100 | - catch (Exception $ex) { |
|
| 103 | + } catch (Exception $ex) { |
|
| 101 | 104 | // Log 10 KB of the WBXML data |
| 102 | 105 | ZLog::Write(LOGLEVEL_FATAL, "WBXML 10K debug data: " . Request::GetInputAsBase64(10240), false); |
| 103 | 106 | throw $ex; |
@@ -118,8 +121,9 @@ discard block |
||
| 118 | 121 | * @return array |
| 119 | 122 | */ |
| 120 | 123 | static public function GetSpecialHeaders() { |
| 121 | - if (!isset(self::$specialHeaders) || !is_array(self::$specialHeaders)) |
|
| 122 | - return array(); |
|
| 124 | + if (!isset(self::$specialHeaders) || !is_array(self::$specialHeaders)) { |
|
| 125 | + return array(); |
|
| 126 | + } |
|
| 123 | 127 | |
| 124 | 128 | return self::$specialHeaders; |
| 125 | 129 | } |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | ZLog::Write(LOGLEVEL_INFO, "Request->HandleSync(): Sync request aborted, as exporting of folders has not yet completed"); |
| 44 | 44 | self::$topCollector->AnnounceInformation("Aborted due incomplete folder sync", true); |
| 45 | 45 | $status = SYNC_STATUS_FOLDERHIERARCHYCHANGED; |
| 46 | + } else { |
|
| 47 | + ZLog::Write(LOGLEVEL_INFO, "Request->HandleSync(): FolderSync marked as complete"); |
|
| 46 | 48 | } |
| 47 | - else |
|
| 48 | - ZLog::Write(LOGLEVEL_INFO, "Request->HandleSync(): FolderSync marked as complete"); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // Start Synchronize |
@@ -55,8 +55,9 @@ discard block |
||
| 55 | 55 | if(self::$decoder->getElementStartTag(SYNC_VERSION)) { |
| 56 | 56 | $sync_version = self::$decoder->getElementContent(); |
| 57 | 57 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("WBXML sync version: '%s'", $sync_version)); |
| 58 | - if(!self::$decoder->getElementEndTag()) |
|
| 59 | - return false; |
|
| 58 | + if(!self::$decoder->getElementEndTag()) { |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | // Syncing specified folders |
@@ -87,8 +88,9 @@ discard block |
||
| 87 | 88 | $class = self::$decoder->getElementContent(); |
| 88 | 89 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Sync folder: '%s'", $class)); |
| 89 | 90 | |
| 90 | - if(!self::$decoder->getElementEndTag()) |
|
| 91 | - return false; |
|
| 91 | + if(!self::$decoder->getElementEndTag()) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 92 | 94 | } |
| 93 | 95 | |
| 94 | 96 | // SyncKey |
@@ -99,16 +101,17 @@ discard block |
||
| 99 | 101 | return false; |
| 100 | 102 | } |
| 101 | 103 | } |
| 104 | + } else { |
|
| 105 | + return false; |
|
| 102 | 106 | } |
| 103 | - else |
|
| 104 | - return false; |
|
| 105 | 107 | |
| 106 | 108 | // FolderId |
| 107 | 109 | if(self::$decoder->getElementStartTag(SYNC_FOLDERID)) { |
| 108 | 110 | $folderid = self::$decoder->getElementContent(); |
| 109 | 111 | |
| 110 | - if(!self::$decoder->getElementEndTag()) |
|
| 111 | - return false; |
|
| 112 | + if(!self::$decoder->getElementEndTag()) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 112 | 115 | } |
| 113 | 116 | |
| 114 | 117 | // compatibility mode AS 1.0 - get folderid which was sent during GetHierarchy() |
@@ -122,24 +125,23 @@ discard block |
||
| 122 | 125 | |
| 123 | 126 | // TODO remove resync of folders |
| 124 | 127 | // this forces a resync of all states |
| 125 | - if (! $spa instanceof SyncParameters) |
|
| 126 | - throw new StateInvalidException("Saved state are not of type SyncParameters"); |
|
| 128 | + if (! $spa instanceof SyncParameters) { |
|
| 129 | + throw new StateInvalidException("Saved state are not of type SyncParameters"); |
|
| 130 | + } |
|
| 127 | 131 | |
| 128 | 132 | // new/resync requested |
| 129 | 133 | if ($synckey == "0") { |
| 130 | 134 | $spa->RemoveSyncKey(); |
| 131 | 135 | $spa->DelFolderStat(); |
| 132 | 136 | $spa->SetMoveState(false); |
| 133 | - } |
|
| 134 | - else if ($synckey !== false) { |
|
| 137 | + } else if ($synckey !== false) { |
|
| 135 | 138 | if ($synckey !== $spa->GetSyncKey() && $synckey !== $spa->GetNewSyncKey()) { |
| 136 | 139 | ZLog::Write(LOGLEVEL_DEBUG, "HandleSync(): Synckey does not match latest saved for this folder or there is a move state, removing folderstat to force Exporter setup"); |
| 137 | 140 | $spa->DelFolderStat(); |
| 138 | 141 | } |
| 139 | 142 | $spa->SetSyncKey($synckey); |
| 140 | 143 | } |
| 141 | - } |
|
| 142 | - catch (StateInvalidException $stie) { |
|
| 144 | + } catch (StateInvalidException $stie) { |
|
| 143 | 145 | $spa = new SyncParameters(); |
| 144 | 146 | $status = SYNC_STATUS_INVALIDSYNCKEY; |
| 145 | 147 | self::$topCollector->AnnounceInformation("State invalid - Resync folder", $this->singleFolder); |
@@ -151,16 +153,16 @@ discard block |
||
| 151 | 153 | $spa->SetFolderId($folderid); |
| 152 | 154 | $spa->SetBackendFolderId(self::$deviceManager->GetBackendIdForFolderId($folderid)); |
| 153 | 155 | |
| 154 | - if ($class !== false) |
|
| 155 | - $spa->SetContentClass($class); |
|
| 156 | + if ($class !== false) { |
|
| 157 | + $spa->SetContentClass($class); |
|
| 158 | + } |
|
| 156 | 159 | |
| 157 | 160 | // Get class for as versions >= 12.0 |
| 158 | 161 | if (! $spa->HasContentClass()) { |
| 159 | 162 | try { |
| 160 | 163 | $spa->SetContentClass(self::$deviceManager->GetFolderClassFromCacheByID($spa->GetFolderId())); |
| 161 | 164 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("GetFolderClassFromCacheByID from Device Manager: '%s' for id:'%s'", $spa->GetContentClass(), $spa->GetFolderId())); |
| 162 | - } |
|
| 163 | - catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 165 | + } catch (NoHierarchyCacheAvailableException $nhca) { |
|
| 164 | 166 | $status = SYNC_STATUS_FOLDERHIERARCHYCHANGED; |
| 165 | 167 | self::$deviceManager->ForceFullResync(); |
| 166 | 168 | } |
@@ -170,10 +172,11 @@ discard block |
||
| 170 | 172 | $sc->AddCollection($spa); |
| 171 | 173 | $sc->AddParameter($spa, "requested", true); |
| 172 | 174 | |
| 173 | - if ($spa->HasContentClass()) |
|
| 174 | - self::$topCollector->AnnounceInformation(sprintf("%s request", $spa->GetContentClass()), $this->singleFolder); |
|
| 175 | - else |
|
| 176 | - ZLog::Write(LOGLEVEL_WARN, "Not possible to determine class of request. Request did not contain class and apparently there is an issue with the HierarchyCache."); |
|
| 175 | + if ($spa->HasContentClass()) { |
|
| 176 | + self::$topCollector->AnnounceInformation(sprintf("%s request", $spa->GetContentClass()), $this->singleFolder); |
|
| 177 | + } else { |
|
| 178 | + ZLog::Write(LOGLEVEL_WARN, "Not possible to determine class of request. Request did not contain class and apparently there is an issue with the HierarchyCache."); |
|
| 179 | + } |
|
| 177 | 180 | |
| 178 | 181 | // SUPPORTED properties |
| 179 | 182 | if(($se = self::$decoder->getElementStartTag(SYNC_SUPPORTED)) !== false) { |
@@ -186,10 +189,11 @@ discard block |
||
| 186 | 189 | while(WBXMLDecoder::InWhile("syncSupported")) { |
| 187 | 190 | $el = self::$decoder->getElement(); |
| 188 | 191 | |
| 189 | - if($el[EN_TYPE] == EN_TYPE_ENDTAG) |
|
| 190 | - break; |
|
| 191 | - else |
|
| 192 | - $supfields[] = $el[EN_TAG]; |
|
| 192 | + if($el[EN_TYPE] == EN_TYPE_ENDTAG) { |
|
| 193 | + break; |
|
| 194 | + } else { |
|
| 195 | + $supfields[] = $el[EN_TAG]; |
|
| 196 | + } |
|
| 193 | 197 | } |
| 194 | 198 | self::$deviceManager->SetSupportedFields($spa->GetFolderId(), $supfields); |
| 195 | 199 | } |
@@ -224,16 +228,18 @@ discard block |
||
| 224 | 228 | if(self::$decoder->getElementStartTag(SYNC_WINDOWSIZE)) { |
| 225 | 229 | $ws = self::$decoder->getElementContent(); |
| 226 | 230 | // normalize windowsize - see ZP-477 |
| 227 | - if ($ws == 0 || $ws > WINDOW_SIZE_MAX) |
|
| 228 | - $ws = WINDOW_SIZE_MAX; |
|
| 231 | + if ($ws == 0 || $ws > WINDOW_SIZE_MAX) { |
|
| 232 | + $ws = WINDOW_SIZE_MAX; |
|
| 233 | + } |
|
| 229 | 234 | |
| 230 | 235 | $spa->SetWindowSize($ws); |
| 231 | 236 | |
| 232 | 237 | // also announce the currently requested window size to the DeviceManager |
| 233 | 238 | self::$deviceManager->SetWindowSize($spa->GetFolderId(), $spa->GetWindowSize()); |
| 234 | 239 | |
| 235 | - if(!self::$decoder->getElementEndTag()) |
|
| 236 | - return false; |
|
| 240 | + if(!self::$decoder->getElementEndTag()) { |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 237 | 243 | } |
| 238 | 244 | |
| 239 | 245 | // conversation mode requested |
@@ -241,8 +247,9 @@ discard block |
||
| 241 | 247 | $spa->SetConversationMode(true); |
| 242 | 248 | if(($conversationmode = self::$decoder->getElementContent()) !== false) { |
| 243 | 249 | $spa->SetConversationMode((bool)$conversationmode); |
| 244 | - if(!self::$decoder->getElementEndTag()) |
|
| 245 | - return false; |
|
| 250 | + if(!self::$decoder->getElementEndTag()) { |
|
| 251 | + return false; |
|
| 252 | + } |
|
| 246 | 253 | } |
| 247 | 254 | } |
| 248 | 255 | |
@@ -273,8 +280,9 @@ discard block |
||
| 273 | 280 | // set to synchronize all changes. The mobile could overwrite this value |
| 274 | 281 | $spa->SetFilterType(SYNC_FILTERTYPE_ALL); |
| 275 | 282 | |
| 276 | - if(!self::$decoder->getElementEndTag()) |
|
| 277 | - return false; |
|
| 283 | + if(!self::$decoder->getElementEndTag()) { |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 278 | 286 | } |
| 279 | 287 | // if no foldertype is defined, use default cpo |
| 280 | 288 | else if ($firstOption){ |
@@ -288,36 +296,42 @@ discard block |
||
| 288 | 296 | |
| 289 | 297 | if(self::$decoder->getElementStartTag(SYNC_FILTERTYPE)) { |
| 290 | 298 | $spa->SetFilterType(self::$decoder->getElementContent()); |
| 291 | - if(!self::$decoder->getElementEndTag()) |
|
| 292 | - return false; |
|
| 299 | + if(!self::$decoder->getElementEndTag()) { |
|
| 300 | + return false; |
|
| 301 | + } |
|
| 293 | 302 | } |
| 294 | 303 | if(self::$decoder->getElementStartTag(SYNC_TRUNCATION)) { |
| 295 | 304 | $spa->SetTruncation(self::$decoder->getElementContent()); |
| 296 | - if(!self::$decoder->getElementEndTag()) |
|
| 297 | - return false; |
|
| 305 | + if(!self::$decoder->getElementEndTag()) { |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 298 | 308 | } |
| 299 | 309 | if(self::$decoder->getElementStartTag(SYNC_RTFTRUNCATION)) { |
| 300 | 310 | $spa->SetRTFTruncation(self::$decoder->getElementContent()); |
| 301 | - if(!self::$decoder->getElementEndTag()) |
|
| 302 | - return false; |
|
| 311 | + if(!self::$decoder->getElementEndTag()) { |
|
| 312 | + return false; |
|
| 313 | + } |
|
| 303 | 314 | } |
| 304 | 315 | |
| 305 | 316 | if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) { |
| 306 | 317 | $spa->SetMimeSupport(self::$decoder->getElementContent()); |
| 307 | - if(!self::$decoder->getElementEndTag()) |
|
| 308 | - return false; |
|
| 318 | + if(!self::$decoder->getElementEndTag()) { |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 309 | 321 | } |
| 310 | 322 | |
| 311 | 323 | if(self::$decoder->getElementStartTag(SYNC_MIMETRUNCATION)) { |
| 312 | 324 | $spa->SetMimeTruncation(self::$decoder->getElementContent()); |
| 313 | - if(!self::$decoder->getElementEndTag()) |
|
| 314 | - return false; |
|
| 325 | + if(!self::$decoder->getElementEndTag()) { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 315 | 328 | } |
| 316 | 329 | |
| 317 | 330 | if(self::$decoder->getElementStartTag(SYNC_CONFLICT)) { |
| 318 | 331 | $spa->SetConflict(self::$decoder->getElementContent()); |
| 319 | - if(!self::$decoder->getElementEndTag()) |
|
| 320 | - return false; |
|
| 332 | + if(!self::$decoder->getElementEndTag()) { |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 321 | 335 | } |
| 322 | 336 | |
| 323 | 337 | while (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPREFERENCE)) { |
@@ -331,24 +345,28 @@ discard block |
||
| 331 | 345 | |
| 332 | 346 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) { |
| 333 | 347 | $spa->BodyPreference($bptype)->SetTruncationSize(self::$decoder->getElementContent()); |
| 334 | - if(!self::$decoder->getElementEndTag()) |
|
| 335 | - return false; |
|
| 348 | + if(!self::$decoder->getElementEndTag()) { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 336 | 351 | } |
| 337 | 352 | |
| 338 | 353 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) { |
| 339 | 354 | $spa->BodyPreference($bptype)->SetAllOrNone(self::$decoder->getElementContent()); |
| 340 | - if(!self::$decoder->getElementEndTag()) |
|
| 341 | - return false; |
|
| 355 | + if(!self::$decoder->getElementEndTag()) { |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 342 | 358 | } |
| 343 | 359 | |
| 344 | 360 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) { |
| 345 | 361 | $spa->BodyPreference($bptype)->SetPreview(self::$decoder->getElementContent()); |
| 346 | - if(!self::$decoder->getElementEndTag()) |
|
| 347 | - return false; |
|
| 362 | + if(!self::$decoder->getElementEndTag()) { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 348 | 365 | } |
| 349 | 366 | |
| 350 | - if(!self::$decoder->getElementEndTag()) |
|
| 351 | - return false; |
|
| 367 | + if(!self::$decoder->getElementEndTag()) { |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 352 | 370 | } |
| 353 | 371 | |
| 354 | 372 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPARTPREFERENCE)) { |
@@ -362,30 +380,35 @@ discard block |
||
| 362 | 380 | |
| 363 | 381 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) { |
| 364 | 382 | $spa->BodyPartPreference($bpptype)->SetTruncationSize(self::$decoder->getElementContent()); |
| 365 | - if(!self::$decoder->getElementEndTag()) |
|
| 366 | - return false; |
|
| 383 | + if(!self::$decoder->getElementEndTag()) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 367 | 386 | } |
| 368 | 387 | |
| 369 | 388 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) { |
| 370 | 389 | $spa->BodyPartPreference($bpptype)->SetAllOrNone(self::$decoder->getElementContent()); |
| 371 | - if(!self::$decoder->getElementEndTag()) |
|
| 372 | - return false; |
|
| 390 | + if(!self::$decoder->getElementEndTag()) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 373 | 393 | } |
| 374 | 394 | |
| 375 | 395 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) { |
| 376 | 396 | $spa->BodyPartPreference($bpptype)->SetPreview(self::$decoder->getElementContent()); |
| 377 | - if(!self::$decoder->getElementEndTag()) |
|
| 378 | - return false; |
|
| 397 | + if(!self::$decoder->getElementEndTag()) { |
|
| 398 | + return false; |
|
| 399 | + } |
|
| 379 | 400 | } |
| 380 | 401 | |
| 381 | - if (!self::$decoder->getElementEndTag()) |
|
| 382 | - return false; |
|
| 402 | + if (!self::$decoder->getElementEndTag()) { |
|
| 403 | + return false; |
|
| 404 | + } |
|
| 383 | 405 | } |
| 384 | 406 | |
| 385 | 407 | if (self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) { |
| 386 | 408 | $spa->SetRmSupport(self::$decoder->getElementContent()); |
| 387 | - if (!self::$decoder->getElementEndTag()) |
|
| 388 | - return false; |
|
| 409 | + if (!self::$decoder->getElementEndTag()) { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 389 | 412 | } |
| 390 | 413 | |
| 391 | 414 | $e = self::$decoder->peek(); |
@@ -439,19 +462,21 @@ discard block |
||
| 439 | 462 | break; |
| 440 | 463 | } |
| 441 | 464 | |
| 442 | - if ($status == SYNC_STATUS_SUCCESS) |
|
| 443 | - $nchanges++; |
|
| 465 | + if ($status == SYNC_STATUS_SUCCESS) { |
|
| 466 | + $nchanges++; |
|
| 467 | + } |
|
| 444 | 468 | |
| 445 | 469 | // Foldertype sent when syncing SMS |
| 446 | 470 | if(self::$decoder->getElementStartTag(SYNC_FOLDERTYPE)) { |
| 447 | 471 | $foldertype = self::$decoder->getElementContent(); |
| 448 | 472 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): incoming data with foldertype '%s'", $foldertype)); |
| 449 | 473 | |
| 450 | - if(!self::$decoder->getElementEndTag()) |
|
| 451 | - return false; |
|
| 474 | + if(!self::$decoder->getElementEndTag()) { |
|
| 475 | + return false; |
|
| 476 | + } |
|
| 477 | + } else { |
|
| 478 | + $foldertype = false; |
|
| 452 | 479 | } |
| 453 | - else |
|
| 454 | - $foldertype = false; |
|
| 455 | 480 | |
| 456 | 481 | $serverid = false; |
| 457 | 482 | if(self::$decoder->getElementStartTag(SYNC_SERVERENTRYID)) { |
@@ -465,11 +490,13 @@ discard block |
||
| 465 | 490 | if(self::$decoder->getElementStartTag(SYNC_CLIENTENTRYID)) { |
| 466 | 491 | $clientid = self::$decoder->getElementContent(); |
| 467 | 492 | |
| 468 | - if(!self::$decoder->getElementEndTag()) // end clientid |
|
| 493 | + if(!self::$decoder->getElementEndTag()) { |
|
| 494 | + // end clientid |
|
| 469 | 495 | return false; |
| 496 | + } |
|
| 497 | + } else { |
|
| 498 | + $clientid = false; |
|
| 470 | 499 | } |
| 471 | - else |
|
| 472 | - $clientid = false; |
|
| 473 | 500 | |
| 474 | 501 | // Get the SyncMessage if sent |
| 475 | 502 | if(($el = self::$decoder->getElementStartTag(SYNC_DATA)) && ($el[EN_FLAGS] & EN_FLAGS_CONTENT)) { |
@@ -479,11 +506,13 @@ discard block |
||
| 479 | 506 | // set Ghosted fields |
| 480 | 507 | $message->emptySupported(self::$deviceManager->GetSupportedFields($spa->GetFolderId())); |
| 481 | 508 | |
| 482 | - if(!self::$decoder->getElementEndTag()) // end applicationdata |
|
| 509 | + if(!self::$decoder->getElementEndTag()) { |
|
| 510 | + // end applicationdata |
|
| 483 | 511 | return false; |
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $message = false; |
|
| 484 | 515 | } |
| 485 | - else |
|
| 486 | - $message = false; |
|
| 487 | 516 | |
| 488 | 517 | switch($element[EN_TAG]) { |
| 489 | 518 | case SYNC_FETCH: |
@@ -491,24 +520,29 @@ discard block |
||
| 491 | 520 | break; |
| 492 | 521 | default: |
| 493 | 522 | // get the importer |
| 494 | - if ($this->importer == false) |
|
| 495 | - $status = $this->getImporter($sc, $spa, $actiondata); |
|
| 523 | + if ($this->importer == false) { |
|
| 524 | + $status = $this->getImporter($sc, $spa, $actiondata); |
|
| 525 | + } |
|
| 496 | 526 | |
| 497 | - if ($status == SYNC_STATUS_SUCCESS) |
|
| 498 | - $this->importMessage($spa, $actiondata, $element[EN_TAG], $message, $clientid, $serverid, $foldertype, $nchanges); |
|
| 499 | - else |
|
| 500 | - ZLog::Write(LOGLEVEL_WARN, "Ignored incoming change, global status indicates problem."); |
|
| 527 | + if ($status == SYNC_STATUS_SUCCESS) { |
|
| 528 | + $this->importMessage($spa, $actiondata, $element[EN_TAG], $message, $clientid, $serverid, $foldertype, $nchanges); |
|
| 529 | + } else { |
|
| 530 | + ZLog::Write(LOGLEVEL_WARN, "Ignored incoming change, global status indicates problem."); |
|
| 531 | + } |
|
| 501 | 532 | |
| 502 | 533 | break; |
| 503 | 534 | } |
| 504 | 535 | |
| 505 | - if ($actiondata["fetchids"]) |
|
| 506 | - self::$topCollector->AnnounceInformation(sprintf("Fetching %d", $nchanges)); |
|
| 507 | - else |
|
| 508 | - self::$topCollector->AnnounceInformation(sprintf("Incoming %d", $nchanges)); |
|
| 536 | + if ($actiondata["fetchids"]) { |
|
| 537 | + self::$topCollector->AnnounceInformation(sprintf("Fetching %d", $nchanges)); |
|
| 538 | + } else { |
|
| 539 | + self::$topCollector->AnnounceInformation(sprintf("Incoming %d", $nchanges)); |
|
| 540 | + } |
|
| 509 | 541 | |
| 510 | - if(!self::$decoder->getElementEndTag()) // end add/change/delete/move |
|
| 542 | + if(!self::$decoder->getElementEndTag()) { |
|
| 543 | + // end add/change/delete/move |
|
| 511 | 544 | return false; |
| 545 | + } |
|
| 512 | 546 | } |
| 513 | 547 | |
| 514 | 548 | if ($status == SYNC_STATUS_SUCCESS && $this->importer !== false) { |
@@ -521,14 +555,15 @@ discard block |
||
| 521 | 555 | try { |
| 522 | 556 | // Save the updated state, which is used for the exporter later |
| 523 | 557 | $sc->AddParameter($spa, "state", $this->importer->GetState()); |
| 524 | - } |
|
| 525 | - catch (StatusException $stex) { |
|
| 558 | + } catch (StatusException $stex) { |
|
| 526 | 559 | $status = $stex->getCode(); |
| 527 | 560 | } |
| 528 | 561 | } |
| 529 | 562 | |
| 530 | - if(!self::$decoder->getElementEndTag()) // end PERFORM |
|
| 563 | + if(!self::$decoder->getElementEndTag()) { |
|
| 564 | + // end PERFORM |
|
| 531 | 565 | return false; |
| 566 | + } |
|
| 532 | 567 | } |
| 533 | 568 | |
| 534 | 569 | // save the failsave state |
@@ -541,28 +576,37 @@ discard block |
||
| 541 | 576 | // save actiondata |
| 542 | 577 | $sc->AddParameter($spa, "actiondata", $actiondata); |
| 543 | 578 | |
| 544 | - if(!self::$decoder->getElementEndTag()) // end collection |
|
| 579 | + if(!self::$decoder->getElementEndTag()) { |
|
| 580 | + // end collection |
|
| 545 | 581 | return false; |
| 582 | + } |
|
| 546 | 583 | |
| 547 | 584 | // AS14 does not send GetChanges anymore. We should do it if there were no incoming changes |
| 548 | - if (!isset($performaction) && !$sc->GetParameter($spa, "getchanges") && $spa->HasSyncKey()) |
|
| 549 | - $sc->AddParameter($spa, "getchanges", true); |
|
| 585 | + if (!isset($performaction) && !$sc->GetParameter($spa, "getchanges") && $spa->HasSyncKey()) { |
|
| 586 | + $sc->AddParameter($spa, "getchanges", true); |
|
| 587 | + } |
|
| 550 | 588 | } // END FOLDER |
| 551 | 589 | |
| 552 | - if(!$wbxmlproblem && !self::$decoder->getElementEndTag()) // end collections |
|
| 590 | + if(!$wbxmlproblem && !self::$decoder->getElementEndTag()) { |
|
| 591 | + // end collections |
|
| 553 | 592 | return false; |
| 593 | + } |
|
| 554 | 594 | } // end FOLDERS |
| 555 | 595 | |
| 556 | 596 | if (self::$decoder->getElementStartTag(SYNC_HEARTBEATINTERVAL)) { |
| 557 | 597 | $hbinterval = self::$decoder->getElementContent(); |
| 558 | - if(!self::$decoder->getElementEndTag()) // SYNC_HEARTBEATINTERVAL |
|
| 598 | + if(!self::$decoder->getElementEndTag()) { |
|
| 599 | + // SYNC_HEARTBEATINTERVAL |
|
| 559 | 600 | return false; |
| 601 | + } |
|
| 560 | 602 | } |
| 561 | 603 | |
| 562 | 604 | if (self::$decoder->getElementStartTag(SYNC_WAIT)) { |
| 563 | 605 | $wait = self::$decoder->getElementContent(); |
| 564 | - if(!self::$decoder->getElementEndTag()) // SYNC_WAIT |
|
| 606 | + if(!self::$decoder->getElementEndTag()) { |
|
| 607 | + // SYNC_WAIT |
|
| 565 | 608 | return false; |
| 609 | + } |
|
| 566 | 610 | |
| 567 | 611 | // internally the heartbeat interval and the wait time are the same |
| 568 | 612 | // heartbeat is in seconds, wait in minutes |
@@ -572,17 +616,22 @@ discard block |
||
| 572 | 616 | if (self::$decoder->getElementStartTag(SYNC_WINDOWSIZE)) { |
| 573 | 617 | $sc->SetGlobalWindowSize(self::$decoder->getElementContent()); |
| 574 | 618 | ZLog::Write(LOGLEVEL_DEBUG, "Sync(): Global WindowSize requested: ". $sc->GetGlobalWindowSize()); |
| 575 | - if(!self::$decoder->getElementEndTag()) // SYNC_WINDOWSIZE |
|
| 619 | + if(!self::$decoder->getElementEndTag()) { |
|
| 620 | + // SYNC_WINDOWSIZE |
|
| 576 | 621 | return false; |
| 622 | + } |
|
| 577 | 623 | } |
| 578 | 624 | |
| 579 | - if(self::$decoder->getElementStartTag(SYNC_PARTIAL)) |
|
| 580 | - $partial = true; |
|
| 581 | - else |
|
| 582 | - $partial = false; |
|
| 625 | + if(self::$decoder->getElementStartTag(SYNC_PARTIAL)) { |
|
| 626 | + $partial = true; |
|
| 627 | + } else { |
|
| 628 | + $partial = false; |
|
| 629 | + } |
|
| 583 | 630 | |
| 584 | - if(!$wbxmlproblem && !self::$decoder->getElementEndTag()) // end sync |
|
| 631 | + if(!$wbxmlproblem && !self::$decoder->getElementEndTag()) { |
|
| 632 | + // end sync |
|
| 585 | 633 | return false; |
| 634 | + } |
|
| 586 | 635 | } |
| 587 | 636 | // we did not receive a SYNCHRONIZE block - assume empty sync |
| 588 | 637 | else { |
@@ -605,13 +654,11 @@ discard block |
||
| 605 | 654 | // Load all collections - do not overwrite existing (received!), load states, check permissions and only load confirmed states! |
| 606 | 655 | try { |
| 607 | 656 | $sc->LoadAllCollections(false, true, true, true, true); |
| 608 | - } |
|
| 609 | - catch (StateInvalidException $siex) { |
|
| 657 | + } catch (StateInvalidException $siex) { |
|
| 610 | 658 | $status = SYNC_STATUS_INVALIDSYNCKEY; |
| 611 | 659 | self::$topCollector->AnnounceInformation("StateNotFoundException", $this->singleFolder); |
| 612 | 660 | $this->saveMultiFolderInfo("exception", "StateNotFoundException"); |
| 613 | - } |
|
| 614 | - catch (StatusException $stex) { |
|
| 661 | + } catch (StatusException $stex) { |
|
| 615 | 662 | $status = SYNC_STATUS_FOLDERHIERARCHYCHANGED; |
| 616 | 663 | self::$topCollector->AnnounceInformation(sprintf("StatusException code: %d", $status), $this->singleFolder); |
| 617 | 664 | $this->saveMultiFolderInfo("exception", "StatusException"); |
@@ -631,10 +678,10 @@ discard block |
||
| 631 | 678 | self::$deviceManager->SetWindowSize($folderid, $spa->GetWindowSize()); |
| 632 | 679 | } |
| 633 | 680 | } |
| 634 | - if (!$sc->HasCollections()) |
|
| 635 | - $status = SYNC_STATUS_SYNCREQUESTINCOMPLETE; |
|
| 636 | - } |
|
| 637 | - else if (isset($hbinterval)) { |
|
| 681 | + if (!$sc->HasCollections()) { |
|
| 682 | + $status = SYNC_STATUS_SYNCREQUESTINCOMPLETE; |
|
| 683 | + } |
|
| 684 | + } else if (isset($hbinterval)) { |
|
| 638 | 685 | // load the hierarchy data - there are no permissions to verify so we just set it to false |
| 639 | 686 | if (!$sc->LoadCollection(false, true, false)) { |
| 640 | 687 | $status = SYNC_STATUS_FOLDERHIERARCHYCHANGED; |
@@ -647,8 +694,9 @@ discard block |
||
| 647 | 694 | if ($status == SYNC_STATUS_SUCCESS && isset($hbinterval)) { |
| 648 | 695 | $interval = (defined('PING_INTERVAL') && PING_INTERVAL > 0) ? PING_INTERVAL : 30; |
| 649 | 696 | |
| 650 | - if (isset($hbinterval)) |
|
| 651 | - $sc->SetLifetime($hbinterval); |
|
| 697 | + if (isset($hbinterval)) { |
|
| 698 | + $sc->SetLifetime($hbinterval); |
|
| 699 | + } |
|
| 652 | 700 | |
| 653 | 701 | // states are lazy loaded - we have to make sure that they are there! |
| 654 | 702 | $loadstatus = SYNC_STATUS_SUCCESS; |
@@ -663,8 +711,9 @@ discard block |
||
| 663 | 711 | $fad = array(); |
| 664 | 712 | // if loading the states fails, we do not enter heartbeat, but we keep $status on SYNC_STATUS_SUCCESS |
| 665 | 713 | // so when the changes are exported the correct folder gets an SYNC_STATUS_INVALIDSYNCKEY |
| 666 | - if ($loadstatus == SYNC_STATUS_SUCCESS) |
|
| 667 | - $loadstatus = $this->loadStates($sc, $spa, $fad); |
|
| 714 | + if ($loadstatus == SYNC_STATUS_SUCCESS) { |
|
| 715 | + $loadstatus = $this->loadStates($sc, $spa, $fad); |
|
| 716 | + } |
|
| 668 | 717 | } |
| 669 | 718 | |
| 670 | 719 | if ($loadstatus == SYNC_STATUS_SUCCESS) { |
@@ -674,12 +723,10 @@ discard block |
||
| 674 | 723 | // always check for changes |
| 675 | 724 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): Entering Heartbeat mode")); |
| 676 | 725 | $foundchanges = $sc->CheckForChanges($sc->GetLifetime(), $interval); |
| 677 | - } |
|
| 678 | - catch (StatusException $stex) { |
|
| 726 | + } catch (StatusException $stex) { |
|
| 679 | 727 | if ($stex->getCode() == SyncCollections::OBSOLETE_CONNECTION) { |
| 680 | 728 | $status = SYNC_COMMONSTATUS_SYNCSTATEVERSIONINVALID; |
| 681 | - } |
|
| 682 | - else { |
|
| 729 | + } else { |
|
| 683 | 730 | $status = SYNC_STATUS_FOLDERHIERARCHYCHANGED; |
| 684 | 731 | self::$topCollector->AnnounceInformation(sprintf("StatusException code: %d", $status), $this->singleFolder); |
| 685 | 732 | $this->saveMultiFolderInfo("exception", "StatusException"); |
@@ -696,8 +743,7 @@ discard block |
||
| 696 | 743 | foreach($sc as $folderid => $spa) { |
| 697 | 744 | if (self::$deviceManager->CheckHearbeatStateIntegrity($spa->GetFolderId(), $spa->GetUuid(), $spa->GetUuidCounter())) { |
| 698 | 745 | $status = SYNC_COMMONSTATUS_SYNCSTATEVERSIONINVALID; |
| 699 | - } |
|
| 700 | - else { |
|
| 746 | + } else { |
|
| 701 | 747 | $sc->SaveCollection($spa); |
| 702 | 748 | } |
| 703 | 749 | } |
@@ -717,9 +763,9 @@ discard block |
||
| 717 | 763 | if ($changecount > 0 && $sc->WaitedForChanges() && self::$deviceManager->CheckHearbeatStateIntegrity($spa->GetFolderId(), $spa->GetUuid(), $spa->GetUuidCounter())) { |
| 718 | 764 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): heartbeat: found %d changes in '%s' which was already synchronized. Heartbeat aborted!", $changecount, $folderid)); |
| 719 | 765 | $status = SYNC_COMMONSTATUS_SYNCSTATEVERSIONINVALID; |
| 766 | + } else { |
|
| 767 | + ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): heartbeat: found %d changes in '%s'", $changecount, $folderid)); |
|
| 720 | 768 | } |
| 721 | - else |
|
| 722 | - ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): heartbeat: found %d changes in '%s'", $changecount, $folderid)); |
|
| 723 | 769 | } |
| 724 | 770 | } |
| 725 | 771 | } |
@@ -806,16 +852,17 @@ discard block |
||
| 806 | 852 | if($status == SYNC_STATUS_SUCCESS) { |
| 807 | 853 | try { |
| 808 | 854 | // if this is an additional folder the backend has to be setup correctly |
| 809 | - if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) |
|
| 810 | - throw new StatusException(sprintf("HandleSync() could not Setup() the backend for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 855 | + if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) { |
|
| 856 | + throw new StatusException(sprintf("HandleSync() could not Setup() the backend for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 857 | + } |
|
| 811 | 858 | |
| 812 | 859 | // Use the state from the importer, as changes may have already happened |
| 813 | 860 | $exporter = self::$backend->GetExporter($spa->GetBackendFolderId()); |
| 814 | 861 | |
| 815 | - if ($exporter === false) |
|
| 816 | - throw new StatusException(sprintf("HandleSync() could not get an exporter for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 817 | - } |
|
| 818 | - catch (StatusException $stex) { |
|
| 862 | + if ($exporter === false) { |
|
| 863 | + throw new StatusException(sprintf("HandleSync() could not get an exporter for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 864 | + } |
|
| 865 | + } catch (StatusException $stex) { |
|
| 819 | 866 | $status = $stex->getCode(); |
| 820 | 867 | } |
| 821 | 868 | try { |
@@ -829,12 +876,12 @@ discard block |
||
| 829 | 876 | |
| 830 | 877 | $changecount = $exporter->GetChangeCount(); |
| 831 | 878 | } |
| 832 | - } |
|
| 833 | - catch (StatusException $stex) { |
|
| 834 | - if ($stex->getCode() === SYNC_FSSTATUS_CODEUNKNOWN && $spa->HasSyncKey()) |
|
| 835 | - $status = SYNC_STATUS_INVALIDSYNCKEY; |
|
| 836 | - else |
|
| 837 | - $status = $stex->getCode(); |
|
| 879 | + } catch (StatusException $stex) { |
|
| 880 | + if ($stex->getCode() === SYNC_FSSTATUS_CODEUNKNOWN && $spa->HasSyncKey()) { |
|
| 881 | + $status = SYNC_STATUS_INVALIDSYNCKEY; |
|
| 882 | + } else { |
|
| 883 | + $status = $stex->getCode(); |
|
| 884 | + } |
|
| 838 | 885 | } |
| 839 | 886 | |
| 840 | 887 | if (! $spa->HasSyncKey()) { |
@@ -846,8 +893,7 @@ discard block |
||
| 846 | 893 | if ($changecount > 0) { |
| 847 | 894 | self::$deviceManager->SetFolderSyncStatus($folderid, DeviceManager::FLD_SYNC_INITIALIZED); |
| 848 | 895 | } |
| 849 | - } |
|
| 850 | - else if ($status != SYNC_STATUS_SUCCESS) { |
|
| 896 | + } else if ($status != SYNC_STATUS_SUCCESS) { |
|
| 851 | 897 | self::$topCollector->AnnounceInformation(sprintf("StatusException code: %d", $status), $this->singleFolder); |
| 852 | 898 | $this->saveMultiFolderInfo("exception", "StatusException"); |
| 853 | 899 | } |
@@ -902,8 +948,9 @@ discard block |
||
| 902 | 948 | } // END foreach collection |
| 903 | 949 | |
| 904 | 950 | //SYNC_FOLDERS - only if the starttag was sent |
| 905 | - if ($this->startFolderTagSent) |
|
| 906 | - self::$encoder->endTag(); |
|
| 951 | + if ($this->startFolderTagSent) { |
|
| 952 | + self::$encoder->endTag(); |
|
| 953 | + } |
|
| 907 | 954 | |
| 908 | 955 | // Check if there was any response - in case of an empty sync request, we shouldn't send an empty answer (ZP-1241) |
| 909 | 956 | if (!$this->startTagsSent && $emptysync === true) { |
@@ -914,8 +961,9 @@ discard block |
||
| 914 | 961 | } |
| 915 | 962 | |
| 916 | 963 | //SYNC_SYNCHRONIZE - only if the starttag was sent |
| 917 | - if ($this->startTagsSent) |
|
| 918 | - self::$encoder->endTag(); |
|
| 964 | + if ($this->startTagsSent) { |
|
| 965 | + self::$encoder->endTag(); |
|
| 966 | + } |
|
| 919 | 967 | |
| 920 | 968 | // final top announcement for a multi-folder sync |
| 921 | 969 | if ($sc->GetCollectionCount() > 1) { |
@@ -989,10 +1037,11 @@ discard block |
||
| 989 | 1037 | } |
| 990 | 1038 | |
| 991 | 1039 | self::$encoder->startTag(SYNC_SYNCKEY); |
| 992 | - if($status == SYNC_STATUS_SUCCESS && $spa->HasNewSyncKey()) |
|
| 993 | - self::$encoder->content($spa->GetNewSyncKey()); |
|
| 994 | - else |
|
| 995 | - self::$encoder->content($spa->GetSyncKey()); |
|
| 1040 | + if($status == SYNC_STATUS_SUCCESS && $spa->HasNewSyncKey()) { |
|
| 1041 | + self::$encoder->content($spa->GetNewSyncKey()); |
|
| 1042 | + } else { |
|
| 1043 | + self::$encoder->content($spa->GetSyncKey()); |
|
| 1044 | + } |
|
| 996 | 1045 | self::$encoder->endTag(); |
| 997 | 1046 | |
| 998 | 1047 | self::$encoder->startTag(SYNC_FOLDERID); |
@@ -1004,8 +1053,9 @@ discard block |
||
| 1004 | 1053 | self::$encoder->endTag(); |
| 1005 | 1054 | |
| 1006 | 1055 | // announce failing status to the process loop detection |
| 1007 | - if ($status !== SYNC_STATUS_SUCCESS) |
|
| 1008 | - self::$deviceManager->AnnounceProcessStatus($spa->GetFolderId(), $status); |
|
| 1056 | + if ($status !== SYNC_STATUS_SUCCESS) { |
|
| 1057 | + self::$deviceManager->AnnounceProcessStatus($spa->GetFolderId(), $status); |
|
| 1058 | + } |
|
| 1009 | 1059 | |
| 1010 | 1060 | // Output IDs and status for incoming items & requests |
| 1011 | 1061 | if($status == SYNC_STATUS_SUCCESS && ( |
@@ -1071,8 +1121,9 @@ discard block |
||
| 1071 | 1121 | $fetchstatus = SYNC_STATUS_SUCCESS; |
| 1072 | 1122 | |
| 1073 | 1123 | // if this is an additional folder the backend has to be setup correctly |
| 1074 | - if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) |
|
| 1075 | - throw new StatusException(sprintf("HandleSync(): could not Setup() the backend to fetch in folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 1124 | + if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) { |
|
| 1125 | + throw new StatusException(sprintf("HandleSync(): could not Setup() the backend to fetch in folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 1126 | + } |
|
| 1076 | 1127 | |
| 1077 | 1128 | $data = self::$backend->Fetch($spa->GetBackendFolderId(), $id, $spa->GetCPO()); |
| 1078 | 1129 | |
@@ -1081,8 +1132,7 @@ discard block |
||
| 1081 | 1132 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): message not to be streamed as requested by DeviceManager, id = %s", $id)); |
| 1082 | 1133 | $fetchstatus = SYNC_STATUS_CLIENTSERVERCONVERSATIONERROR; |
| 1083 | 1134 | } |
| 1084 | - } |
|
| 1085 | - catch (StatusException $stex) { |
|
| 1135 | + } catch (StatusException $stex) { |
|
| 1086 | 1136 | $fetchstatus = $stex->getCode(); |
| 1087 | 1137 | } |
| 1088 | 1138 | |
@@ -1099,9 +1149,9 @@ discard block |
||
| 1099 | 1149 | self::$encoder->startTag(SYNC_DATA); |
| 1100 | 1150 | $data->Encode(self::$encoder); |
| 1101 | 1151 | self::$encoder->endTag(); |
| 1152 | + } else { |
|
| 1153 | + ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to Fetch '%s'", $id)); |
|
| 1102 | 1154 | } |
| 1103 | - else |
|
| 1104 | - ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to Fetch '%s'", $id)); |
|
| 1105 | 1155 | self::$encoder->endTag(); |
| 1106 | 1156 | |
| 1107 | 1157 | } |
@@ -1139,18 +1189,18 @@ discard block |
||
| 1139 | 1189 | while(WBXMLDecoder::InWhile("syncSynchronize")) { |
| 1140 | 1190 | try { |
| 1141 | 1191 | $progress = $exporter->Synchronize(); |
| 1142 | - if(!is_array($progress)) |
|
| 1143 | - break; |
|
| 1192 | + if(!is_array($progress)) { |
|
| 1193 | + break; |
|
| 1194 | + } |
|
| 1144 | 1195 | $n++; |
| 1145 | - if ($n % 10 == 0) |
|
| 1146 | - self::$topCollector->AnnounceInformation(sprintf("Streamed data of %d objects out of %d", $n, (($changecount > $windowSize)?$windowSize:$changecount))); |
|
| 1147 | - } |
|
| 1148 | - catch (SyncObjectBrokenException $mbe) { |
|
| 1196 | + if ($n % 10 == 0) { |
|
| 1197 | + self::$topCollector->AnnounceInformation(sprintf("Streamed data of %d objects out of %d", $n, (($changecount > $windowSize)?$windowSize:$changecount))); |
|
| 1198 | + } |
|
| 1199 | + } catch (SyncObjectBrokenException $mbe) { |
|
| 1149 | 1200 | $brokenSO = $mbe->GetSyncObject(); |
| 1150 | 1201 | if (!$brokenSO) { |
| 1151 | 1202 | ZLog::Write(LOGLEVEL_ERROR, sprintf("HandleSync(): Caught SyncObjectBrokenException but broken SyncObject not available. This should be fixed in the backend.")); |
| 1152 | - } |
|
| 1153 | - else { |
|
| 1203 | + } else { |
|
| 1154 | 1204 | if (!isset($brokenSO->id)) { |
| 1155 | 1205 | $brokenSO->id = "Unknown ID"; |
| 1156 | 1206 | ZLog::Write(LOGLEVEL_ERROR, sprintf("HandleSync(): Caught SyncObjectBrokenException but no ID of object set. This should be fixed in the backend.")); |
@@ -1212,14 +1262,13 @@ discard block |
||
| 1212 | 1262 | $newFolderStatAfterExport = self::$backend->GetFolderStat(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()), $spa->GetBackendFolderId()); |
| 1213 | 1263 | if ($newFolderStat === $newFolderStatAfterExport) { |
| 1214 | 1264 | $this->setFolderStat($spa, $newFolderStat); |
| 1215 | - } |
|
| 1216 | - else { |
|
| 1265 | + } else { |
|
| 1217 | 1266 | ZLog::Write(LOGLEVEL_DEBUG, "Sync() Folderstat differs after export, force another exporter run."); |
| 1218 | 1267 | } |
| 1219 | 1268 | } |
| 1269 | + } else { |
|
| 1270 | + self::$deviceManager->SetFolderSyncStatus($spa->GetFolderId(), DeviceManager::FLD_SYNC_INPROGRESS); |
|
| 1220 | 1271 | } |
| 1221 | - else |
|
| 1222 | - self::$deviceManager->SetFolderSyncStatus($spa->GetFolderId(), DeviceManager::FLD_SYNC_INPROGRESS); |
|
| 1223 | 1272 | } |
| 1224 | 1273 | |
| 1225 | 1274 | self::$encoder->endTag(); |
@@ -1234,27 +1283,30 @@ discard block |
||
| 1234 | 1283 | } |
| 1235 | 1284 | |
| 1236 | 1285 | // nothing exported, but possibly imported - get the importer state |
| 1237 | - else if ($sc->GetParameter($spa, "state") !== null) |
|
| 1238 | - $state = $sc->GetParameter($spa, "state"); |
|
| 1286 | + else if ($sc->GetParameter($spa, "state") !== null) { |
|
| 1287 | + $state = $sc->GetParameter($spa, "state"); |
|
| 1288 | + } |
|
| 1239 | 1289 | |
| 1240 | 1290 | // if a new request without state information (hierarchy) save an empty state |
| 1241 | - else if (! $spa->HasSyncKey()) |
|
| 1242 | - $state = ""; |
|
| 1243 | - } |
|
| 1244 | - catch (StatusException $stex) { |
|
| 1291 | + else if (! $spa->HasSyncKey()) { |
|
| 1292 | + $state = ""; |
|
| 1293 | + } |
|
| 1294 | + } catch (StatusException $stex) { |
|
| 1245 | 1295 | $status = $stex->getCode(); |
| 1246 | 1296 | } |
| 1247 | 1297 | |
| 1248 | 1298 | |
| 1249 | - if (isset($state) && $status == SYNC_STATUS_SUCCESS) |
|
| 1250 | - self::$deviceManager->GetStateManager()->SetSyncState($spa->GetNewSyncKey(), $state, $spa->GetFolderId()); |
|
| 1251 | - else |
|
| 1252 | - ZLog::Write(LOGLEVEL_ERROR, sprintf("HandleSync(): error saving '%s' - no state information available", $spa->GetNewSyncKey())); |
|
| 1299 | + if (isset($state) && $status == SYNC_STATUS_SUCCESS) { |
|
| 1300 | + self::$deviceManager->GetStateManager()->SetSyncState($spa->GetNewSyncKey(), $state, $spa->GetFolderId()); |
|
| 1301 | + } else { |
|
| 1302 | + ZLog::Write(LOGLEVEL_ERROR, sprintf("HandleSync(): error saving '%s' - no state information available", $spa->GetNewSyncKey())); |
|
| 1303 | + } |
|
| 1253 | 1304 | } |
| 1254 | 1305 | |
| 1255 | 1306 | // save SyncParameters |
| 1256 | - if ($status == SYNC_STATUS_SUCCESS && empty($actiondata["fetchids"])) |
|
| 1257 | - $sc->SaveCollection($spa); |
|
| 1307 | + if ($status == SYNC_STATUS_SUCCESS && empty($actiondata["fetchids"])) { |
|
| 1308 | + $sc->SaveCollection($spa); |
|
| 1309 | + } |
|
| 1258 | 1310 | |
| 1259 | 1311 | return $status; |
| 1260 | 1312 | } |
@@ -1285,15 +1337,14 @@ discard block |
||
| 1285 | 1337 | } |
| 1286 | 1338 | |
| 1287 | 1339 | // if this is an additional folder the backend has to be setup correctly |
| 1288 | - if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) |
|
| 1289 | - throw new StatusException(sprintf("HandleSync() could not Setup() the backend for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 1290 | - } |
|
| 1291 | - catch (StateNotFoundException $snfex) { |
|
| 1340 | + if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore($spa->GetBackendFolderId()))) { |
|
| 1341 | + throw new StatusException(sprintf("HandleSync() could not Setup() the backend for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 1342 | + } |
|
| 1343 | + } catch (StateNotFoundException $snfex) { |
|
| 1292 | 1344 | $status = SYNC_STATUS_INVALIDSYNCKEY; |
| 1293 | 1345 | self::$topCollector->AnnounceInformation("StateNotFoundException", $this->singleFolder); |
| 1294 | 1346 | $this->saveMultiFolderInfo("exception", "StateNotFoundException"); |
| 1295 | - } |
|
| 1296 | - catch (StatusException $stex) { |
|
| 1347 | + } catch (StatusException $stex) { |
|
| 1297 | 1348 | $status = $stex->getCode(); |
| 1298 | 1349 | self::$topCollector->AnnounceInformation(sprintf("StatusException code: %d", $status), $this->singleFolder); |
| 1299 | 1350 | $this->saveMultiFolderInfo("exception", "StateNotFoundException"); |
@@ -1328,22 +1379,22 @@ discard block |
||
| 1328 | 1379 | $this->importer = self::$backend->GetImporter($spa->GetBackendFolderId()); |
| 1329 | 1380 | |
| 1330 | 1381 | // if something goes wrong, ask the mobile to resync the hierarchy |
| 1331 | - if ($this->importer === false) |
|
| 1332 | - throw new StatusException(sprintf("Sync->getImporter(): no importer for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 1382 | + if ($this->importer === false) { |
|
| 1383 | + throw new StatusException(sprintf("Sync->getImporter(): no importer for folder id %s/%s", $spa->GetFolderId(), $spa->GetBackendFolderId()), SYNC_STATUS_FOLDERHIERARCHYCHANGED); |
|
| 1384 | + } |
|
| 1333 | 1385 | |
| 1334 | 1386 | // if there is a valid state obtained after importing changes in a previous loop, we use that state |
| 1335 | 1387 | if (isset($actiondata["failstate"]) && isset($actiondata["failstate"]["failedsyncstate"])) { |
| 1336 | 1388 | $this->importer->Config($actiondata["failstate"]["failedsyncstate"], $spa->GetConflict()); |
| 1389 | + } else { |
|
| 1390 | + $this->importer->Config($sc->GetParameter($spa, "state"), $spa->GetConflict()); |
|
| 1337 | 1391 | } |
| 1338 | - else |
|
| 1339 | - $this->importer->Config($sc->GetParameter($spa, "state"), $spa->GetConflict()); |
|
| 1340 | 1392 | |
| 1341 | 1393 | // the CPO is also needed by the importer to check if imported changes are inside the sync window - see ZP-258 |
| 1342 | 1394 | $this->importer->ConfigContentParameters($spa->GetCPO()); |
| 1343 | 1395 | $this->importer->LoadConflicts($spa->GetCPO(), $sc->GetParameter($spa, "state")); |
| 1344 | 1396 | } |
| 1345 | - } |
|
| 1346 | - catch (StatusException $stex) { |
|
| 1397 | + } catch (StatusException $stex) { |
|
| 1347 | 1398 | $status = $stex->getCode(); |
| 1348 | 1399 | } |
| 1349 | 1400 | |
@@ -1369,8 +1420,9 @@ discard block |
||
| 1369 | 1420 | */ |
| 1370 | 1421 | private function importMessage($spa, &$actiondata, $todo, $message, $clientid, $serverid, $foldertype, $messageCount) { |
| 1371 | 1422 | // the importer needs to be available! |
| 1372 | - if ($this->importer == false) |
|
| 1373 | - throw new StatusException("Sync->importMessage(): importer not available", SYNC_STATUS_SERVERERROR); |
|
| 1423 | + if ($this->importer == false) { |
|
| 1424 | + throw new StatusException("Sync->importMessage(): importer not available", SYNC_STATUS_SERVERERROR); |
|
| 1425 | + } |
|
| 1374 | 1426 | |
| 1375 | 1427 | // mark this state as used, e.g. for HeartBeat |
| 1376 | 1428 | self::$deviceManager->SetHeartbeatStateIntegrity($spa->GetFolderId(), $spa->GetUuid(), $spa->GetUuidCounter()); |
@@ -1423,13 +1475,11 @@ discard block |
||
| 1423 | 1475 | // check incoming message without logging WARN messages about errors |
| 1424 | 1476 | else if (!($message instanceof SyncObject) || !$message->Check(true)) { |
| 1425 | 1477 | $actiondata["statusids"][$serverid] = SYNC_STATUS_CLIENTSERVERCONVERSATIONERROR; |
| 1426 | - } |
|
| 1427 | - else { |
|
| 1478 | + } else { |
|
| 1428 | 1479 | if(isset($message->read)) { |
| 1429 | 1480 | // Currently, 'read' is only sent by the PDA when it is ONLY setting the read flag. |
| 1430 | 1481 | $this->importer->ImportMessageReadFlag($serverid, $message->read); |
| 1431 | - } |
|
| 1432 | - elseif (!isset($message->flag)) { |
|
| 1482 | + } elseif (!isset($message->flag)) { |
|
| 1433 | 1483 | $this->importer->ImportMessageChange($serverid, $message); |
| 1434 | 1484 | } |
| 1435 | 1485 | |
@@ -1441,8 +1491,7 @@ discard block |
||
| 1441 | 1491 | |
| 1442 | 1492 | $actiondata["statusids"][$serverid] = SYNC_STATUS_SUCCESS; |
| 1443 | 1493 | } |
| 1444 | - } |
|
| 1445 | - catch (StatusException $stex) { |
|
| 1494 | + } catch (StatusException $stex) { |
|
| 1446 | 1495 | $actiondata["statusids"][$serverid] = $stex->getCode(); |
| 1447 | 1496 | } |
| 1448 | 1497 | |
@@ -1465,14 +1514,12 @@ discard block |
||
| 1465 | 1514 | else if (!($message instanceof SyncObject) || !$message->Check(true)) { |
| 1466 | 1515 | $actiondata["clientids"][$clientid] = false; |
| 1467 | 1516 | $actiondata["statusids"][$clientid] = SYNC_STATUS_CLIENTSERVERCONVERSATIONERROR; |
| 1468 | - } |
|
| 1469 | - else { |
|
| 1517 | + } else { |
|
| 1470 | 1518 | $actiondata["clientids"][$clientid] = false; |
| 1471 | 1519 | $actiondata["clientids"][$clientid] = $this->importer->ImportMessageChange(false, $message); |
| 1472 | 1520 | $actiondata["statusids"][$clientid] = SYNC_STATUS_SUCCESS; |
| 1473 | 1521 | } |
| 1474 | - } |
|
| 1475 | - catch (StatusException $stex) { |
|
| 1522 | + } catch (StatusException $stex) { |
|
| 1476 | 1523 | $actiondata["statusids"][$clientid] = $stex->getCode(); |
| 1477 | 1524 | } |
| 1478 | 1525 | break; |
@@ -1485,8 +1532,7 @@ discard block |
||
| 1485 | 1532 | ZLog::Write(LOGLEVEL_DEBUG, "SMS sync are not supported. Ignoring message."); |
| 1486 | 1533 | // TODO we should delete the SMS |
| 1487 | 1534 | $actiondata["statusids"][$serverid] = SYNC_STATUS_SUCCESS; |
| 1488 | - } |
|
| 1489 | - else { |
|
| 1535 | + } else { |
|
| 1490 | 1536 | // if message deletions are to be moved, move them |
| 1491 | 1537 | if($spa->GetDeletesAsMoves()) { |
| 1492 | 1538 | $folderid = self::$backend->GetWasteBasket(); |
@@ -1495,16 +1541,15 @@ discard block |
||
| 1495 | 1541 | $actiondata["statusids"][$serverid] = SYNC_STATUS_SUCCESS; |
| 1496 | 1542 | $this->importer->ImportMessageMove($serverid, $folderid); |
| 1497 | 1543 | break; |
| 1544 | + } else { |
|
| 1545 | + ZLog::Write(LOGLEVEL_WARN, "Message should be moved to WasteBasket, but the Backend did not return a destination ID. Message is hard deleted now!"); |
|
| 1498 | 1546 | } |
| 1499 | - else |
|
| 1500 | - ZLog::Write(LOGLEVEL_WARN, "Message should be moved to WasteBasket, but the Backend did not return a destination ID. Message is hard deleted now!"); |
|
| 1501 | 1547 | } |
| 1502 | 1548 | |
| 1503 | 1549 | $this->importer->ImportMessageDeletion($serverid); |
| 1504 | 1550 | $actiondata["statusids"][$serverid] = SYNC_STATUS_SUCCESS; |
| 1505 | 1551 | } |
| 1506 | - } |
|
| 1507 | - catch (StatusException $stex) { |
|
| 1552 | + } catch (StatusException $stex) { |
|
| 1508 | 1553 | if($stex->getCode() != SYNC_MOVEITEMSSTATUS_SUCCESS) { |
| 1509 | 1554 | $actiondata["statusids"][$serverid] = SYNC_STATUS_OBJECTNOTFOUND; |
| 1510 | 1555 | } |
@@ -1551,11 +1596,9 @@ discard block |
||
| 1551 | 1596 | } |
| 1552 | 1597 | if (isset($this->multiFolderInfo["outgoing"]) && isset($this->multiFolderInfo["queued"]) && $this->multiFolderInfo["outgoing"] > 0) { |
| 1553 | 1598 | $s .= sprintf(": Streamed %d out of %d", $this->multiFolderInfo["outgoing"], $this->multiFolderInfo["queued"]); |
| 1554 | - } |
|
| 1555 | - else if (!isset($this->multiFolderInfo["outgoing"]) && !isset($this->multiFolderInfo["queued"])) { |
|
| 1599 | + } else if (!isset($this->multiFolderInfo["outgoing"]) && !isset($this->multiFolderInfo["queued"])) { |
|
| 1556 | 1600 | $s .= ": no changes"; |
| 1557 | - } |
|
| 1558 | - else { |
|
| 1601 | + } else { |
|
| 1559 | 1602 | if (isset($this->multiFolderInfo["outgoing"])) { |
| 1560 | 1603 | $s .= "/".$this->multiFolderInfo["outgoing"] ." streamed"; |
| 1561 | 1604 | } |
@@ -22,27 +22,33 @@ discard block |
||
| 22 | 22 | $searchpicture = false; |
| 23 | 23 | $cpo = new ContentParameters(); |
| 24 | 24 | |
| 25 | - if(!self::$decoder->getElementStartTag(SYNC_SEARCH_SEARCH)) |
|
| 26 | - return false; |
|
| 25 | + if(!self::$decoder->getElementStartTag(SYNC_SEARCH_SEARCH)) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | // TODO check: possible to search in other stores? |
| 29 | - if(!self::$decoder->getElementStartTag(SYNC_SEARCH_STORE)) |
|
| 30 | - return false; |
|
| 30 | + if(!self::$decoder->getElementStartTag(SYNC_SEARCH_STORE)) { |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | - if(!self::$decoder->getElementStartTag(SYNC_SEARCH_NAME)) |
|
| 33 | - return false; |
|
| 34 | + if(!self::$decoder->getElementStartTag(SYNC_SEARCH_NAME)) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 34 | 37 | $searchname = strtoupper(self::$decoder->getElementContent()); |
| 35 | - if(!self::$decoder->getElementEndTag()) |
|
| 36 | - return false; |
|
| 38 | + if(!self::$decoder->getElementEndTag()) { |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 37 | 41 | |
| 38 | - if(!self::$decoder->getElementStartTag(SYNC_SEARCH_QUERY)) |
|
| 39 | - return false; |
|
| 42 | + if(!self::$decoder->getElementStartTag(SYNC_SEARCH_QUERY)) { |
|
| 43 | + return false; |
|
| 44 | + } |
|
| 40 | 45 | |
| 41 | 46 | // check if it is a content of an element (= GAL search) |
| 42 | 47 | // or a starttag (= mailbox or documentlibrary search) |
| 43 | 48 | $searchquery = self::$decoder->getElementContent(); |
| 44 | - if($searchquery && !self::$decoder->getElementEndTag()) |
|
| 45 | - return false; |
|
| 49 | + if($searchquery && !self::$decoder->getElementEndTag()) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 46 | 52 | |
| 47 | 53 | if ($searchquery === false) { |
| 48 | 54 | $cpo->SetSearchName($searchname); |
@@ -50,30 +56,38 @@ discard block |
||
| 50 | 56 | if (self::$decoder->getElementStartTag(SYNC_FOLDERID)) { |
| 51 | 57 | $searchfolderid = self::$decoder->getElementContent(); |
| 52 | 58 | $cpo->SetSearchFolderid($searchfolderid); |
| 53 | - if(!self::$decoder->getElementEndTag()) // SYNC_FOLDERTYPE |
|
| 59 | + if(!self::$decoder->getElementEndTag()) { |
|
| 60 | + // SYNC_FOLDERTYPE |
|
| 54 | 61 | return false; |
| 62 | + } |
|
| 55 | 63 | } |
| 56 | 64 | |
| 57 | 65 | |
| 58 | 66 | if (self::$decoder->getElementStartTag(SYNC_FOLDERTYPE)) { |
| 59 | 67 | $searchclass = self::$decoder->getElementContent(); |
| 60 | 68 | $cpo->SetSearchClass($searchclass); |
| 61 | - if(!self::$decoder->getElementEndTag()) // SYNC_FOLDERTYPE |
|
| 69 | + if(!self::$decoder->getElementEndTag()) { |
|
| 70 | + // SYNC_FOLDERTYPE |
|
| 62 | 71 | return false; |
| 72 | + } |
|
| 63 | 73 | } |
| 64 | 74 | |
| 65 | 75 | if (self::$decoder->getElementStartTag(SYNC_FOLDERID)) { |
| 66 | 76 | $searchfolderid = self::$decoder->getElementContent(); |
| 67 | 77 | $cpo->SetSearchFolderid($searchfolderid); |
| 68 | - if(!self::$decoder->getElementEndTag()) // SYNC_FOLDERTYPE |
|
| 78 | + if(!self::$decoder->getElementEndTag()) { |
|
| 79 | + // SYNC_FOLDERTYPE |
|
| 69 | 80 | return false; |
| 81 | + } |
|
| 70 | 82 | } |
| 71 | 83 | |
| 72 | 84 | if (self::$decoder->getElementStartTag(SYNC_SEARCH_FREETEXT)) { |
| 73 | 85 | $searchfreetext = self::$decoder->getElementContent(); |
| 74 | 86 | $cpo->SetSearchFreeText($searchfreetext); |
| 75 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_FREETEXT |
|
| 87 | + if(!self::$decoder->getElementEndTag()) { |
|
| 88 | + // SYNC_SEARCH_FREETEXT |
|
| 76 | 89 | return false; |
| 90 | + } |
|
| 77 | 91 | } |
| 78 | 92 | |
| 79 | 93 | //TODO - review |
@@ -92,12 +106,16 @@ discard block |
||
| 92 | 106 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_VALUE)) { |
| 93 | 107 | $searchvalue = self::$decoder->getElementContent(); |
| 94 | 108 | $cpo->SetSearchValueGreater($searchvalue); |
| 95 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_VALUE |
|
| 109 | + if(!self::$decoder->getElementEndTag()) { |
|
| 110 | + // SYNC_SEARCH_VALUE |
|
| 96 | 111 | return false; |
| 112 | + } |
|
| 97 | 113 | } |
| 98 | 114 | |
| 99 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_GREATERTHAN |
|
| 115 | + if(!self::$decoder->getElementEndTag()) { |
|
| 116 | + // SYNC_SEARCH_GREATERTHAN |
|
| 100 | 117 | return false; |
| 118 | + } |
|
| 101 | 119 | } |
| 102 | 120 | |
| 103 | 121 | if (self::$decoder->getElementStartTag(SYNC_SEARCH_LESSTHAN)) { |
@@ -115,25 +133,32 @@ discard block |
||
| 115 | 133 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_VALUE)) { |
| 116 | 134 | $searchvalue = self::$decoder->getElementContent(); |
| 117 | 135 | $cpo->SetSearchValueLess($searchvalue); |
| 118 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_VALUE |
|
| 136 | + if(!self::$decoder->getElementEndTag()) { |
|
| 137 | + // SYNC_SEARCH_VALUE |
|
| 119 | 138 | return false; |
| 139 | + } |
|
| 120 | 140 | } |
| 121 | 141 | |
| 122 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_LESSTHAN |
|
| 142 | + if(!self::$decoder->getElementEndTag()) { |
|
| 143 | + // SYNC_SEARCH_LESSTHAN |
|
| 123 | 144 | return false; |
| 145 | + } |
|
| 124 | 146 | } |
| 125 | 147 | |
| 126 | 148 | if (self::$decoder->getElementStartTag(SYNC_SEARCH_FREETEXT)) { |
| 127 | 149 | $searchfreetext = self::$decoder->getElementContent(); |
| 128 | 150 | $cpo->SetSearchFreeText($searchfreetext); |
| 129 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_FREETEXT |
|
| 151 | + if(!self::$decoder->getElementEndTag()) { |
|
| 152 | + // SYNC_SEARCH_FREETEXT |
|
| 130 | 153 | return false; |
| 154 | + } |
|
| 131 | 155 | } |
| 132 | 156 | |
| 133 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_AND |
|
| 157 | + if(!self::$decoder->getElementEndTag()) { |
|
| 158 | + // SYNC_SEARCH_AND |
|
| 134 | 159 | return false; |
| 135 | - } |
|
| 136 | - elseif (self::$decoder->getElementStartTag(SYNC_SEARCH_EQUALTO)) { |
|
| 160 | + } |
|
| 161 | + } elseif (self::$decoder->getElementStartTag(SYNC_SEARCH_EQUALTO)) { |
|
| 137 | 162 | // linkid can be an empty tag as well as have value |
| 138 | 163 | if(self::$decoder->getElementStartTag(SYNC_DOCUMENTLIBRARY_LINKID)) { |
| 139 | 164 | if (($linkId = self::$decoder->getElementContent()) !== false) { |
@@ -147,16 +172,22 @@ discard block |
||
| 147 | 172 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_VALUE)) { |
| 148 | 173 | $searchvalue = self::$decoder->getElementContent(); |
| 149 | 174 | $cpo->SetSearchValueEqualTo($searchvalue); |
| 150 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_VALUE |
|
| 175 | + if(!self::$decoder->getElementEndTag()) { |
|
| 176 | + // SYNC_SEARCH_VALUE |
|
| 151 | 177 | return false; |
| 178 | + } |
|
| 152 | 179 | } |
| 153 | 180 | |
| 154 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_EQUALTO |
|
| 181 | + if(!self::$decoder->getElementEndTag()) { |
|
| 182 | + // SYNC_SEARCH_EQUALTO |
|
| 155 | 183 | return false; |
| 184 | + } |
|
| 156 | 185 | } |
| 157 | 186 | |
| 158 | - if(!self::$decoder->getElementEndTag()) // SYNC_SEARCH_QUERY |
|
| 187 | + if(!self::$decoder->getElementEndTag()) { |
|
| 188 | + // SYNC_SEARCH_QUERY |
|
| 159 | 189 | return false; |
| 190 | + } |
|
| 160 | 191 | |
| 161 | 192 | } |
| 162 | 193 | |
@@ -166,8 +197,9 @@ discard block |
||
| 166 | 197 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_RANGE)) { |
| 167 | 198 | $searchrange = self::$decoder->getElementContent(); |
| 168 | 199 | $cpo->SetSearchRange($searchrange); |
| 169 | - if(!self::$decoder->getElementEndTag()) |
|
| 170 | - return false; |
|
| 200 | + if(!self::$decoder->getElementEndTag()) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 171 | 203 | } |
| 172 | 204 | |
| 173 | 205 | |
@@ -195,8 +227,9 @@ discard block |
||
| 195 | 227 | |
| 196 | 228 | if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) { |
| 197 | 229 | $cpo->SetMimeSupport(self::$decoder->getElementContent()); |
| 198 | - if(!self::$decoder->getElementEndTag()) |
|
| 199 | - return false; |
|
| 230 | + if(!self::$decoder->getElementEndTag()) { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 200 | 233 | } |
| 201 | 234 | |
| 202 | 235 | //TODO body preferences |
@@ -211,24 +244,28 @@ discard block |
||
| 211 | 244 | |
| 212 | 245 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) { |
| 213 | 246 | $cpo->BodyPreference($bptype)->SetTruncationSize(self::$decoder->getElementContent()); |
| 214 | - if(!self::$decoder->getElementEndTag()) |
|
| 215 | - return false; |
|
| 247 | + if(!self::$decoder->getElementEndTag()) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 216 | 250 | } |
| 217 | 251 | |
| 218 | 252 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) { |
| 219 | 253 | $cpo->BodyPreference($bptype)->SetAllOrNone(self::$decoder->getElementContent()); |
| 220 | - if(!self::$decoder->getElementEndTag()) |
|
| 221 | - return false; |
|
| 254 | + if(!self::$decoder->getElementEndTag()) { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 222 | 257 | } |
| 223 | 258 | |
| 224 | 259 | if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) { |
| 225 | 260 | $cpo->BodyPreference($bptype)->SetPreview(self::$decoder->getElementContent()); |
| 226 | - if(!self::$decoder->getElementEndTag()) |
|
| 227 | - return false; |
|
| 261 | + if(!self::$decoder->getElementEndTag()) { |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 228 | 264 | } |
| 229 | 265 | |
| 230 | - if(!self::$decoder->getElementEndTag()) |
|
| 231 | - return false; |
|
| 266 | + if(!self::$decoder->getElementEndTag()) { |
|
| 267 | + return false; |
|
| 268 | + } |
|
| 232 | 269 | } |
| 233 | 270 | |
| 234 | 271 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPARTPREFERENCE)) { |
@@ -242,44 +279,51 @@ discard block |
||
| 242 | 279 | |
| 243 | 280 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) { |
| 244 | 281 | $cpo->BodyPartPreference($bpptype)->SetTruncationSize(self::$decoder->getElementContent()); |
| 245 | - if(!self::$decoder->getElementEndTag()) |
|
| 246 | - return false; |
|
| 282 | + if(!self::$decoder->getElementEndTag()) { |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 247 | 285 | } |
| 248 | 286 | |
| 249 | 287 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) { |
| 250 | 288 | $cpo->BodyPartPreference($bpptype)->SetAllOrNone(self::$decoder->getElementContent()); |
| 251 | - if(!self::$decoder->getElementEndTag()) |
|
| 252 | - return false; |
|
| 289 | + if(!self::$decoder->getElementEndTag()) { |
|
| 290 | + return false; |
|
| 291 | + } |
|
| 253 | 292 | } |
| 254 | 293 | |
| 255 | 294 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) { |
| 256 | 295 | $cpo->BodyPartPreference($bpptype)->SetPreview(self::$decoder->getElementContent()); |
| 257 | - if(!self::$decoder->getElementEndTag()) |
|
| 258 | - return false; |
|
| 296 | + if(!self::$decoder->getElementEndTag()) { |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 259 | 299 | } |
| 260 | 300 | |
| 261 | - if (!self::$decoder->getElementEndTag()) |
|
| 262 | - return false; |
|
| 301 | + if (!self::$decoder->getElementEndTag()) { |
|
| 302 | + return false; |
|
| 303 | + } |
|
| 263 | 304 | } |
| 264 | 305 | |
| 265 | 306 | if(self::$decoder->getElementStartTag(SYNC_RIGHTSMANAGEMENT_SUPPORT)) { |
| 266 | 307 | $cpo->SetRmSupport(self::$decoder->getElementContent()); |
| 267 | - if(!self::$decoder->getElementEndTag()) |
|
| 268 | - return false; |
|
| 308 | + if(!self::$decoder->getElementEndTag()) { |
|
| 309 | + return false; |
|
| 310 | + } |
|
| 269 | 311 | } |
| 270 | 312 | |
| 271 | 313 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_PICTURE)) { // TODO - do something with maxsize and maxpictures in the backend |
| 272 | 314 | $searchpicture = new SyncResolveRecipientsPicture(); |
| 273 | 315 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_MAXSIZE)) { |
| 274 | 316 | $searchpicture->maxsize = self::$decoder->getElementContent(); |
| 275 | - if(!self::$decoder->getElementEndTag()) |
|
| 276 | - return false; |
|
| 317 | + if(!self::$decoder->getElementEndTag()) { |
|
| 318 | + return false; |
|
| 319 | + } |
|
| 277 | 320 | } |
| 278 | 321 | |
| 279 | 322 | if(self::$decoder->getElementStartTag(SYNC_SEARCH_MAXPICTURES)) { |
| 280 | 323 | $searchpicture->maxpictures = self::$decoder->getElementContent(); |
| 281 | - if(!self::$decoder->getElementEndTag()) |
|
| 282 | - return false; |
|
| 324 | + if(!self::$decoder->getElementEndTag()) { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 283 | 327 | } |
| 284 | 328 | |
| 285 | 329 | // iOs devices send empty picture tag: <Search:Picture/> |
@@ -297,11 +341,15 @@ discard block |
||
| 297 | 341 | } |
| 298 | 342 | } |
| 299 | 343 | } |
| 300 | - if(!self::$decoder->getElementEndTag()) //store |
|
| 344 | + if(!self::$decoder->getElementEndTag()) { |
|
| 345 | + //store |
|
| 301 | 346 | return false; |
| 347 | + } |
|
| 302 | 348 | |
| 303 | - if(!self::$decoder->getElementEndTag()) //search |
|
| 349 | + if(!self::$decoder->getElementEndTag()) { |
|
| 350 | + //search |
|
| 304 | 351 | return false; |
| 352 | + } |
|
| 305 | 353 | |
| 306 | 354 | // get SearchProvider |
| 307 | 355 | $searchprovider = ZPush::GetBackend()->GetSearchProvider(); |
@@ -315,18 +363,15 @@ discard block |
||
| 315 | 363 | if ($searchname == ISearchProvider::SEARCH_GAL) { |
| 316 | 364 | //get search results from the searchprovider |
| 317 | 365 | $rows = $searchprovider->GetGALSearchResults($searchquery, $searchrange, $searchpicture); |
| 318 | - } |
|
| 319 | - elseif ($searchname == ISearchProvider::SEARCH_MAILBOX) { |
|
| 366 | + } elseif ($searchname == ISearchProvider::SEARCH_MAILBOX) { |
|
| 320 | 367 | $backendFolderId = self::$deviceManager->GetBackendIdForFolderId($cpo->GetSearchFolderid()); |
| 321 | 368 | $cpo->SetSearchFolderid($backendFolderId); |
| 322 | 369 | $rows = $searchprovider->GetMailboxSearchResults($cpo); |
| 323 | 370 | } |
| 324 | - } |
|
| 325 | - catch (StatusException $stex) { |
|
| 371 | + } catch (StatusException $stex) { |
|
| 326 | 372 | $storestatus = $stex->getCode(); |
| 327 | 373 | } |
| 328 | - } |
|
| 329 | - else { |
|
| 374 | + } else { |
|
| 330 | 375 | $rows = array('searchtotal' => 0); |
| 331 | 376 | $status = SYNC_SEARCHSTATUS_SERVERERROR; |
| 332 | 377 | ZLog::Write(LOGLEVEL_WARN, sprintf("Searchtype '%s' is not supported.", $searchname)); |
@@ -441,8 +486,7 @@ discard block |
||
| 441 | 486 | self::$encoder->endTag();//properties |
| 442 | 487 | } |
| 443 | 488 | } |
| 444 | - } |
|
| 445 | - elseif ($searchname == ISearchProvider::SEARCH_MAILBOX) { |
|
| 489 | + } elseif ($searchname == ISearchProvider::SEARCH_MAILBOX) { |
|
| 446 | 490 | foreach ($rows as $u) { |
| 447 | 491 | // TODO: unclear if any clients *require* the folder id where the message is located (it's not available anymore) |
| 448 | 492 | //$folderid = self::$deviceManager->GetFolderIdForBackendId($u['folderid']); |
@@ -21,33 +21,37 @@ discard block |
||
| 21 | 21 | $sm = new SyncSendMail(); |
| 22 | 22 | |
| 23 | 23 | $reply = $forward = $parent = $sendmail = $smartreply = $smartforward = false; |
| 24 | - if (Request::GetGETCollectionId()) |
|
| 25 | - $parent = Request::GetGETCollectionId(); |
|
| 26 | - if ($commandCode == ZPush::COMMAND_SMARTFORWARD) |
|
| 27 | - $forward = Request::GetGETItemId(); |
|
| 28 | - else if ($commandCode == ZPush::COMMAND_SMARTREPLY) |
|
| 29 | - $reply = Request::GetGETItemId(); |
|
| 24 | + if (Request::GetGETCollectionId()) { |
|
| 25 | + $parent = Request::GetGETCollectionId(); |
|
| 26 | + } |
|
| 27 | + if ($commandCode == ZPush::COMMAND_SMARTFORWARD) { |
|
| 28 | + $forward = Request::GetGETItemId(); |
|
| 29 | + } else if ($commandCode == ZPush::COMMAND_SMARTREPLY) { |
|
| 30 | + $reply = Request::GetGETItemId(); |
|
| 31 | + } |
|
| 30 | 32 | |
| 31 | 33 | if (self::$decoder->IsWBXML()) { |
| 32 | 34 | $el = self::$decoder->getElement(); |
| 33 | 35 | |
| 34 | - if($el[EN_TYPE] != EN_TYPE_STARTTAG) |
|
| 35 | - return false; |
|
| 36 | + if($el[EN_TYPE] != EN_TYPE_STARTTAG) { |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 36 | 39 | |
| 37 | 40 | |
| 38 | - if($el[EN_TAG] == SYNC_COMPOSEMAIL_SENDMAIL) |
|
| 39 | - $sendmail = true; |
|
| 40 | - else if($el[EN_TAG] == SYNC_COMPOSEMAIL_SMARTREPLY) |
|
| 41 | - $smartreply = true; |
|
| 42 | - else if($el[EN_TAG] == SYNC_COMPOSEMAIL_SMARTFORWARD) |
|
| 43 | - $smartforward = true; |
|
| 41 | + if($el[EN_TAG] == SYNC_COMPOSEMAIL_SENDMAIL) { |
|
| 42 | + $sendmail = true; |
|
| 43 | + } else if($el[EN_TAG] == SYNC_COMPOSEMAIL_SMARTREPLY) { |
|
| 44 | + $smartreply = true; |
|
| 45 | + } else if($el[EN_TAG] == SYNC_COMPOSEMAIL_SMARTFORWARD) { |
|
| 46 | + $smartforward = true; |
|
| 47 | + } |
|
| 44 | 48 | |
| 45 | - if(!$sendmail && !$smartreply && !$smartforward) |
|
| 46 | - return false; |
|
| 49 | + if(!$sendmail && !$smartreply && !$smartforward) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 47 | 52 | |
| 48 | 53 | $sm->Decode(self::$decoder); |
| 49 | - } |
|
| 50 | - else { |
|
| 54 | + } else { |
|
| 51 | 55 | $sm->mime = self::$decoder->GetPlainInputStream(); |
| 52 | 56 | // no wbxml output is provided, only a http OK |
| 53 | 57 | $sm->saveinsent = Request::GetGETSaveInSent(); |
@@ -60,9 +64,15 @@ discard block |
||
| 60 | 64 | // If the mobile sends an email in WBXML data the variables below |
| 61 | 65 | // should be set. If it is a RFC822 message, get the reply/forward message id |
| 62 | 66 | // from the request as they are always available there |
| 63 | - if (!isset($sm->source)) $sm->source = new SyncSendMailSource(); |
|
| 64 | - if (!isset($sm->source->itemid)) $sm->source->itemid = Request::GetGETItemId(); |
|
| 65 | - if (!isset($sm->source->folderid)) $sm->source->folderid = Request::GetGETCollectionId(); |
|
| 67 | + if (!isset($sm->source)) { |
|
| 68 | + $sm->source = new SyncSendMailSource(); |
|
| 69 | + } |
|
| 70 | + if (!isset($sm->source->itemid)) { |
|
| 71 | + $sm->source->itemid = Request::GetGETItemId(); |
|
| 72 | + } |
|
| 73 | + if (!isset($sm->source->folderid)) { |
|
| 74 | + $sm->source->folderid = Request::GetGETCollectionId(); |
|
| 75 | + } |
|
| 66 | 76 | |
| 67 | 77 | // split long-id if it's set - it overwrites folderid and itemid |
| 68 | 78 | if (isset($sm->source->longid) && $sm->source->longid) { |
@@ -81,13 +91,13 @@ discard block |
||
| 81 | 91 | // Even if they are a part of SyncSendMail object, they won't be streamed. |
| 82 | 92 | if ($smartreply || $reply) { |
| 83 | 93 | $sm->replyflag = true; |
| 84 | - } |
|
| 85 | - else { |
|
| 94 | + } else { |
|
| 86 | 95 | $sm->forwardflag = true; |
| 87 | 96 | } |
| 88 | 97 | |
| 89 | - if (!isset($sm->source->folderid) || !$sm->source->folderid) |
|
| 90 | - ZLog::Write(LOGLEVEL_ERROR, sprintf("SendMail(): No parent folder id while replying or forwarding message:'%s'", (($reply) ? $reply : $forward))); |
|
| 98 | + if (!isset($sm->source->folderid) || !$sm->source->folderid) { |
|
| 99 | + ZLog::Write(LOGLEVEL_ERROR, sprintf("SendMail(): No parent folder id while replying or forwarding message:'%s'", (($reply) ? $reply : $forward))); |
|
| 100 | + } |
|
| 91 | 101 | } |
| 92 | 102 | |
| 93 | 103 | self::$topCollector->AnnounceInformation(sprintf("SendMail(): Sending email with %d bytes", strlen($sm->mime)), true); |
@@ -95,8 +105,7 @@ discard block |
||
| 95 | 105 | $statusMessage = ''; |
| 96 | 106 | try { |
| 97 | 107 | $status = self::$backend->SendMail($sm); |
| 98 | - } |
|
| 99 | - catch (StatusException $se) { |
|
| 108 | + } catch (StatusException $se) { |
|
| 100 | 109 | $status = $se->getCode(); |
| 101 | 110 | $statusMessage = $se->getMessage(); |
| 102 | 111 | } |
@@ -110,9 +119,9 @@ discard block |
||
| 110 | 119 | self::$encoder->content($status); //TODO return the correct status |
| 111 | 120 | self::$encoder->endTag(); |
| 112 | 121 | self::$encoder->endTag(); |
| 122 | + } else { |
|
| 123 | + throw new HTTPReturnCodeException($statusMessage, HTTP_CODE_500, null, LOGLEVEL_WARN); |
|
| 113 | 124 | } |
| 114 | - else |
|
| 115 | - throw new HTTPReturnCodeException($statusMessage, HTTP_CODE_500, null, LOGLEVEL_WARN); |
|
| 116 | 125 | } |
| 117 | 126 | |
| 118 | 127 | return $status; |