part of request #2830224: prepare API for short url service
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@570 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
60fa8fd540
commit
82b17be346
10 changed files with 101 additions and 22 deletions
|
@ -19,6 +19,7 @@ CREATE TABLE `sc_bookmarks` (
|
||||||
`bHash` varchar(32) NOT NULL default '',
|
`bHash` varchar(32) NOT NULL default '',
|
||||||
`bVotes` int(11) NOT NULL,
|
`bVotes` int(11) NOT NULL,
|
||||||
`bVoting` int(11) NOT NULL,
|
`bVoting` int(11) NOT NULL,
|
||||||
|
`bShort` varchar(16) default NULL,
|
||||||
PRIMARY KEY (`bId`),
|
PRIMARY KEY (`bId`),
|
||||||
KEY `sc_bookmarks_usd` (`uId`,`bStatus`,`bDatetime`),
|
KEY `sc_bookmarks_usd` (`uId`,`bStatus`,`bDatetime`),
|
||||||
KEY `sc_bookmarks_hui` (`bHash`,`uId`,`bId`),
|
KEY `sc_bookmarks_hui` (`bHash`,`uId`,`bId`),
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
Upgrading SemanticScuttle from a previous version
|
Upgrading SemanticScuttle from a previous version
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
From versin 0.94 to 0.95.0
|
From version 0.95 to 0.96
|
||||||
|
-------------------------
|
||||||
|
Update your database:
|
||||||
|
- ALTER TABLE `sc_bookmarks` ADD `bShort` VARCHAR(16) NULL DEFAULT NULL;
|
||||||
|
|
||||||
|
API:
|
||||||
|
The method signatures of addBookmark() and updateBookmark()
|
||||||
|
changed due to the addition of the $short parameter.
|
||||||
|
|
||||||
|
|
||||||
|
From version 0.94 to 0.95
|
||||||
--------------------------
|
--------------------------
|
||||||
The file structure completely changed in 0.95.0 compared
|
The file structure completely changed in 0.95.0 compared
|
||||||
to previous versions. We recommend that you start with a
|
to previous versions. We recommend that you start with a
|
||||||
|
|
|
@ -20,7 +20,7 @@ for ($nA = 0; $nA < 10; $nA++) {
|
||||||
null,
|
null,
|
||||||
0,
|
0,
|
||||||
array('unittest'),
|
array('unittest'),
|
||||||
null, false, false,
|
null, null, false, false,
|
||||||
$uid
|
$uid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,6 +286,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
* 1 - shared
|
* 1 - shared
|
||||||
* 2 - private
|
* 2 - private
|
||||||
* @param array $tags Array of tags
|
* @param array $tags Array of tags
|
||||||
|
* @param string $short Short URL name. May be null
|
||||||
* @param string $date Date when the bookmark has been created
|
* @param string $date Date when the bookmark has been created
|
||||||
* originally. Used in combination with
|
* originally. Used in combination with
|
||||||
* $fromImport. Has to be a strtotime()
|
* $fromImport. Has to be a strtotime()
|
||||||
|
@ -298,6 +299,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
*/
|
*/
|
||||||
public function addBookmark(
|
public function addBookmark(
|
||||||
$address, $title, $description, $privateNote, $status, $tags,
|
$address, $title, $description, $privateNote, $status, $tags,
|
||||||
|
$short = null,
|
||||||
$date = null, $fromApi = false, $fromImport = false, $sId = null
|
$date = null, $fromApi = false, $fromImport = false, $sId = null
|
||||||
) {
|
) {
|
||||||
if ($sId === null) {
|
if ($sId === null) {
|
||||||
|
@ -327,6 +329,10 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
}
|
}
|
||||||
$datetime = gmdate('Y-m-d H:i:s', $time);
|
$datetime = gmdate('Y-m-d H:i:s', $time);
|
||||||
|
|
||||||
|
if ($short === '') {
|
||||||
|
$short = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the SQL insert statement and execute it.
|
// Set up the SQL insert statement and execute it.
|
||||||
$values = array(
|
$values = array(
|
||||||
'uId' => intval($sId),
|
'uId' => intval($sId),
|
||||||
|
@ -338,7 +344,8 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
'bDescription' => $description,
|
'bDescription' => $description,
|
||||||
'bPrivateNote' => $privateNote,
|
'bPrivateNote' => $privateNote,
|
||||||
'bStatus' => intval($status),
|
'bStatus' => intval($status),
|
||||||
'bHash' => md5($address)
|
'bHash' => md5($address),
|
||||||
|
'bShort' => $short
|
||||||
);
|
);
|
||||||
|
|
||||||
$sql = 'INSERT INTO '. $this->getTableName()
|
$sql = 'INSERT INTO '. $this->getTableName()
|
||||||
|
@ -402,6 +409,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
* 1 - shared
|
* 1 - shared
|
||||||
* 2 - private
|
* 2 - private
|
||||||
* @param array $categories Array of tags
|
* @param array $categories Array of tags
|
||||||
|
* @param string $short Short URL name. May be null.
|
||||||
* @param string $date Date when the bookmark has been created
|
* @param string $date Date when the bookmark has been created
|
||||||
* originally. Used in combination with
|
* originally. Used in combination with
|
||||||
* $fromImport. Has to be a strtotime()
|
* $fromImport. Has to be a strtotime()
|
||||||
|
@ -412,7 +420,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
*/
|
*/
|
||||||
public function updateBookmark(
|
public function updateBookmark(
|
||||||
$bId, $address, $title, $description, $privateNote, $status,
|
$bId, $address, $title, $description, $privateNote, $status,
|
||||||
$categories, $date = NULL, $fromApi = false
|
$categories, $short = null, $date = null, $fromApi = false
|
||||||
) {
|
) {
|
||||||
if (!is_numeric($bId)) {
|
if (!is_numeric($bId)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -431,15 +439,31 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
|
||||||
|
|
||||||
$address = $this->normalize($address);
|
$address = $this->normalize($address);
|
||||||
|
|
||||||
//check if a new address ($address) doesn't already exist for another bookmark from the same user
|
//check if a new address ($address) doesn't already exist
|
||||||
|
// for another bookmark from the same user
|
||||||
$bookmark = $this->getBookmark($bId);
|
$bookmark = $this->getBookmark($bId);
|
||||||
if($bookmark['bAddress'] != $address && $this->bookmarkExists($address, $bookmark['uId'])) {
|
if ($bookmark['bAddress'] != $address
|
||||||
|
&& $this->bookmarkExists($address, $bookmark['uId'])
|
||||||
|
) {
|
||||||
message_die(GENERAL_ERROR, 'Could not update bookmark (URL already existing = '.$address.')', '', __LINE__, __FILE__);
|
message_die(GENERAL_ERROR, 'Could not update bookmark (URL already existing = '.$address.')', '', __LINE__, __FILE__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($short === '') {
|
||||||
|
$short = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the SQL update statement and execute it.
|
// Set up the SQL update statement and execute it.
|
||||||
$updates = array('bModified' => $moddatetime, 'bTitle' => $title, 'bAddress' => $address, 'bDescription' => $description, 'bPrivateNote' => $privateNote, 'bStatus' => $status, 'bHash' => md5($address));
|
$updates = array(
|
||||||
|
'bModified' => $moddatetime,
|
||||||
|
'bTitle' => $title,
|
||||||
|
'bAddress' => $address,
|
||||||
|
'bDescription' => $description,
|
||||||
|
'bPrivateNote' => $privateNote,
|
||||||
|
'bStatus' => $status,
|
||||||
|
'bHash' => md5($address),
|
||||||
|
'bShort' => $short
|
||||||
|
);
|
||||||
|
|
||||||
if (!is_null($date)) {
|
if (!is_null($date)) {
|
||||||
$datetime = gmdate('Y-m-d H:i:s', strtotime($date));
|
$datetime = gmdate('Y-m-d H:i:s', strtotime($date));
|
||||||
|
|
|
@ -69,6 +69,24 @@ class BookmarkTest extends TestBase
|
||||||
$this->vs->deleteAll();
|
$this->vs->deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if adding a bookmark with short url name
|
||||||
|
* saves it in the database.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddBookmarkShort()
|
||||||
|
{
|
||||||
|
$bid = $this->bs->addBookmark(
|
||||||
|
'http://example.org', 'title', 'desc', 'priv',
|
||||||
|
0, array(), 'myShortName'
|
||||||
|
);
|
||||||
|
$bm = $this->bs->getBookmark($bid);
|
||||||
|
$this->assertEquals('http://example.org', $bm['bAddress']);
|
||||||
|
$this->assertArrayHasKey('bShort', $bm);
|
||||||
|
$this->assertEquals('myShortName', $bm['bShort']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testHardCharactersInBookmarks()
|
public function testHardCharactersInBookmarks()
|
||||||
{
|
{
|
||||||
$bs = $this->bs;
|
$bs = $this->bs;
|
||||||
|
@ -81,7 +99,7 @@ class BookmarkTest extends TestBase
|
||||||
$bid = $bs->addBookmark(
|
$bid = $bs->addBookmark(
|
||||||
'http://site1.com', $title, $desc, 'note',
|
'http://site1.com', $title, $desc, 'note',
|
||||||
0, array($tag1, $tag2),
|
0, array($tag1, $tag2),
|
||||||
null, false, false, $uid
|
null, null, false, false, $uid
|
||||||
);
|
);
|
||||||
|
|
||||||
$bookmarks = $bs->getBookmarks(0, 1);
|
$bookmarks = $bs->getBookmarks(0, 1);
|
||||||
|
@ -108,12 +126,12 @@ class BookmarkTest extends TestBase
|
||||||
|
|
||||||
$bs->addBookmark(
|
$bs->addBookmark(
|
||||||
'http://site1.com', "title", "description", 'note',
|
'http://site1.com', "title", "description", 'note',
|
||||||
0, array('tag1'), null, false, false,
|
0, array('tag1'), null, null, false, false,
|
||||||
$uid
|
$uid
|
||||||
);
|
);
|
||||||
$bs->addBookmark(
|
$bs->addBookmark(
|
||||||
"http://site1.com", "title2", "description2", 'note',
|
"http://site1.com", "title2", "description2", 'note',
|
||||||
0, array('tag2'), null, false, false,
|
0, array('tag2'), null, null, false, false,
|
||||||
$uid2
|
$uid2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -280,7 +298,7 @@ class BookmarkTest extends TestBase
|
||||||
$this->bs->addBookmark(
|
$this->bs->addBookmark(
|
||||||
'http://test', 'test', 'desc', 'note',
|
'http://test', 'test', 'desc', 'note',
|
||||||
2,//private
|
2,//private
|
||||||
array(), null, false, false, $uid
|
array(), null, null, false, false, $uid
|
||||||
);
|
);
|
||||||
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
||||||
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
||||||
|
@ -302,7 +320,7 @@ class BookmarkTest extends TestBase
|
||||||
$this->bs->addBookmark(
|
$this->bs->addBookmark(
|
||||||
'http://test', 'test', 'desc', 'note',
|
'http://test', 'test', 'desc', 'note',
|
||||||
1,//shared
|
1,//shared
|
||||||
array(), null, false, false, $uid
|
array(), null, null, false, false, $uid
|
||||||
);
|
);
|
||||||
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
||||||
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
||||||
|
@ -734,6 +752,32 @@ class BookmarkTest extends TestBase
|
||||||
$this->assertEquals(1, count($bm['tags']));
|
$this->assertEquals(1, count($bm['tags']));
|
||||||
$this->assertContains('new', $bm['tags']);
|
$this->assertContains('new', $bm['tags']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if updating a bookmark's short url name
|
||||||
|
* saves it in the database.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUpdateBookmarkShort()
|
||||||
|
{
|
||||||
|
$bid = $this->bs->addBookmark(
|
||||||
|
'http://example.org', 'title', 'desc', 'priv',
|
||||||
|
0, array(), 'myShortName'
|
||||||
|
);
|
||||||
|
$bm = $this->bs->getBookmark($bid);
|
||||||
|
$this->assertEquals('myShortName', $bm['bShort']);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$this->bs->updateBookmark(
|
||||||
|
$bid, 'http://example2.org', 'my title', 'desc',
|
||||||
|
'priv', 0, array(), 'newShortNambb'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$bm = $this->bs->getBookmark($bid);
|
||||||
|
$this->assertEquals('newShortNambb', $bm['bShort']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,7 @@ class Tag2TagTest extends TestBase
|
||||||
$uid = $this->addUser();
|
$uid = $this->addUser();
|
||||||
$bs->addBookmark(
|
$bs->addBookmark(
|
||||||
"http://google.com", "title", "description", 'note',
|
"http://google.com", "title", "description", 'note',
|
||||||
0, $tags, null, false, false,
|
0, $tags, null, null, false, false,
|
||||||
$uid
|
$uid
|
||||||
);
|
);
|
||||||
$bookmark = $bs->getBookmarkByAddress("http://google.com");
|
$bookmark = $bs->getBookmarkByAddress("http://google.com");
|
||||||
|
@ -312,17 +312,17 @@ class Tag2TagTest extends TestBase
|
||||||
$tags = array('aa>bb>cc', 'dd');
|
$tags = array('aa>bb>cc', 'dd');
|
||||||
$bs->addBookmark(
|
$bs->addBookmark(
|
||||||
"web1.com", "B1", "description", 'note', 0,
|
"web1.com", "B1", "description", 'note', 0,
|
||||||
$tags, null, false, false, 1
|
$tags, null, null, false, false, 1
|
||||||
);
|
);
|
||||||
$tags = array('bb>gg', 'ee>ff');
|
$tags = array('bb>gg', 'ee>ff');
|
||||||
$bs->addBookmark(
|
$bs->addBookmark(
|
||||||
"web2.com", "B2", "description", 'note', 0,
|
"web2.com", "B2", "description", 'note', 0,
|
||||||
$tags, null, false, false, 1
|
$tags, null, null, false, false, 1
|
||||||
);
|
);
|
||||||
$tags = array('ee=ii');
|
$tags = array('ee=ii');
|
||||||
$bs->addBookmark(
|
$bs->addBookmark(
|
||||||
"web3.com", "B3", "description", 'note', 0,
|
"web3.com", "B3", "description", 'note', 0,
|
||||||
$tags, null, false, false, 1
|
$tags, null, null, false, false, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
// Query format:
|
// Query format:
|
||||||
|
@ -489,12 +489,12 @@ class Tag2TagTest extends TestBase
|
||||||
// with classic tags (users 10 & 20)
|
// with classic tags (users 10 & 20)
|
||||||
$bid1 = $bs->addBookmark(
|
$bid1 = $bs->addBookmark(
|
||||||
"http://site1.com", "title", "description", 'note', 0,
|
"http://site1.com", "title", "description", 'note', 0,
|
||||||
array('tag1', 'tag11', 'tag111'), null, false, false,
|
array('tag1', 'tag11', 'tag111'), null, null, false, false,
|
||||||
$uid1
|
$uid1
|
||||||
);
|
);
|
||||||
$bid2 = $bs->addBookmark(
|
$bid2 = $bs->addBookmark(
|
||||||
"http://site1.com", "title2", "description2", 'note', 0,
|
"http://site1.com", "title2", "description2", 'note', 0,
|
||||||
array('tag2', 'tag22', 'tag222'), null, false, false,
|
array('tag2', 'tag22', 'tag222'), null, null, false, false,
|
||||||
$uid2
|
$uid2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class TestBase extends PHPUnit_Framework_TestCase
|
||||||
null,
|
null,
|
||||||
0,
|
0,
|
||||||
array('unittest'),
|
array('unittest'),
|
||||||
null, false, false,
|
null, null, false, false,
|
||||||
$user
|
$user
|
||||||
);
|
);
|
||||||
return $bid;
|
return $bid;
|
||||||
|
|
|
@ -73,7 +73,7 @@ if (is_null($url) || is_null($description)) {
|
||||||
if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId()))
|
if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId()))
|
||||||
$added = false;
|
$added = false;
|
||||||
else
|
else
|
||||||
$added = $bookmarkservice->addBookmark($url, $description, $extended, '', $status, $tags, $dt, true);
|
$added = $bookmarkservice->addBookmark($url, $description, $extended, '', $status, $tags, null, $dt, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the XML file and output the result.
|
// Set up the XML file and output the result.
|
||||||
|
|
|
@ -100,7 +100,7 @@ function startElement($parser, $name, $attrs) {
|
||||||
$bDatetime = gmdate('Y-m-d H:i:s');
|
$bDatetime = gmdate('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, '', $status, $tags, $bDatetime, true, true))
|
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, '', $status, $tags, null, $bDatetime, true, true))
|
||||||
$tplVars['msg'] = T_('Bookmark imported.');
|
$tplVars['msg'] = T_('Bookmark imported.');
|
||||||
else
|
else
|
||||||
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
|
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
|
||||||
|
|
|
@ -102,7 +102,7 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si
|
||||||
$bDatetime = gmdate('Y-m-d H:i:s');
|
$bDatetime = gmdate('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $bPrivateNote, $status, $bCategories, $bDatetime, false, true)) {
|
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $bPrivateNote, $status, $bCategories, null, $bDatetime, false, true)) {
|
||||||
$countImportedBookmarks++;
|
$countImportedBookmarks++;
|
||||||
} else {
|
} else {
|
||||||
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
|
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
|
||||||
|
|
Loading…
Reference in a new issue