]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.1.x' of gitorious.org:statusnet/mainline into 1.1.x
authorEvan Prodromou <evan@e14n.com>
Sun, 2 Jun 2013 18:29:40 +0000 (14:29 -0400)
committerEvan Prodromou <evan@e14n.com>
Sun, 2 Jun 2013 18:29:40 +0000 (14:29 -0400)
Conflicts:
lib/useractivitystream.php

classes/Fave.php
lib/profilenoticestream.php
lib/useractivitystream.php
scripts/backupuser.php

index 59a1e00318c2dfe8cf94ee15c5123fde0dd1f0b5..455e7b089cee57f44ede339cbe8ecab8f5127564 100644 (file)
@@ -124,9 +124,18 @@ class Fave extends Managed_DataObject
 
     function asActivity()
     {
-        $notice  = Notice::staticGet('id', $this->notice_id);
+        $notice = Notice::staticGet('id', $this->notice_id);
+
+        if (!$notice) {
+            throw new Exception("Fave for non-existent notice: " . $this->notice_id);
+        }
+
         $profile = Profile::staticGet('id', $this->user_id);
 
+        if (!$profile) {
+            throw new Exception("Fave by non-existent profile: " . $this->user_id);
+        }
+
         $act = new Activity();
 
         $act->verb = ActivityVerb::FAVORITE;
index f7154a52be9563ae3bc90551ee370838ae84771d..0cf088a7020198d9f5ea1491d2b08967cac155f6 100644 (file)
@@ -62,7 +62,7 @@ class ProfileNoticeStream extends ScopingNoticeStream
                             $userProfile);
     }
 
-    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    function getNoticeIds($offset, $limit, $sinceId = null, $maxId = null)
     {
         if ($this->impossibleStream()) {
             return array();
index df4f2187edc420eccbbeca5c643b34692ad8d802..5422afc2c0a89c434e06c8c114678c0fe3df955b 100644 (file)
@@ -75,61 +75,121 @@ class UserActivityStream extends AtomUserNoticeFeed
 
         $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
 
+        $subscriptions = null;
+        $subscribers   = null;
+        $groups        = null;
+        $faves         = null;
+
+        unset($subscriptions);
+        unset($subscribers);
+        unset($groups);
+        unset($faves);
+
         // Sort by create date
 
         usort($objs, 'UserActivityStream::compareObject');
 
         // We'll keep these around for later, and interleave them into
         // the output stream with the user's notices.
-        foreach ($objs as $obj) {
-            try {
-                $this->activities[] = $obj->asActivity();
-            } catch (Exception $e) {
-                // Continue
-            }
-        }
+
+        $this->objs = $objs;
     }
 
     /**
      * Interleave the pre-sorted subs/groups/faves with the user's
      * notices, all in reverse chron order.
      */
-    function renderEntries()
+    function renderEntries($format=Feed::ATOM, $handle=null)
     {
+        $haveOne = false;
+
         $end = time() + 1;
-        foreach ($this->activities as $act) {
+        foreach ($this->objs as $obj) {
+            try {
+                $act = $obj->asActivity();
+            } catch (Exception $e) {
+                common_log(LOG_ERR, $e->getMessage());
+                continue;
+            }
+
             $start = $act->time;
 
             if ($this->outputMode == self::OUTPUT_RAW && $start != $end) {
                 // In raw mode, we haven't pre-fetched notices.
                 // Grab the chunks of notices between other activities.
-                $notices = $this->getNoticesBetween($start, $end);
-                foreach ($notices as $noticeAct) {
-                    try {
-                        $nact = $noticeAct->asActivity();
-                        $nact->outputTo($this, false, false);
-                    } catch (Exception $e) {
-                        // Continue
+                try {
+                    $notices = $this->getNoticesBetween($start, $end);
+                    foreach ($notices as $noticeAct) {
+                        try {
+                            $nact = $noticeAct->asActivity();
+                            if ($format == Feed::ATOM) {
+                                $nact->outputTo($this, false, false);
+                            } else {
+                                if ($haveOne) {
+                                    fwrite($handle, ",");
+                                }
+                                fwrite($handle, json_encode($nact->asArray()));
+                                $haveOne = true;
+                            }
+                        } catch (Exception $e) {
+                            common_log(LOG_ERR, $e->getMessage());
+                            continue;
+                        }
+                        $nact = null;
+                        unset($nact);
                     }
+                } catch (Exception $e) {
+                    common_log(LOG_ERR, $e->getMessage());
                 }
             }
 
-            // Only show the author sub-element if it's different from default user
-            $act->outputTo($this, false, ($act->actor->id != $this->user->uri));
+            $notices = null;
+            unset($notices);
+
+            try {
+                if ($format == Feed::ATOM) {
+                    // Only show the author sub-element if it's different from default user
+                    $act->outputTo($this, false, ($act->actor->id != $this->user->uri));
+                } else {
+                    if ($haveOne) {
+                        fwrite($handle, ",");
+                    }
+                    fwrite($handle, json_encode($act->asArray()));
+                    $haveOne = true;
+                }
+            } catch (Exception $e) {
+                common_log(LOG_ERR, $e->getMessage());
+            }
+
+            $act = null;
+            unset($act);
 
             $end = $start;
         }
 
         if ($this->outputMode == self::OUTPUT_RAW) {
             // Grab anything after the last pre-sorted activity.
-            $notices = $this->getNoticesBetween(0, $end);
-            foreach ($notices as $noticeAct) {
-                try {
-                    $nact = $noticeAct->asActivity();
-                    $nact->outputTo($this, false, false);
-                } catch (Exception $e) {
-                    // Continue
+            try {
+                $notices = $this->getNoticesBetween(0, $end);
+                foreach ($notices as $noticeAct) {
+                    try {
+                        $nact = $noticeAct->asActivity();
+                        if ($format == Feed::ATOM) {
+                            $nact->outputTo($this, false, false);
+                        } else {
+                            if ($haveOne) {
+                                fwrite($handle, ",");
+                            }
+                            fwrite($handle, json_encode($nact->asArray()));
+                            $haveOne = true;
+                        }
+                    } catch (Exception $e) {
+                        common_log(LOG_ERR, $e->getMessage());
+                        continue;
+                    }
                 }
+            } catch (Exception $e) {
+                common_log(LOG_ERR, $e->getMessage());
             }
         }
     }
@@ -252,4 +312,12 @@ class UserActivityStream extends AtomUserNoticeFeed
 
         return $groups;
     }
+
+    function writeJSON($handle)
+    {
+        require_once INSTALLDIR.'/lib/activitystreamjsondocument.php';
+        fwrite($handle, '{"items": [');
+        $this->renderEntries(Feed::JSON, $handle);
+        fwrite($handle, ']}');
+    }
 }
index ee2951fc8f146609dfb8cfdbcea071e96202666c..d183dba2b9b633667c9fef43d89d94c87d903ce9 100644 (file)
@@ -19,8 +19,8 @@
 
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 
-$shortoptions = 'i:n:f:';
-$longoptions = array('id=', 'nickname=', 'file=');
+$shortoptions = 'i:n:f:j';
+$longoptions = array('id=', 'nickname=', 'file=', 'json');
 
 $helptext = <<<END_OF_EXPORTACTIVITYSTREAM_HELP
 exportactivitystream.php [options]
@@ -28,7 +28,7 @@ Export a StatusNet user history to a file
 
   -i --id       ID of user to export
   -n --nickname nickname of the user to export
-  -f --file     file to export to (default STDOUT)
+  -j --json     Output JSON (default Atom)
 
 END_OF_EXPORTACTIVITYSTREAM_HELP;
 
@@ -37,7 +37,11 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
 try {
     $user = getUser();
     $actstr = new UserActivityStream($user, true, UserActivityStream::OUTPUT_RAW);
-    print $actstr->getString();
+    if (have_option('j', 'json')) {
+        $actstr->writeJSON(STDOUT);
+    } else {
+        print $actstr->getString();
+    }
 } catch (Exception $e) {
     print $e->getMessage()."\n";
     exit(1);