]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Break up delicious import into a queue manager by bookmark
authorEvan Prodromou <evan@status.net>
Tue, 21 Dec 2010 16:09:01 +0000 (11:09 -0500)
committerEvan Prodromou <evan@status.net>
Tue, 21 Dec 2010 16:09:01 +0000 (11:09 -0500)
plugins/Bookmark/BookmarkPlugin.php
plugins/Bookmark/deliciousbackupimporter.php
plugins/Bookmark/deliciousbookmarkimporter.php [new file with mode: 0644]
plugins/Bookmark/importbookmarks.php

index 900dc7651bf12e46dfa985a398655828a9d1f2ec..6bd38a8c129c64a3011e24b31457e1821b80cfb0 100644 (file)
@@ -134,6 +134,7 @@ class BookmarkPlugin extends Plugin
             return false;
         case 'BookmarkForm':
         case 'DeliciousBackupImporter':
+        case 'DeliciousBookmarkImporter':
             include_once $dir.'/'.strtolower($cls).'.php';
             return false;
         default:
@@ -286,6 +287,13 @@ class BookmarkPlugin extends Plugin
         return true;
     }
 
+    function onEndInitializeQueueManager($qm)
+    {
+        $qm->connect('dlcsback', 'DeliciousBackupImporter');
+        $qm->connect('dlcsbkmk', 'DeliciousBookmarkImporter');
+        return true;
+    }
+
     /**
      * Plugin version data
      *
index 6ab87b5212a4931f6eba0055a9ab0d46d2f51d66..01b996bbe534df1103db8d9725a7bfa7bed712f6 100644 (file)
@@ -34,8 +34,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/apiauth.php';
-
 /**
  * Importer class for Delicious bookmarks
  *
@@ -47,8 +45,19 @@ require_once INSTALLDIR . '/lib/apiauth.php';
  * @link      http://status.net/
  */
 
-class DeliciousBackupImporter
+class DeliciousBackupImporter extends QueueHandler
 {
+    /**
+     * Transport of the importer
+     *
+     * @return string transport string
+     */
+
+    function transport()
+    {
+        return 'dlcsback';
+    }
+
     /**
      * Import an in-memory bookmark list to a user's account
      *
@@ -59,14 +68,15 @@ class DeliciousBackupImporter
      * a bunch of <dt>'s, occasionally with <dd>'s.
      * There are sometimes <p>'s lost inside.
      *
-     * @param User   $user User whose feed we're going to fill
-     * @param string $body Body of the file
+     * @param array $data pair of user, text
      *
-     * @return void
+     * @return boolean success value
      */
 
-    function importBookmarks($user, $body)
+    function handle($data)
     {
+        list($user, $body) = $data;
+
         $doc = $this->importHTML($body);
 
         $dls = $doc->getElementsByTagName('dl');
@@ -117,6 +127,8 @@ class DeliciousBackupImporter
                 $dt = $dd = null;
             }
         }
+
+        return true;
     }
 
     /**
@@ -152,40 +164,9 @@ class DeliciousBackupImporter
             }
         }
 
-        $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));
-
-        $saved = Notice_bookmark::saveNew($user,
-                                          $title,
-                                          $url,
-                                          $tags,
-                                          $description,
-                                          array('created' => $created));
-
-        return $saved;
+        $qm = QueueManager::get();
+        
+        $qm->enqueue(array($user, $dt, $dd), 'dlcsbkmk');
     }
 
     /**
diff --git a/plugins/Bookmark/deliciousbookmarkimporter.php b/plugins/Bookmark/deliciousbookmarkimporter.php
new file mode 100644 (file)
index 0000000..686e1a3
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * Importer class for Delicious.com bookmarks
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Bookmark
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Importer class for Delicious bookmarks
+ *
+ * @category  Bookmark
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+class DeliciousBookmarkImporter extends QueueHandler
+{
+    /**
+     * Return the transport for this queue handler
+     *
+     * @return string 'dlcsbkmk'
+     */
+
+    function transport()
+    {
+        return 'dlcsbkmk';
+    }
+
+    /**
+     * Handle the data
+     * 
+     * @param array $data array of user, dt, dd
+     *
+     * @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));
+
+        $saved = Notice_bookmark::saveNew($user,
+                                          $title,
+                                          $url,
+                                          $tags,
+                                          $description,
+                                          array('created' => $created));
+
+        return true;
+    }
+}
index 991329dd6d37d724e248a084a276aa234c0d022f..5518b00e9748a6f6e2bd9d41368d0e327223df4c 100644 (file)
@@ -83,13 +83,12 @@ function getBookmarksFile()
 }
 
 try {
-    $dbi = new DeliciousBackupImporter();
-
     $user = getUser();
-
     $html = getBookmarksFile();
 
-    $dbi->importBookmarks($user, $html);
+    $qm = QueueManager::get();
+    
+    $qm->enqueue(array($user, $html), 'dlcsback');
 
 } catch (Exception $e) {
     print $e->getMessage()."\n";