#!/usr/bin/env php . /** * ActivityPub implementation for GNU social * * @package GNUsocial * * @author Diogo Cordeiro * @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ define('INSTALLDIR', dirname(__DIR__, 3)); define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); $shortoptions = 'i:af'; $longoptions = ['id=', 'all', 'force']; $helptext = <<getProfile()); exit(0); } elseif (!have_option('a', 'all')) { show_help(); exit(1); } $user = new User(); $cnt = $user->find(); while ($user->fetch()) { fix_subscriptions($user->getProfile()); } $user->free(); unset($user); printfnq("Done.\n"); /** * Validate and fix the `subscription` table */ function fix_subscriptions(Profile $profile) { // Collect every remote AP subscription $aprofiles = []; $subs = Subscription::getSubscribedIDs($profile->getID(), 0, null); $subs_aprofiles = Activitypub_profile::multiGet('profile_id', $subs); foreach ($subs_aprofiles->fetchAll() as $ap) { $aprofiles[$ap->getID()] = $ap; } unset($subs_aprofiles); // For each remote AP subscription, send a Follow activity foreach ($aprofiles as $sub) { try { $postman = new Activitypub_postman($profile, [$sub]); $postman->follow(); printfnq( 'Ensured subscription between ' . $profile->getBestName() . ' and ' . $sub->getUri() . "\n" ); } catch (Exception $e) { // Let it go printfnq('Failed to ensure subscription between ' . $profile->getBestName() . ' and ' . $sub->getUri() . "\n" ); printfnq('The reason was: ' . $e->getMessage() . "\n"); } } }