3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Console;
25 use Friendica\Core\L10n;
26 use Friendica\Model\Contact;
29 * tool to block an account from the node
31 * With this tool, you can block an account in such a way, that no postings
32 * or comments this account writes are accepted to the node.
34 class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
36 protected $helpOptions = ['h', 'help', '?'];
43 * @var \Friendica\Core\L10n
47 protected function getHelp()
50 console globalcommunityblock - Block remote profile from interacting with this node
52 bin/console globalcommunityblock <profile_url> [<reason>] [-h|--help|-?] [-v]
55 Blocks an account in such a way that no postings or comments this account writes are accepted to this node.
56 You can provide a optional reason for the block.
59 -h|--help|-? Show help information
60 -v Show more debug information.
65 public function __construct(App\Mode $appMode, L10n $l10n, $argv = null)
67 parent::__construct($argv);
69 $this->appMode = $appMode;
73 protected function doExecute()
75 if ($this->getOption('v')) {
76 $this->out('Class: ' . __CLASS__);
77 $this->out('Arguments: ' . var_export($this->args, true));
78 $this->out('Options: ' . var_export($this->options, true));
81 if (count($this->args) == 0) {
82 $this->out($this->getHelp());
86 if (count($this->args) > 2) {
87 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
90 if ($this->appMode->isInstall()) {
91 throw new \RuntimeException('Database isn\'t ready or populated yet');
94 $contact_id = Contact::getIdForURL($this->getArgument(0));
96 throw new \RuntimeException($this->l10n->t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
99 $block_reason = $this->getArgument(1);
100 if(Contact::block($contact_id, $block_reason)) {
101 $this->out($this->l10n->t('The contact has been blocked from the node'));
103 throw new \RuntimeException('The contact block failed.');