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.
This commit is contained in:
parent
ca28140107
commit
7d56f1cd19
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user