]> git.mxchange.org Git - friendica.git/blobdiff - src/Console/ServerBlock.php
Apply suggestions from code review
[friendica.git] / src / Console / ServerBlock.php
index 9ef6777db73d3cf307514922775522c5084ec26c..4d04dcff81e0d23847af76a05fe399728f1ea8b6 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -24,6 +24,7 @@ namespace Friendica\Console;
 use Asika\SimpleConsole\CommandArgsException;
 use Asika\SimpleConsole\Console;
 use Console_Table;
+use Friendica\Core\Worker;
 use Friendica\Moderation\DomainPatternBlocklist;
 
 /**
@@ -106,6 +107,11 @@ HELP;
        {
                $filename = $this->getArgument(1);
 
+               if (empty($filename)) {
+                       $this->out('A file name is required, e.g. ./bin/console serverblock export backup.csv');
+                       return 1;
+               }
+
                $this->blocklist->exportToFile($filename);
 
                // Success
@@ -127,6 +133,7 @@ HELP;
 
                if ($this->blocklist->append($newBlockList)) {
                        $this->out(sprintf("Entries from %s that were not blocked before are now blocked", $filename));
+                       Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers');
                        return 0;
                } else {
                        $this->out("Couldn't save the block list");
@@ -155,12 +162,12 @@ HELP;
         */
        private function addBlockedServer(): int
        {
-               if (count($this->args) < 2 || count($this->args) > 3) {
-                       throw new CommandArgsException('Add needs a domain pattern and optionally a reason.');
+               if (count($this->args) != 3) {
+                       throw new CommandArgsException('Add needs a domain pattern and a reason.');
                }
 
                $pattern = $this->getArgument(1);
-               $reason  = (count($this->args) === 3) ? $this->getArgument(2) : DomainPatternBlocklist::DEFAULT_REASON;
+               $reason  = $this->getArgument(2);
 
                $result = $this->blocklist->addPattern($pattern, $reason);
                if ($result) {
@@ -169,6 +176,7 @@ HELP;
                        } else {
                                $this->out(sprintf("The domain pattern '%s' is now blocked. (Reason: '%s')", $pattern, $reason));
                        }
+                       Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers');
                        return 0;
                } else {
                        $this->out(sprintf("Couldn't save '%s' as blocked domain pattern", $pattern));
@@ -193,6 +201,7 @@ HELP;
                if ($result) {
                        if ($result == 2) {
                                $this->out(sprintf("The domain pattern '%s' isn't blocked anymore", $pattern));
+                               Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers');
                                return 0;
                        } else {
                                $this->out(sprintf("The domain pattern '%s' wasn't blocked.", $pattern));