]> git.mxchange.org Git - friendica.git/blobdiff - src/Console/Relay.php
bump version 2023.12
[friendica.git] / src / Console / Relay.php
index ab994dc62c1af0e2b030e8279c7fd6152ea2731f..11d1dbf8215a9871dbc4ffae535d8904a3f1ff94 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,8 +23,8 @@ namespace Friendica\Console;
 
 use Asika\SimpleConsole\CommandArgsException;
 use Friendica\Model\APContact;
-use Friendica\Model\Contact;
 use Friendica\Protocol\ActivityPub\Transmitter;
+use Friendica\Protocol\Relay as ProtocolRelay;
 
 /**
  * tool to control the list of ActivityPub relay servers from the CLI
@@ -49,7 +49,7 @@ console relay - Manage ActivityPub relay configuration
 Synopsis
        bin/console relay list [-h|--help|-?] [-v]
        bin/console relay add <actor> [-h|--help|-?] [-v]
-       bin/console relay remove <actor> [-h|--help|-?] [-v]
+       bin/console relay remove <actor> [-f|--force] [-h|--help|-?] [-v]
 
 Description
        bin/console relay list
@@ -62,6 +62,7 @@ Description
                Remove a relay actor in the format https://relayserver.tld/actor
 
 Options
+    -f|--force   Change the relay status in the system even if the unsubscribe message failed
     -h|--help|-? Show help information
     -v           Show more debug information.
 HELP;
@@ -75,7 +76,7 @@ HELP;
                $this->dba = $dba;
        }
 
-       protected function doExecute()
+       protected function doExecute(): int
        {
                if ($this->getOption('v')) {
                        $this->out('Executable: ' . $this->executable);
@@ -89,13 +90,9 @@ HELP;
                }
 
                if ((count($this->args) == 1) && ($this->getArgument(0) == 'list')) {
-                       $contacts = $this->dba->select('apcontact', ['url'],
-                       ["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))",
-                               'Application', 0, Contact::FOLLOWER, Contact::FRIEND]);
-                       while ($contact = $this->dba->fetch($contacts)) {
+                       foreach (ProtocolRelay::getList(['url']) as $contact) {
                                $this->out($contact['url']);
                        }
-                       $this->dba->close($contacts);
                } elseif (count($this->args) == 0) {
                        throw new CommandArgsException('too few arguments');
                } elseif (count($this->args) == 1) {
@@ -107,7 +104,7 @@ HELP;
                        $actor = $this->getArgument(1);
 
                        $apcontact = APContact::getByURL($actor);
-                       if (empty($apcontact) || ($apcontact['type'] != 'Application')) {
+                       if (empty($apcontact) || !in_array($apcontact['type'], ['Application', 'Service'])) {
                                $this->out($actor . ' is no relay actor');
                                return 1;
                        }
@@ -119,10 +116,14 @@ HELP;
                                        $this->out($actor . " couldn't be added");
                                }
                        } elseif ($mode == 'remove') {
-                               if (Transmitter::sendRelayUndoFollow($actor)) {
+                               $force = $this->getOption(['f', 'force'], false);
+
+                               if (Transmitter::sendRelayUndoFollow($actor, $force)) {
                                        $this->out('Successfully removed ' . $actor);
-                               } else {
+                               } elseif (!$force) {
                                        $this->out($actor . " couldn't be removed");
+                               } else {
+                                       $this->out($actor . " is forcefully removed");
                                }
                        } else {
                                throw new CommandArgsException($mode . ' is no valid command');