From 7d56f1cd193eab9ce85b4f62059a7a0975bdc1f9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Dec 2010 21:11:27 -0800 Subject: [PATCH] Some fixes from debugging of bookmark plugin URI foramt Tightened up the URI format, fixed some auto-loading issues, and forced the url_crc32 column to be unsigned. --- plugins/Bookmark/Bookmark.php | 37 +++++++++++++++++++++++++---- plugins/Bookmark/BookmarkPlugin.php | 7 +++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/plugins/Bookmark/Bookmark.php b/plugins/Bookmark/Bookmark.php index aa9e9af43b..c3394c542b 100644 --- a/plugins/Bookmark/Bookmark.php +++ b/plugins/Bookmark/Bookmark.php @@ -71,6 +71,24 @@ class Bookmark extends Memcached_DataObject return Memcached_DataObject::staticGet('Bookmark', $k, $v); } + /** + * Get an instance by compound key + * + * This is a utility method to get a single instance with a given set of + * key-value pairs. Usually used for the primary key for a compound key; thus + * the name. + * + * @param array $kv array of key-value mappings + * + * @return Bookmark object found, or null for no hits + * + */ + + function pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Bookmark', $kv); + } + /** * return table definition for DB_DataObject * @@ -219,21 +237,32 @@ class Bookmark extends Memcached_DataObject $nb->title = $title; $nb->description = $description; $nb->url_crc32 = crc32($nb->url); - $nb->created = common_sql_now(); + + if (array_key_exists('created', $options)) { + $nb->created = $options['created']; + } else { + $nb->created = common_sql_now(); + } if (array_key_exists('uri', $options)) { $nb->uri = $options['uri']; } else { - $dt = new DateTime($nb->created); + $dt = new DateTime($nb->created, new DateTimeZone('UTC')); + // I posit that it's sufficiently impossible // for the same user to generate two CRC-32-clashing // URLs in the same second that this is a safe unique identifier. // If you find a real counterexample, contact me at acct:evan@status.net // and I will publicly apologize for my hubris. + + $created = $dt->format('YmdHis'); + + $crc32 = sprintf('%08x', $nb->url_crc32); + $nb->uri = common_local_url('showbookmark', array('user' => $profile->id, - 'created' => $dt->format(DateTime::W3C), - 'crc32' => sprintf('%08x', $nb->url_crc32))); + 'created' => $created, + 'crc32' => $crc32)); } $nb->insert(); diff --git a/plugins/Bookmark/BookmarkPlugin.php b/plugins/Bookmark/BookmarkPlugin.php index 01dd6f1eaa..53121276b1 100644 --- a/plugins/Bookmark/BookmarkPlugin.php +++ b/plugins/Bookmark/BookmarkPlugin.php @@ -85,7 +85,7 @@ class BookmarkPlugin extends Plugin false, 'UNI'), new ColumnDef('url_crc32', - 'integer', + 'integer unsigned', null, false, 'MUL'), @@ -154,6 +154,7 @@ class BookmarkPlugin extends Plugin switch ($cls) { + case 'ShowbookmarkAction': case 'NewbookmarkAction': case 'BookmarkpopupAction': include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; @@ -190,8 +191,8 @@ class BookmarkPlugin extends Plugin $m->connect('bookmark/:user/:created/:crc32', array('action' => 'showbookmark'), array('user' => '[0-9]+', - 'created' => '[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z', - 'crc32' => '[0-9A-F]{8}')); + 'created' => '[0-9]{14}', + 'crc32' => '[0-9a-f]{8}')); return true; }