Add a persistent 'shorturl' key to all links
All existing link will keep their permalinks. New links will have smallhash generated with date+id. The purpose of this is to avoid collision between links due to their creation date.
This commit is contained in:
parent
c3dfd89959
commit
d592daea83
15 changed files with 115 additions and 91 deletions
tests
|
@ -86,7 +86,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
// Test first link (note link)
|
||||
$link = reset($data['links']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
|
||||
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
|
||||
|
@ -140,7 +140,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(1, count($data['links']));
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,7 +157,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(1, count($data['links']));
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,7 +174,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
// First link is a permalink
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
|
||||
$this->assertContains('Direct link', $link['description']);
|
||||
|
@ -182,7 +182,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
// Second link is a direct link
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals(8, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114633'), $link['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
|
||||
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
|
||||
$this->assertContains('Direct link', $link['description']);
|
||||
|
|
|
@ -191,7 +191,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
'url'=>'http://dum.my',
|
||||
'description'=>'One more',
|
||||
'private'=>0,
|
||||
'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'),
|
||||
'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'),
|
||||
'tags'=>'unit test'
|
||||
);
|
||||
$testDB[$link['id']] = $link;
|
||||
|
@ -447,17 +447,17 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testReorderLinksDesc()
|
||||
{
|
||||
self::$publicLinkDB->reorder('ASC');
|
||||
$linkIdToTest = 42;
|
||||
foreach (self::$publicLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIdToTest, $key);
|
||||
break;
|
||||
self::$privateLinkDB->reorder('ASC');
|
||||
$linkIds = array(42, 4, 1, 0, 7, 6, 8, 41);
|
||||
$cpt = 0;
|
||||
foreach (self::$privateLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIds[$cpt++], $key);
|
||||
}
|
||||
self::$publicLinkDB->reorder('DESC');
|
||||
$linkIdToTest = 41;
|
||||
foreach (self::$publicLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIdToTest, $key);
|
||||
break;
|
||||
self::$privateLinkDB->reorder('DESC');
|
||||
$linkIds = array_reverse($linkIds);
|
||||
$cpt = 0;
|
||||
foreach (self::$privateLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIds[$cpt++], $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 0,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160618_203944'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160618_203944'),
|
||||
'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
|
||||
'url' => 'http://hginit.com/',
|
||||
'description' => '',
|
||||
|
@ -145,7 +145,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 0,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235541'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235541'),
|
||||
'title' => 'Nested 1',
|
||||
'url' => 'http://nest.ed/1',
|
||||
'description' => '',
|
||||
|
@ -158,7 +158,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 1,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235542'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235542'),
|
||||
'title' => 'Nested 1-1',
|
||||
'url' => 'http://nest.ed/1-1',
|
||||
'description' => '',
|
||||
|
@ -171,7 +171,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 2,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235547'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235547'),
|
||||
'title' => 'Nested 1-2',
|
||||
'url' => 'http://nest.ed/1-2',
|
||||
'description' => '',
|
||||
|
@ -184,7 +184,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 3,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'),
|
||||
'title' => 'Nested 2-1',
|
||||
'url' => 'http://nest.ed/2-1',
|
||||
'description' => 'First link of the second section',
|
||||
|
@ -197,7 +197,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 4,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'),
|
||||
'title' => 'Nested 2-2',
|
||||
'url' => 'http://nest.ed/2-2',
|
||||
'description' => 'Second link of the second section',
|
||||
|
@ -210,7 +210,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 5,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'),
|
||||
'title' => 'Nested 3-1',
|
||||
'url' => 'http://nest.ed/3-1',
|
||||
'description' => '',
|
||||
|
@ -223,7 +223,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 6,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'),
|
||||
'title' => 'Nested 3-2',
|
||||
'url' => 'http://nest.ed/3-2',
|
||||
'description' => '',
|
||||
|
@ -236,7 +236,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 7,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160229_111541'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160229_111541'),
|
||||
'title' => 'Nested 2',
|
||||
'url' => 'http://nest.ed/2',
|
||||
'description' => '',
|
||||
|
@ -269,7 +269,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
array(
|
||||
'id' => 0,
|
||||
// Old link - UTC+4 (note that TZ in the import file is ignored).
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'),
|
||||
'title' => 'Secret stuff',
|
||||
'url' => 'https://private.tld',
|
||||
'description' => "Super-secret stuff you're not supposed to know about",
|
||||
|
@ -282,7 +282,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 1,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'),
|
||||
'title' => 'Public stuff',
|
||||
'url' => 'http://public.tld',
|
||||
'description' => '',
|
||||
|
@ -313,7 +313,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
array(
|
||||
'id' => 0,
|
||||
// Note that TZ in the import file is ignored.
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'),
|
||||
'title' => 'Secret stuff',
|
||||
'url' => 'https://private.tld',
|
||||
'description' => "Super-secret stuff you're not supposed to know about",
|
||||
|
@ -326,7 +326,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'id' => 1,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'),
|
||||
'title' => 'Public stuff',
|
||||
'url' => 'http://public.tld',
|
||||
'description' => '',
|
||||
|
|
|
@ -352,20 +352,20 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
|
|||
$this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
|
||||
$this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
|
||||
$this->assertTrue($linkDB[0]['private']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_142300'), $linkDB[0]['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), $linkDB[0]['created']);
|
||||
|
||||
$this->assertTrue(isset($linkDB[1]));
|
||||
$this->assertFalse(isset($linkDB[1]['linkdate']));
|
||||
$this->assertEquals(1, $linkDB[1]['id']);
|
||||
$this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_172539'), $linkDB[1]['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), $linkDB[1]['created']);
|
||||
|
||||
$this->assertTrue(isset($linkDB[2]));
|
||||
$this->assertFalse(isset($linkDB[2]['linkdate']));
|
||||
$this->assertEquals(2, $linkDB[2]['id']);
|
||||
$this->assertEquals('Geek and Poke', $linkDB[2]['title']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_182539'), $linkDB[2]['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_190301'), $linkDB[2]['updated']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), $linkDB[2]['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'), $linkDB[2]['updated']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,8 +52,9 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
|
|||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'id' => 12,
|
||||
'url' => $str,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -66,7 +67,14 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
// plugin data
|
||||
$this->assertEquals(1, count($data['plugin_end_zone']));
|
||||
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date));
|
||||
$this->assertNotFalse(strpos(
|
||||
$data['plugin_end_zone'][0],
|
||||
'data-isso-id="'. $data['links'][0]['id'] .'"'
|
||||
));
|
||||
$this->assertNotFalse(strpos(
|
||||
$data['plugin_end_zone'][0],
|
||||
'data-title="'. $data['links'][0]['id'] .'"'
|
||||
));
|
||||
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
|
||||
}
|
||||
|
||||
|
@ -85,12 +93,14 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
|
|||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'id' => 12,
|
||||
'url' => $str,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date1),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1),
|
||||
),
|
||||
array(
|
||||
'id' => 13,
|
||||
'url' => $str . '2',
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date2),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -114,8 +124,9 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
|
|||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'id' => 12,
|
||||
'url' => $str,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date),
|
||||
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
|
||||
)
|
||||
),
|
||||
'search_term' => $str
|
||||
|
|
|
@ -21,7 +21,7 @@ class ReferenceLinkDB
|
|||
'?WDWyig',
|
||||
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20150310_114651'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'),
|
||||
'sTuff',
|
||||
null,
|
||||
'WDWyig'
|
||||
|
@ -33,7 +33,7 @@ class ReferenceLinkDB
|
|||
'?WDWyig',
|
||||
'Used to test links reordering.',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20100310_101010'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100310_101010'),
|
||||
'ut'
|
||||
);
|
||||
|
||||
|
@ -43,9 +43,9 @@ class ReferenceLinkDB
|
|||
'https://static.fsf.org/nosvn/faif-2.0.pdf',
|
||||
'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20150310_114633'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'),
|
||||
'free gnu software stallman -exclude stuff hashtag',
|
||||
DateTime::createFromFormat('Ymd_His', '20160803_093033')
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
|
@ -54,7 +54,7 @@ class ReferenceLinkDB
|
|||
'http://mediagoblin.org/',
|
||||
'A free software media publishing platform #hashtagOther',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20130614_184135'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
|
||||
'gnu media web .hidden hashtag',
|
||||
null,
|
||||
'IuWvgA'
|
||||
|
@ -66,7 +66,7 @@ class ReferenceLinkDB
|
|||
'https://dvcs.w3.org/hg/markup-validator/summary',
|
||||
'Mercurial repository for the W3C Validator #private',
|
||||
1,
|
||||
DateTime::createFromFormat('Ymd_His', '20141125_084734'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20141125_084734'),
|
||||
'css html w3c web Mercurial'
|
||||
);
|
||||
|
||||
|
@ -76,7 +76,7 @@ class ReferenceLinkDB
|
|||
'http://ars.userfriendly.org/cartoons/?id=20121206',
|
||||
'Naming conventions... #private',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20121206_142300'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'),
|
||||
'dev cartoon web'
|
||||
);
|
||||
|
||||
|
@ -86,7 +86,7 @@ class ReferenceLinkDB
|
|||
'http://ars.userfriendly.org/cartoons/?id=20010306',
|
||||
'Tropical printing',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20121206_172539'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'),
|
||||
'samba cartoon web'
|
||||
);
|
||||
|
||||
|
@ -96,7 +96,7 @@ class ReferenceLinkDB
|
|||
'http://geek-and-poke.com/',
|
||||
'',
|
||||
1,
|
||||
DateTime::createFromFormat('Ymd_His', '20121206_182539'),
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'),
|
||||
'dev cartoon tag1 tag2 tag3 tag4 '
|
||||
);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class ReferenceLinkDB
|
|||
'tags' => $tags,
|
||||
'created' => $date,
|
||||
'updated' => $updated,
|
||||
'shorturl' => $shorturl ? $shorturl : smallHash($date->format('Ymd_His') . $id),
|
||||
'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id),
|
||||
);
|
||||
$this->_links[$id] = $link;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue