From 0939ad8e76054819d2422db36d9ec6f68bce441b Mon Sep 17 00:00:00 2001 From: David Glenck Date: Sun, 26 Oct 2014 19:33:23 +0100 Subject: [PATCH 1/2] keep creation date when updating bookmark --- www/api/posts_add.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/www/api/posts_add.php b/www/api/posts_add.php index 80d65155..c655239b 100644 --- a/www/api/posts_add.php +++ b/www/api/posts_add.php @@ -68,7 +68,7 @@ if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '') && (trim($_REQUEST['tags']) != ',') ) { - $tags = trim($_REQUEST['tags']); + $tags = trim(urldecode($_REQUEST['tags'])); } else { $tags = null; } @@ -123,12 +123,13 @@ header('HTTP/1.0 409 Conflict'); $msg = 'bookmark does already exist'; } else { - //delete it before we re-add it + //edit bookmark instead $bookmark = $bs->getBookmarkByAddress($url, false); - $bId = $bookmark['bId']; - $bs->deleteBookmark($bId); - - $exists = false; + $bId = intval($bookmark['bId']); + $updated = $bs->updateBookmark( + $bId, $url, $description, $extended, '', $status, $tags, null, null, true + ); + $msg = 'done'; } } @@ -143,4 +144,4 @@ // Set up the XML file and output the result. echo '\r\n"; echo ''; -?> \ No newline at end of file +?> From 5053c753f10b33b49fd2f0c04e448fcc754add45 Mon Sep 17 00:00:00 2001 From: David Glenck Date: Sun, 26 Oct 2014 23:09:23 +0100 Subject: [PATCH 2/2] test for creation/modification date for api/posts/add with replace yes --- tests/Api/PostsAddTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index e6d05311..50d7a8f5 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -375,6 +375,12 @@ public function testReplaceYes() //all should be well $this->assertEquals(200, $res->getStatus()); + //get date + $data = $this->bs->getBookmarks(0, null, $uId); + $creationDate = $data['bookmarks'][0]['bDatetime']; + $modificationDate = $data['bookmarks'][0]['bModified']; + sleep(1); //wait 1 second to detect change in modification time + //send it a second time, with different title list($req, $dummy) = $this->getAuthRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); @@ -405,6 +411,9 @@ public function testReplaceYes() $data = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(1, $data['total']); $this->assertEquals($title2, $data['bookmarks'][0]['bTitle']); + // creation date should be unchanged and modification date should be newer + $this->assertEquals($creationDate, $data['bookmarks'][0]['bDatetime'], "Creation date must not be updated, when replacing a bookmark."); + $this->assertGreaterThan($modificationDate, $data['bookmarks'][0]['bModified'], "Modification date must be updated, when replacing a bookmark."); }