]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/YammerImport/lib/yammerimporter.php
Merge remote-tracking branch 'upstream/master'
[quix0rs-gnu-social.git] / plugins / YammerImport / lib / yammerimporter.php
index ffc88ab4739a980d3d1860c59699426102f114bc..abd41dd99e271028e44acdf54d1524e5fd8e6695 100644 (file)
@@ -20,6 +20,8 @@
 /**
  * Basic client class for Yammer's OAuth/JSON API.
  *
+ * Depends on Favorite plugin
+ *
  * @package YammerImportPlugin
  * @author Brion Vibber <brion@status.net>
  */
@@ -27,7 +29,7 @@ class YammerImporter
 {
     protected $client;
 
-    function __construct(SN_YammerClient $client)
+    function __construct(SNYammerClient $client)
     {
         $this->client = $client;
     }
@@ -45,11 +47,12 @@ class YammerImporter
 
         $profileId = $this->findImportedUser($data['orig_id']);
         if ($profileId) {
-            return Profile::staticGet('id', $profileId);
+            return Profile::getKV('id', $profileId);
         } else {
-            $user = User::staticGet('nickname', $nickname);
-            if ($user) {
-                common_log(LOG_WARN, "Copying Yammer profile info onto existing user $nickname");
+            $user = User::getKV('nickname', $nickname);
+
+            if ($user instanceof User) {
+                common_log(LOG_WARNING, "Copying Yammer profile info onto existing user $nickname");
                 $profile = $user->getProfile();
                 $this->savePropertiesOn($profile, $data['options'],
                         array('fullname', 'homepage', 'bio', 'location'));
@@ -57,6 +60,7 @@ class YammerImporter
                 $user = User::register($data['options']);
                 $profile = $user->getProfile();
             }
+
             if ($data['avatar']) {
                 try {
                     $this->saveAvatar($data['avatar'], $profile);
@@ -82,12 +86,12 @@ class YammerImporter
 
         $groupId = $this->findImportedGroup($data['orig_id']);
         if ($groupId) {
-            return User_group::staticGet('id', $groupId);
+            return User_group::getKV('id', $groupId);
         } else {
-            $local = Local_group::staticGet('nickname', $nickname);
+            $local = Local_group::getKV('nickname', $nickname);
             if ($local) {
-                common_log(LOG_WARN, "Copying Yammer group info onto existing group $nickname");
-                $group = User_group::staticGet('id', $local->group_id);
+                common_log(LOG_WARNING, "Copying Yammer group info onto existing group $nickname");
+                $group = User_group::getKV('id', $local->group_id);
                 $this->savePropertiesOn($group, $data['options'],
                         array('fullname', 'description'));
             } else {
@@ -130,11 +134,11 @@ class YammerImporter
 
         $noticeId = $this->findImportedNotice($data['orig_id']);
         if ($noticeId) {
-            return Notice::staticGet('id', $noticeId);
+            return Notice::getKV('id', $noticeId);
         } else {
-            $notice = Notice::staticGet('uri', $data['options']['uri']);
+            $notice = Notice::getKV('uri', $data['options']['uri']);
             $content = $data['content'];
-            $user = User::staticGet($data['profile']);
+            $user = User::getKV($data['profile']);
 
             // Fetch file attachments and add the URLs...
             $uploads = array();
@@ -156,9 +160,14 @@ class YammerImporter
 
             // Save "likes" as favorites...
             foreach ($data['faves'] as $nickname) {
-                $user = User::staticGet('nickname', $nickname);
-                if ($user) {
-                    Fave::addNew($user->getProfile(), $notice);
+                $user = User::getKV('nickname', $nickname);
+                if ($user instanceof User) {
+                    try {
+                        Fave::addNew($user->getProfile(), $notice);
+                    } catch (Exception $e) {
+                        // failed, let's move to the next
+                        common_debug('YammerImport failed favoriting a notice: '.$e->getMessage());
+                    }
                 }
             }
 
@@ -331,8 +340,8 @@ class YammerImporter
                 $options['groups'] = array($groupId);
 
                 // @fixme if we see a group link inline, don't add this?
-                $group = User_group::staticGet('id', $groupId);
-                if ($group) {
+                $group = User_group::getKV('id', $groupId);
+                if ($group instanceof User_group) {
                     $content .= ' !' . $group->nickname;
                 }
             }
@@ -365,19 +374,19 @@ class YammerImporter
 
     private function findImportedUser($origId)
     {
-        $map = Yammer_user::staticGet('id', $origId);
+        $map = Yammer_user::getKV('id', $origId);
         return $map ? $map->user_id : null;
     }
 
     private function findImportedGroup($origId)
     {
-        $map = Yammer_group::staticGet('id', $origId);
+        $map = Yammer_group::getKV('id', $origId);
         return $map ? $map->group_id : null;
     }
 
     private function findImportedNotice($origId)
     {
-        $map = Yammer_notice::staticGet('id', $origId);
+        $map = Yammer_notice::getKV('id', $origId);
         return $map ? $map->notice_id : null;
     }
 
@@ -440,7 +449,7 @@ class YammerImporter
 
         // @fixme this should be better encapsulated
         // ripped from oauthstore.php (for old OMB client)
-        $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
+        $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar');
         try {
             if (!copy($url, $temp_filename)) {
                 // TRANS: Server exception thrown when an avatar could not be fetched.
@@ -492,7 +501,7 @@ class YammerImporter
         $temp = tmpfile();
         fwrite($temp, $body);
         try {
-            $upload = MediaFile::fromFileHandle($temp, $user);
+            $upload = MediaFile::fromFilehandle($temp, $user->getProfile());
             fclose($temp);
             return $upload;
         } catch (Exception $e) {