]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Bookmark/deliciousbookmarkimporter.php
Merge branch '1.1.x'
[quix0rs-gnu-social.git] / plugins / Bookmark / deliciousbookmarkimporter.php
index 545c336860e769721e147a8f28ba88117bd3e0de..4065fc308593ebc1d55330788d43799fd62e0350 100644 (file)
@@ -4,7 +4,7 @@
  * 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
@@ -44,7 +44,6 @@ if (!defined('STATUSNET')) {
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  * @link      http://status.net/
  */
-
 class DeliciousBookmarkImporter extends QueueHandler
 {
     /**
@@ -52,7 +51,6 @@ class DeliciousBookmarkImporter extends QueueHandler
      *
      * @return string 'dlcsbkmk'
      */
-
     function transport()
     {
         return 'dlcsbkmk';
@@ -60,54 +58,34 @@ 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) {
+        } catch (ClientException $ce) {
             // 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]: " . $ce->getMessage());
             return true;
+        } catch (Exception $ex) {
+            if (preg_match("/DB Error: already exists/", $ex->getMessage())) {
+                common_log(LOG_ERR, "Error importing delicious bookmark to $data[url]: " . $ce->getMessage());
+                return true;
+            } else {
+                throw $ex;
+            }
         }
 
         return true;