]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Some fixes from debugging of bookmark plugin URI foramt
authorEvan Prodromou <evan@status.net>
Mon, 27 Dec 2010 05:11:27 +0000 (21:11 -0800)
committerEvan Prodromou <evan@status.net>
Mon, 27 Dec 2010 05:11:27 +0000 (21:11 -0800)
Tightened up the URI format, fixed some auto-loading issues,
and forced the url_crc32 column to be unsigned.

plugins/Bookmark/Bookmark.php
plugins/Bookmark/BookmarkPlugin.php

index aa9e9af43b96b799542fd4174220e0bbb31a22e7..c3394c542b8a810efde088fdea7253720e7ae00b 100644 (file)
@@ -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();
index 01dd6f1eaae87a60c658ccf7e60a417b4af7a22a..53121276b1f0cb874ce988631c4c41711fd663a1 100644 (file)
@@ -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;
     }