forked from GNUsocial/gnu-social
Add JSON output for backups
Conflicts: lib/useractivitystream.php
This commit is contained in:
parent
ea8151688e
commit
1c1bcd7cc6
@ -75,61 +75,107 @@ class UserActivityStream extends AtomUserNoticeFeed
|
|||||||
|
|
||||||
$objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
|
$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
|
// Sort by create date
|
||||||
|
|
||||||
usort($objs, 'UserActivityStream::compareObject');
|
usort($objs, 'UserActivityStream::compareObject');
|
||||||
|
|
||||||
// We'll keep these around for later, and interleave them into
|
// We'll keep these around for later, and interleave them into
|
||||||
// the output stream with the user's notices.
|
// the output stream with the user's notices.
|
||||||
foreach ($objs as $obj) {
|
|
||||||
try {
|
$this->objs = $objs;
|
||||||
$this->activities[] = $obj->asActivity();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
// Continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interleave the pre-sorted subs/groups/faves with the user's
|
* Interleave the pre-sorted subs/groups/faves with the user's
|
||||||
* notices, all in reverse chron order.
|
* notices, all in reverse chron order.
|
||||||
*/
|
*/
|
||||||
function renderEntries()
|
function renderEntries($format=Feed::ATOM, $handle=null)
|
||||||
{
|
{
|
||||||
$end = time() + 1;
|
$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;
|
$start = $act->time;
|
||||||
|
|
||||||
if ($this->outputMode == self::OUTPUT_RAW && $start != $end) {
|
if ($this->outputMode == self::OUTPUT_RAW && $start != $end) {
|
||||||
// In raw mode, we haven't pre-fetched notices.
|
// In raw mode, we haven't pre-fetched notices.
|
||||||
// Grab the chunks of notices between other activities.
|
// Grab the chunks of notices between other activities.
|
||||||
$notices = $this->getNoticesBetween($start, $end);
|
try {
|
||||||
foreach ($notices as $noticeAct) {
|
$notices = $this->getNoticesBetween($start, $end);
|
||||||
try {
|
foreach ($notices as $noticeAct) {
|
||||||
$nact = $noticeAct->asActivity();
|
try {
|
||||||
$nact->outputTo($this, false, false);
|
$nact = $noticeAct->asActivity();
|
||||||
} catch (Exception $e) {
|
if ($format == Feed::ATOM) {
|
||||||
// Continue
|
$nact->outputTo($this, false, false);
|
||||||
|
} else {
|
||||||
|
fwrite($handle, json_encode($nact->asArray()));
|
||||||
|
}
|
||||||
|
} 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
|
$notices = null;
|
||||||
$act->outputTo($this, false, ($act->actor->id != $this->user->uri));
|
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 {
|
||||||
|
fwrite($handle, json_encode($act->asArray()));
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_ERR, $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$act = null;
|
||||||
|
unset($act);
|
||||||
|
|
||||||
$end = $start;
|
$end = $start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->outputMode == self::OUTPUT_RAW) {
|
if ($this->outputMode == self::OUTPUT_RAW) {
|
||||||
// Grab anything after the last pre-sorted activity.
|
// Grab anything after the last pre-sorted activity.
|
||||||
$notices = $this->getNoticesBetween(0, $end);
|
try {
|
||||||
foreach ($notices as $noticeAct) {
|
$notices = $this->getNoticesBetween(0, $end);
|
||||||
try {
|
foreach ($notices as $noticeAct) {
|
||||||
$nact = $noticeAct->asActivity();
|
try {
|
||||||
$nact->outputTo($this, false, false);
|
$nact = $noticeAct->asActivity();
|
||||||
} catch (Exception $e) {
|
if ($format == Feed::ATOM) {
|
||||||
// Continue
|
$nact->outputTo($this, false, false);
|
||||||
|
} else {
|
||||||
|
fwrite($handle, json_encode($nact->asArray()));
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_ERR, $e->getMessage());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_ERR, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,4 +298,12 @@ class UserActivityStream extends AtomUserNoticeFeed
|
|||||||
|
|
||||||
return $groups;
|
return $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeJSON($handle)
|
||||||
|
{
|
||||||
|
require_once INSTALLDIR.'/lib/activitystreamjsondocument.php';
|
||||||
|
fwrite($handle, '{"items": [');
|
||||||
|
$this->renderEntries(Feed::JSON, $handle);
|
||||||
|
fwrite($handle, ']');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
||||||
|
|
||||||
$shortoptions = 'i:n:f:';
|
$shortoptions = 'i:n:f:j';
|
||||||
$longoptions = array('id=', 'nickname=', 'file=');
|
$longoptions = array('id=', 'nickname=', 'file=', 'json');
|
||||||
|
|
||||||
$helptext = <<<END_OF_EXPORTACTIVITYSTREAM_HELP
|
$helptext = <<<END_OF_EXPORTACTIVITYSTREAM_HELP
|
||||||
exportactivitystream.php [options]
|
exportactivitystream.php [options]
|
||||||
@ -28,7 +28,7 @@ Export a StatusNet user history to a file
|
|||||||
|
|
||||||
-i --id ID of user to export
|
-i --id ID of user to export
|
||||||
-n --nickname nickname of the 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;
|
END_OF_EXPORTACTIVITYSTREAM_HELP;
|
||||||
|
|
||||||
@ -37,7 +37,11 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
|
|||||||
try {
|
try {
|
||||||
$user = getUser();
|
$user = getUser();
|
||||||
$actstr = new UserActivityStream($user, true, UserActivityStream::OUTPUT_RAW);
|
$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) {
|
} catch (Exception $e) {
|
||||||
print $e->getMessage()."\n";
|
print $e->getMessage()."\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user