We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit f30744c7 authored by Brion Vibber's avatar Brion Vibber

refactor for multi....

parent f7b431d6
...@@ -31,21 +31,6 @@ END_OF_HELP; ...@@ -31,21 +31,6 @@ END_OF_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc'; require_once INSTALLDIR.'/scripts/commandline.inc';
if (empty($args[0]) || !Validate::uri($args[0])) {
print "$helptext";
exit(1);
}
$uri = $args[0];
$oprofile = Ostatus_profile::staticGet('uri', $uri);
if (!$oprofile) {
print "No OStatus remote profile known for URI $uri\n";
exit(1);
}
function showProfileInfo($oprofile) { function showProfileInfo($oprofile) {
if ($oprofile->isGroup()) { if ($oprofile->isGroup()) {
echo "group\n"; echo "group\n";
...@@ -58,32 +43,53 @@ function showProfileInfo($oprofile) { ...@@ -58,32 +43,53 @@ function showProfileInfo($oprofile) {
echo "\n"; echo "\n";
} }
echo "Before:\n"; function fixProfile($uri) {
showProfileInfo($oprofile); $oprofile = Ostatus_profile::staticGet('uri', $uri);
if (!$oprofile) {
print "No OStatus remote profile known for URI $uri\n";
return false;
}
echo "Before:\n";
showProfileInfo($oprofile);
$feedurl = $oprofile->feeduri; $feedurl = $oprofile->feeduri;
$client = new HttpClient(); $client = new HttpClient();
$response = $client->get($feedurl); $response = $client->get($feedurl);
if ($response->isOk()) { if ($response->isOk()) {
echo "Updating profile from feed: $feedurl\n"; echo "Updating profile from feed: $feedurl\n";
$dom = new DOMDocument(); $dom = new DOMDocument();
if ($dom->loadXML($response->getBody())) { if ($dom->loadXML($response->getBody())) {
$feed = $dom->documentElement; $feed = $dom->documentElement;
$entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry'); $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
if ($entries->length) { if ($entries->length) {
$entry = $entries->item(0); $entry = $entries->item(0);
$activity = new Activity($entry, $feed); $activity = new Activity($entry, $feed);
$oprofile->checkAuthorship($activity); $oprofile->checkAuthorship($activity);
echo " (ok)\n"; echo " (ok)\n";
} else {
echo " (no entry; skipping)\n";
return false;
}
} else { } else {
echo " (no entry; skipping)\n"; echo " (bad feed; skipping)\n";
return false;
} }
} else { } else {
echo " (bad feed; skipping)\n"; echo "Failed feed fetch: {$response->getStatus()} for $feedurl\n";
return false;
} }
} else {
echo "Failed feed fetch: {$response->getStatus()} for $feedurl\n"; echo "After:\n";
showProfileInfo($oprofile);
return true;
} }
echo "After:\n"; if (empty($args[0]) || !Validate::uri($args[0])) {
showProfileInfo($oprofile); print "$helptext";
exit(1);
}
$uri = $args[0];
fixProfile($uri);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment