Page MenuHomePhorge

D4950.id14178.diff
No OneTemporary

D4950.id14178.diff

diff --git a/lib/ext/Syncroton/Command/MoveItems.php b/lib/ext/Syncroton/Command/MoveItems.php
--- a/lib/ext/Syncroton/Command/MoveItems.php
+++ b/lib/ext/Syncroton/Command/MoveItems.php
@@ -59,11 +59,11 @@
$response = $moves->appendChild($this->_outputDom->createElementNS('uri:Move', 'Response'));
$response->appendChild($this->_outputDom->createElementNS('uri:Move', 'SrcMsgId', $move['srcMsgId']));
- try {
- if ($move['srcFldId'] === $move['dstFldId']) {
- throw new Syncroton_Exception_Status_MoveItems(Syncroton_Exception_Status_MoveItems::SAME_FOLDER);
- }
+ if ($this->_logger instanceof Zend_Log) {
+ $this->_logger->warning(__METHOD__ . '::' . __LINE__ . "Moving from " . $move['srcFldId'] . " to " . $move['dstFldId']);
+ }
+ try {
try {
$sourceFolder = $this->_folderBackend->getFolder($this->_device, $move['srcFldId']);
} catch (Syncroton_Exception_NotFound $e) {
@@ -76,19 +76,25 @@
throw new Syncroton_Exception_Status_MoveItems(Syncroton_Exception_Status_MoveItems::INVALID_DESTINATION);
}
- $dataController = Syncroton_Data_Factory::factory($sourceFolder->class, $this->_device, $this->_syncTimeStamp);
- $newId = $dataController->moveItem($move['srcFldId'], $move['srcMsgId'], $move['dstFldId']);
+ if ($move['srcFldId'] === $move['dstFldId']) {
+ throw new Syncroton_Exception_Status_MoveItems(Syncroton_Exception_Status_MoveItems::SAME_FOLDER);
+ }
+
+ try {
+ $dataController = Syncroton_Data_Factory::factory($sourceFolder->class, $this->_device, $this->_syncTimeStamp);
+ $newId = $dataController->moveItem($move['srcFldId'], $move['srcMsgId'], $move['dstFldId']);
- if (!$newId) {
+ if (!$newId) {
+ throw new Syncroton_Exception_Status_MoveItems(Syncroton_Exception_Status_MoveItems::INVALID_SOURCE);
+ }
+ } catch (Exception $e) {
throw new Syncroton_Exception_Status_MoveItems(Syncroton_Exception_Status_MoveItems::INVALID_SOURCE);
}
$response->appendChild($this->_outputDom->createElementNS('uri:Move', 'Status', Syncroton_Command_MoveItems::STATUS_SUCCESS));
$response->appendChild($this->_outputDom->createElementNS('uri:Move', 'DstMsgId', $newId));
- } catch (Syncroton_Exception_Status $e) {
+ } catch (Syncroton_Exception_Status_MoveItems $e) {
$response->appendChild($this->_outputDom->createElementNS('uri:Move', 'Status', $e->getCode()));
- } catch (Exception $e) {
- $response->appendChild($this->_outputDom->createElementNS('uri:Move', 'Status', Syncroton_Exception_Status::SERVER_ERROR));
}
}
diff --git a/tests/Sync/MoveItemsTest.php b/tests/Sync/MoveItemsTest.php
--- a/tests/Sync/MoveItemsTest.php
+++ b/tests/Sync/MoveItemsTest.php
@@ -134,6 +134,64 @@
$this->assertSame('test sync', $xpath->query("ns:Commands/ns:Add/ns:ApplicationData/Email:Subject", $root)->item(0)->nodeValue);
}
+ public function testInvalidMove()
+ {
+ $this->emptyTestFolder('INBOX', 'mail');
+ $this->emptyTestFolder('Trash', 'mail');
+ $uid = $this->appendMail('INBOX', 'mail.sync1');
+ $this->registerDevice();
+ $inbox = array_search('INBOX', $this->folders);
+ $trash = array_search('Trash', $this->folders);
+
+ // Move item that doesn't exist
+ $request = <<<EOF
+ <?xml version="1.0" encoding="utf-8"?>
+ <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
+ <MoveItems xmlns="uri:Move">
+ <Move>
+ <SrcMsgId>foobar::99999</SrcMsgId>
+ <SrcFldId>foobar</SrcFldId>
+ <DstFldId>foobar</DstFldId>
+ </Move>
+ </MoveItems>
+ EOF;
+
+ $response = $this->request($request, 'MoveItems');
+
+ $this->assertEquals(200, $response->getStatusCode());
+
+ $dom = $this->fromWbxml($response->getBody());
+ $xpath = $this->xpath($dom);
+ $xpath->registerNamespace('Move', 'uri:Move');
+
+ $root = $xpath->query("//Move:MoveItems/Move:Response")->item(0);
+ $this->assertSame('1', $xpath->query("Move:Status", $root)->item(0)->nodeValue);
+
+ // Move item that doesn't exist
+ $request = <<<EOF
+ <?xml version="1.0" encoding="utf-8"?>
+ <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
+ <MoveItems xmlns="uri:Move">
+ <Move>
+ <SrcMsgId>{$inbox}::99999</SrcMsgId>
+ <SrcFldId>{$inbox}</SrcFldId>
+ <DstFldId>{$trash}</DstFldId>
+ </Move>
+ </MoveItems>
+ EOF;
+
+ $response = $this->request($request, 'MoveItems');
+
+ $this->assertEquals(200, $response->getStatusCode());
+
+ $dom = $this->fromWbxml($response->getBody());
+ $xpath = $this->xpath($dom);
+ $xpath->registerNamespace('Move', 'uri:Move');
+
+ $root = $xpath->query("//Move:MoveItems/Move:Response")->item(0);
+ $this->assertSame('1', $xpath->query("Move:Status", $root)->item(0)->nodeValue);
+ }
+
/**
* Test moving a contact
*/

File Metadata

Mime Type
text/plain
Expires
Sun, Sep 22, 5:21 AM (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9483039
Default Alt Text
D4950.id14178.diff (5 KB)

Event Timeline