4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2010, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
23 $longoptions = array('all', 'suspicious', 'quiet');
25 $helptext = <<<END_OF_HELP
26 update-profile-data.php [options] [http://example.com/profile/url]
28 Rerun profile discovery for the given OStatus remote profile, and save the
29 updated profile data (nickname, fullname, avatar, bio, etc).
30 Doesn't touch feed state.
31 Can be used to clean up after breakages.
34 --all Run for all known OStatus profiles
35 --suspicious Run for OStatus profiles with all-numeric nicknames
36 (fixes 0.9.7 prerelease back-compatibility bug)
40 require_once INSTALLDIR.'/scripts/commandline.inc';
42 function showProfileInfo(Ostatus_profile $oprofile) {
43 if ($oprofile->isGroup()) {
46 $profile = $oprofile->localProfile();
47 foreach (array('nickname', 'fullname', 'bio', 'homepage', 'location') as $field) {
48 print " $field: {$profile->$field}\n";
54 function fixProfile(Ostatus_profile $oprofile) {
56 showProfileInfo($oprofile);
58 $feedurl = $oprofile->feeduri;
59 $client = new HTTPClient();
60 $response = $client->get($feedurl);
61 if ($response->isOk()) {
62 echo "Updating profile from feed: $feedurl\n";
63 $dom = new DOMDocument();
64 if ($dom->loadXML($response->getBody())) {
65 if ($dom->documentElement->tagName !== 'feed') {
66 echo " (no <feed> element in feed URL response; skipping)\n";
69 $actorObj = ActivityUtils::getFeedAuthor($dom->documentElement);
71 $oprofile->updateFromActivityObject($actorObj);
74 echo " (no author on feed; skipping)\n";
78 echo " (bad feed; skipping)\n";
82 echo "Failed feed fetch: {$response->getStatus()} for $feedurl\n";
87 showProfileInfo($oprofile);
92 $validate = new Validate();
93 if (have_option('all')) {
94 $oprofile = new Ostatus_profile();
96 echo "Found $oprofile->N profiles:\n\n";
97 while ($oprofile->fetch()) {
99 $ok = fixProfile($oprofile) && $ok;
100 } catch (Exception $e) {
102 echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";
105 } else if (have_option('suspicious')) {
106 $oprofile = new Ostatus_profile();
107 $oprofile->joinAdd(array('profile_id', 'profile:id'));
108 $oprofile->whereAdd("nickname rlike '^[0-9]$'");
110 echo "Found $oprofile->N matching profiles:\n\n";
111 while ($oprofile->fetch()) {
113 $ok = fixProfile($oprofile) && $ok;
114 } catch (Exception $e) {
116 echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";
119 } else if (!empty($args[0]) && $validate->uri($args[0])) {
121 $oprofile = Ostatus_profile::getKV('uri', $uri);
123 if (!$oprofile instanceof Ostatus_profile) {
124 print "No OStatus remote profile known for URI $uri\n";
129 $ok = fixProfile($oprofile) && $ok;
130 } catch (Exception $e) {
132 echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";