From 7bef2ad4ccb10a319dde1e62460d34f7ebf3242c Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 28 Mar 2016 16:19:47 +0200 Subject: [PATCH] Update Profile Data script fixes, might work for groups too now --- lib/activityutils.php | 2 +- plugins/OStatus/classes/Ostatus_profile.php | 6 ++++++ plugins/OStatus/scripts/update-profile-data.php | 15 ++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/activityutils.php b/lib/activityutils.php index b86dd65909..dcccbb8d87 100644 --- a/lib/activityutils.php +++ b/lib/activityutils.php @@ -301,7 +301,7 @@ class ActivityUtils return false; } - static function getFeedAuthor($feedEl) + static function getFeedAuthor(DOMDocument $feedEl) { // Try old and deprecated activity:subject diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 5673d51457..e8ac16fb1d 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -1281,6 +1281,12 @@ class Ostatus_profile extends Managed_DataObject */ public function updateFromActivityObject(ActivityObject $object, array $hints=array()) { + if (self::getActivityObjectProfileURI($actorObj) !== $this->getUri()) { + common_log(LOG_ERR, 'Trying to update profile with URI '._ve($this->getUri()).' from ActivityObject with URI: '._ve(self::getActivityObjectProfileURI($actorObj))); + // FIXME: Maybe not AuthorizationException? + throw new AuthorizationException('Trying to update profile from ActivityObject with different URI.'); + } + if ($this->isGroup()) { $group = $this->localGroup(); self::updateGroup($group, $object, $hints); diff --git a/plugins/OStatus/scripts/update-profile-data.php b/plugins/OStatus/scripts/update-profile-data.php index e713ee36fe..5b3e00e9fc 100755 --- a/plugins/OStatus/scripts/update-profile-data.php +++ b/plugins/OStatus/scripts/update-profile-data.php @@ -62,15 +62,16 @@ function fixProfile(Ostatus_profile $oprofile) { 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); + if ($dom->documentElement->tagName !== 'feed') { + echo " (no element in feed URL response; skipping)\n"; + return false; + } + $actorObj = ActivityUtils::getFeedAuthor($dom->documentElement); + if ($actorObj) { + $oprofile->updateFromActivityObject($actorObj); echo " (ok)\n"; } else { - echo " (no entry; skipping)\n"; + echo " (no author on feed; skipping)\n"; return false; } } else { -- 2.39.2