X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Fscripts%2Fupdate_ostatus_profiles.php;h=707dbe61f808d0c8c162843e589a23888d3f6c6e;hb=dd03e55e125c357eeaeca5eb41d04e7c031824c2;hp=f0bc3e12dcff684d4b932025b5a713b66dd4d86d;hpb=3fc1d245a179efabfa862d3539642fe0fc67f856;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/scripts/update_ostatus_profiles.php b/plugins/OStatus/scripts/update_ostatus_profiles.php index f0bc3e12dc..707dbe61f8 100644 --- a/plugins/OStatus/scripts/update_ostatus_profiles.php +++ b/plugins/OStatus/scripts/update_ostatus_profiles.php @@ -20,8 +20,8 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); -$shortoptions = 'u:a'; -$longoptions = array('uri=', 'all'); +$shortoptions = 'u:af'; +$longoptions = array('uri=', 'all', 'force'); $helptext = <<isGroup()) { - $self = $this->localGroup(); - } else { - $self = $this->localProfile(); - } - if (!$self) { - throw new ServerException(sprintf( - // TRANS: Server exception. %s is a URI. - _m('Tried to update avatar for unsaved remote profile %s.'), - $this->uri)); - } - - // @fixme this should be better encapsulated - // ripped from oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); - try { - if (!copy($url, $temp_filename)) { - // TRANS: Server exception. %s is a URL. - throw new ServerException(sprintf(_m('Unable to fetch avatar from %s.'), $url)); - } - - if ($this->isGroup()) { - $id = $this->group_id; - } else { - $id = $this->profile_id; - } - // @fixme should we be using different ids? - $imagefile = new ImageFile($id, $temp_filename); - $filename = Avatar::filename($id, - image_type_to_extension($imagefile->type), - null, - common_timestamp()); - rename($temp_filename, Avatar::path($filename)); - } catch (Exception $e) { - unlink($temp_filename); - throw $e; - } - // @fixme hardcoded chmod is lame, but seems to be necessary to - // keep from accidentally saving images from command-line (queues) - // that can't be read from web server, which causes hard-to-notice - // problems later on: - // - // http://status.net/open-source/issues/2663 - chmod(Avatar::path($filename), 0644); - - $self->setOriginal($filename); - - $orig = clone($this); - $this->avatar = $url; - $this->update($orig); - } - /** * Look up and if necessary create an Ostatus_profile for the remote entity * with the given profile page URL. This should never return null -- you @@ -118,7 +54,7 @@ class LooseOstatusProfile extends Ostatus_profile * @throws Exception on various error conditions * @throws OStatusShadowException if this reference would obscure a local user/group */ - public static function updateProfileURL($profile_url, $hints=array()) + public static function updateProfileURL($profile_url, array $hints=array()) { $oprofile = null; @@ -157,13 +93,13 @@ class LooseOstatusProfile extends Ostatus_profile // Check if they've got an LRDD header $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml'); - - if (!empty($lrdd)) { - - $xrd = Discovery::fetchXrd($lrdd); + try { + $xrd = new XML_XRD(); + $xrd->loadFile($lrdd); $xrdHints = DiscoveryHints::fromXRD($xrd); - $hints = array_merge($hints, $xrdHints); + } catch (Exception $e) { + // No hints available from XRD } // If discovery found a feedurl (probably from LRDD), use it. @@ -214,9 +150,12 @@ class LooseOstatusProfile extends Ostatus_profile $hints = array('webfinger' => $addr); - $dhints = DiscoveryHints::fromXRD($xrd); - - $hints = array_merge($hints, $dhints); + try { + $dHints = DiscoveryHints::fromXRD($xrd); + $hints = array_merge($hints, $xrdHints); + } catch (Exception $e) { + // No hints available from XRD + } // If there's an Hcard, let's grab its info if (array_key_exists('hcard', $hints)) { @@ -292,6 +231,8 @@ if (have_option('u', 'uri')) { exit(1); } +$forceUpdates = have_option('f', 'force'); + $cnt = $lop->find(); if (!empty($cnt)) { @@ -314,12 +255,12 @@ while($lop->fetch()) { $orig = clone($lop); $lop->avatar = $oprofile->avatar; $lop->update($orig); - $lop->updateAvatar($oprofile->avatar); + $lop->updateAvatar($oprofile->avatar, $forceUpdates); if (!$quiet) { print "Done.\n"; } } } catch (Exception $e) { if (!$quiet) { print $e->getMessage() . "\n"; } - common_log(LOG_WARN, $e->getMessage(), __FILE__); + common_log(LOG_WARNING, $e->getMessage(), __FILE__); // continue on error } }