123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class AccountMover extends QueueHandler
- {
- function transport()
- {
- return 'acctmove';
- }
- function handle($object) : bool
- {
- list($user, $remote, $password) = $object;
- $remote = Discovery::normalize($remote);
- $oprofile = Ostatus_profile::ensureProfileURI($remote);
- if (empty($oprofile)) {
-
-
- throw new Exception(sprintf(_("Cannot locate account %s."),$remote));
- }
- list($svcDocUrl, $username) = self::getServiceDocument($remote);
- $sink = new ActivitySink($svcDocUrl, $username, $password);
- $this->log(LOG_INFO,
- "Moving user {$user->nickname} ".
- "to {$remote}.");
- $stream = new UserActivityStream($user);
-
- $acts = array_reverse($stream->activities);
- $this->log(LOG_INFO,
- "Got ".count($acts)." activities ".
- "for {$user->nickname}.");
- $qm = QueueManager::get();
- foreach ($acts as $act) {
- $qm->enqueue(array($act, $sink, $user->getUri(), $remote), 'actmove');
- }
- $this->log(LOG_INFO,
- "Finished moving user {$user->nickname} ".
- "to {$remote}.");
- }
- static function getServiceDocument($remote)
- {
- $discovery = new Discovery();
- $xrd = $discovery->lookup($remote);
- if (empty($xrd)) {
-
-
- throw new Exception(sprintf(_("Cannot find XRD for %s."),$remote));
- }
- $svcDocUrl = null;
- $username = null;
- $link = $xrd->links->get('http://apinamespace.org/atom', 'application/atomsvc+xml');
- if (!is_null($link)) {
- $svcDocUrl = $link->href;
- if (isset($link['http://apinamespace.org/atom/username'])) {
- $username = $link['http://apinamespace.org/atom/username'];
- }
- }
- if (empty($svcDocUrl)) {
-
-
- throw new Exception(sprintf(_("No AtomPub API service for %s."),$remote));
- }
- return array($svcDocUrl, $username);
- }
-
- protected function log($level, $message)
- {
- common_log($level, "AccountMover: " . $message);
- }
- }
|