3 namespace Friendica\Console;
5 use Friendica\Core\L10n;
6 use Friendica\Model\Contact;
9 * @brief tool to block an account from the node
11 * With this tool, you can block an account in such a way, that no postings
12 * or comments this account writes are accepted to the node.
14 * License: AGPLv3 or later, same as Friendica
16 * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
17 * @author Hypolite Petovan <hypolite@mrpetovan.com>
19 class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
21 protected $helpOptions = ['h', 'help', '?'];
23 protected function getHelp()
26 console globalcommunityblock - Block remote profile from interacting with this node
28 bin/console globalcommunityblock <profile_url> [<reason>] [-h|--help|-?] [-v]
31 Blocks an account in such a way that no postings or comments this account writes are accepted to this node.
32 You can provide a optional reason for the block.
35 -h|--help|-? Show help information
36 -v Show more debug information.
41 protected function doExecute()
45 if ($this->getOption('v')) {
46 $this->out('Class: ' . __CLASS__);
47 $this->out('Arguments: ' . var_export($this->args, true));
48 $this->out('Options: ' . var_export($this->options, true));
51 if (count($this->args) == 0) {
52 $this->out($this->getHelp());
56 if (count($this->args) > 2) {
57 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
60 if ($a->getMode()->isInstall()) {
61 throw new \RuntimeException('Database isn\'t ready or populated yet');
64 $contact_id = Contact::getIdForURL($this->getArgument(0));
66 throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
69 $block_reason = $this->getArgument(1);
70 if(Contact::block($contact_id, $block_reason)) {
71 $this->out(L10n::t('The contact has been blocked from the node'));
73 throw new \RuntimeException('The contact block failed.');