From 91535365b3a2f0b56f52c982f0e8ab8976d36dc6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 11 Feb 2011 11:55:23 -0800 Subject: [PATCH 1/4] Work in progress: update-profile-data.php to update ostatus profile info from the current feed --- .../OStatus/scripts/update-profile-data.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 plugins/OStatus/scripts/update-profile-data.php diff --git a/plugins/OStatus/scripts/update-profile-data.php b/plugins/OStatus/scripts/update-profile-data.php new file mode 100644 index 0000000000..f10da71437 --- /dev/null +++ b/plugins/OStatus/scripts/update-profile-data.php @@ -0,0 +1,88 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); + +$helptext = <<isGroup()) { + echo "group\n"; + } else { + $profile = $oprofile->localProfile(); + foreach (array('nickname', 'bio', 'homepage', 'location') as $field) { + print " $field: {$profile->$field}\n"; + } + } + echo "\n"; +} + +echo "Before:\n"; +showProfileInfo($oprofile); + +$feedurl = $oprofile->feeduri; +$client = new HttpClient(); +$response = $client->get($feedurl); +if ($response->isOk()) { + echo "Updating profile from feed: $feedurl\n"; + $dom = new DOMDocument(); + if ($dom->loadXML($response->getBody())) { + $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry'); + if ($entries->length) { + $entry = $entries->item(0); + $activity = new Activity($entry, $feed); + $oprofile->checkAuthorship($activity); + echo " (ok)\n"; + } else { + echo " (no entry; skipping)\n"; + } + } else { + echo " (bad feed; skipping)\n"; + } +} else { + echo "Failed feed fetch: {$response->getStatus()} for $feedurl\n"; +} + +echo "After:\n"; +showProfileInfo($oprofile); From f7b431d60bd2d38d5fbf12e1a37678f3d25a7cc6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 11 Feb 2011 12:08:35 -0800 Subject: [PATCH 2/4] woops --- plugins/OStatus/scripts/update-profile-data.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/OStatus/scripts/update-profile-data.php b/plugins/OStatus/scripts/update-profile-data.php index f10da71437..4f5409bfab 100644 --- a/plugins/OStatus/scripts/update-profile-data.php +++ b/plugins/OStatus/scripts/update-profile-data.php @@ -68,6 +68,7 @@ if ($response->isOk()) { echo "Updating profile from feed: $feedurl\n"; $dom = new DOMDocument(); if ($dom->loadXML($response->getBody())) { + $feed = $dom->documentElement; $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry'); if ($entries->length) { $entry = $entries->item(0); From f30744c7c565c50047b90515bcfd71baa382c96e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 11 Feb 2011 12:13:33 -0800 Subject: [PATCH 3/4] refactor for multi.... --- .../OStatus/scripts/update-profile-data.php | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/plugins/OStatus/scripts/update-profile-data.php b/plugins/OStatus/scripts/update-profile-data.php index 4f5409bfab..d61d9470d1 100644 --- a/plugins/OStatus/scripts/update-profile-data.php +++ b/plugins/OStatus/scripts/update-profile-data.php @@ -31,21 +31,6 @@ END_OF_HELP; 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) { if ($oprofile->isGroup()) { echo "group\n"; @@ -58,32 +43,53 @@ function showProfileInfo($oprofile) { echo "\n"; } -echo "Before:\n"; -showProfileInfo($oprofile); +function fixProfile($uri) { + $oprofile = Ostatus_profile::staticGet('uri', $uri); -$feedurl = $oprofile->feeduri; -$client = new HttpClient(); -$response = $client->get($feedurl); -if ($response->isOk()) { - echo "Updating profile from feed: $feedurl\n"; - $dom = new DOMDocument(); - if ($dom->loadXML($response->getBody())) { - $feed = $dom->documentElement; - $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry'); - if ($entries->length) { - $entry = $entries->item(0); - $activity = new Activity($entry, $feed); - $oprofile->checkAuthorship($activity); - echo " (ok)\n"; + if (!$oprofile) { + print "No OStatus remote profile known for URI $uri\n"; + return false; + } + + echo "Before:\n"; + showProfileInfo($oprofile); + + $feedurl = $oprofile->feeduri; + $client = new HttpClient(); + $response = $client->get($feedurl); + if ($response->isOk()) { + echo "Updating profile from feed: $feedurl\n"; + $dom = new DOMDocument(); + if ($dom->loadXML($response->getBody())) { + $feed = $dom->documentElement; + $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry'); + if ($entries->length) { + $entry = $entries->item(0); + $activity = new Activity($entry, $feed); + $oprofile->checkAuthorship($activity); + echo " (ok)\n"; + } else { + echo " (no entry; skipping)\n"; + return false; + } } else { - echo " (no entry; skipping)\n"; + echo " (bad feed; skipping)\n"; + return false; } } 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"; -showProfileInfo($oprofile); +if (empty($args[0]) || !Validate::uri($args[0])) { + print "$helptext"; + exit(1); +} + +$uri = $args[0]; +fixProfile($uri); From c92358fa7bfadef0138e22d7e19f6d33cb557f72 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 11 Feb 2011 12:23:03 -0800 Subject: [PATCH 4/4] add --all and --suspicious options for update-profile-data.php --- .../OStatus/scripts/update-profile-data.php | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/plugins/OStatus/scripts/update-profile-data.php b/plugins/OStatus/scripts/update-profile-data.php index d61d9470d1..20f6d57d90 100644 --- a/plugins/OStatus/scripts/update-profile-data.php +++ b/plugins/OStatus/scripts/update-profile-data.php @@ -20,13 +20,20 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); +$longoptions = array('all', 'suspicious', 'quiet'); + $helptext = <<find(); + echo "Found $oprofile->N profiles:\n\n"; + while ($oprofile->fetch()) { + $ok = fixProfile($oprofile->uri) && $ok; + } +} else if (have_option('suspicious')) { + $oprofile = new Ostatus_profile(); + $oprofile->joinAdd(array('profile_id', 'profile:id')); + $oprofile->whereAdd("nickname rlike '^[0-9]$'"); + $oprofile->find(); + echo "Found $oprofile->N matching profiles:\n\n"; + while ($oprofile->fetch()) { + $ok = fixProfile($oprofile->uri) && $ok; + } +} else if (!empty($args[0]) && Validate::uri($args[0])) { + $uri = $args[0]; + $ok = fixProfile($uri); +} else { print "$helptext"; - exit(1); + $ok = false; } -$uri = $args[0]; -fixProfile($uri); +exit($ok ? 0 : 1);