]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Bookmark plugin: fix for delicious import with queues enabled
authorBrion Vibber <brion@pobox.com>
Fri, 31 Dec 2010 20:33:51 +0000 (12:33 -0800)
committerBrion Vibber <brion@pobox.com>
Fri, 31 Dec 2010 20:33:51 +0000 (12:33 -0800)
We were passing DOM nodes directly into the queues for the final bookmark import stage; unfortunately these don't actually survive serialization.
Moved the extraction of properties from the HTML up to the first-stage handler, so now we don't have to worry about moving DOM nodes from one handler to the next. Instead passing an associative array of properties, which is fed into the Bookmark::saveNew by the per-bookmark handler.

plugins/Bookmark/deliciousbackupimporter.php
plugins/Bookmark/deliciousbookmarkimporter.php

index bc5a91be8072c11c13ab4b74970d61c836884c98..197c7a143bc18af208782ca91c5e82af87858e7a 100644 (file)
@@ -162,9 +162,38 @@ class DeliciousBackupImporter extends QueueHandler
 
     function importBookmark($user, $dt, $dd = null)
     {
+        $as = $dt->getElementsByTagName('a');
+
+        if ($as->length == 0) {
+            throw new ClientException(_("No <A> tag in a <DT>."));
+        }
+
+        $a = $as->item(0);
+
+        $private = $a->getAttribute('private');
+
+        if ($private != 0) {
+            throw new ClientException(_('Skipping private bookmark.'));
+        }
+
+        if (!empty($dd)) {
+            $description = $dd->nodeValue;
+        } else {
+            $description = null;
+        }
+        $addDate = $a->getAttribute('add_date');
+
+        $data = array(
+            'profile_id' => $user->id,
+            'title' => $a->nodeValue,
+            'description' => $description,
+            'url' => $a->getAttribute('href'),
+            'tags' => $a->getAttribute('tags'),
+            'created' => common_sql_date(intval($addDate))
+        );
+
         $qm = QueueManager::get();
-        
-        $qm->enqueue(array($user, $dt, $dd), 'dlcsbkmk');
+        $qm->enqueue($data, 'dlcsbkmk');
     }
 
     /**
index 545c336860e769721e147a8f28ba88117bd3e0de..018239f49d6be341edc6cbfd065820c64fcf463a 100644 (file)
@@ -61,52 +61,26 @@ class DeliciousBookmarkImporter extends QueueHandler
     /**
      * Handle the data
      * 
-     * @param array $data array of user, dt, dd
+     * @param array $data associative array of user & bookmark info from DeliciousBackupImporter::importBookmark()
      *
      * @return boolean success value
      */
 
     function handle($data)
     {
-        list($user, $dt, $dd) = $data;
-
-        $as = $dt->getElementsByTagName('a');
-
-        if ($as->length == 0) {
-            throw new ClientException(_("No <A> tag in a <DT>."));
-        }
-
-        $a = $as->item(0);
-                    
-        $private = $a->getAttribute('private');
-
-        if ($private != 0) {
-            throw new ClientException(_('Skipping private bookmark.'));
-        }
-
-        if (!empty($dd)) {
-            $description = $dd->nodeValue;
-        } else {
-            $description = null;
-        }
-
-        $title   = $a->nodeValue;
-        $url     = $a->getAttribute('href');
-        $tags    = $a->getAttribute('tags');
-        $addDate = $a->getAttribute('add_date');
-        $created = common_sql_date(intval($addDate));
+        $profile = Profile::staticGet('id', $data['profile_id']);
 
         try {
-            $saved = Bookmark::saveNew($user->getProfile(),
-                                       $title,
-                                       $url,
-                                       $tags,
-                                       $description,
-                                       array('created' => $created,
+            $saved = Bookmark::saveNew($profile,
+                                       $data['title'],
+                                       $data['url'],
+                                       $data['tags'],
+                                       $data['description'],
+                                       array('created' => $data['created'],
                                              'distribute' => false));
         } catch (ClientException $e) {
             // Most likely a duplicate -- continue on with the rest!
-            common_log(LOG_ERR, "Error importing delicious bookmark to $url: " . $e->getMessage());
+            common_log(LOG_ERR, "Error importing delicious bookmark to $data[url]: " . $e->getMessage());
             return true;
         }