3 namespace Friendica\Console;
6 use Friendica\Core\L10n;
7 use Friendica\Model\Contact;
10 * @brief tool to block an account from the node
12 * With this tool, you can block an account in such a way, that no postings
13 * or comments this account writes are accepted to the node.
15 * License: AGPLv3 or later, same as Friendica
17 * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
18 * @author Hypolite Petovan <hypolite@mrpetovan.com>
20 class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
22 protected $helpOptions = ['h', 'help', '?'];
33 protected function getHelp()
36 console globalcommunityblock - Block remote profile from interacting with this node
38 bin/console globalcommunityblock <profile_url> [<reason>] [-h|--help|-?] [-v]
41 Blocks an account in such a way that no postings or comments this account writes are accepted to this node.
42 You can provide a optional reason for the block.
45 -h|--help|-? Show help information
46 -v Show more debug information.
51 public function __construct(App\Mode $appMode, L10n $l10n, $argv = null)
53 parent::__construct($argv);
55 $this->appMode = $appMode;
59 protected function doExecute()
61 if ($this->getOption('v')) {
62 $this->out('Class: ' . __CLASS__);
63 $this->out('Arguments: ' . var_export($this->args, true));
64 $this->out('Options: ' . var_export($this->options, true));
67 if (count($this->args) == 0) {
68 $this->out($this->getHelp());
72 if (count($this->args) > 2) {
73 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
76 if ($this->appMode->isInstall()) {
77 throw new \RuntimeException('Database isn\'t ready or populated yet');
80 $contact_id = Contact::getIdForURL($this->getArgument(0));
82 throw new \RuntimeException($this->l10n->t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
85 $block_reason = $this->getArgument(1);
86 if(Contact::block($contact_id, $block_reason)) {
87 $this->out($this->l10n->t('The contact has been blocked from the node'));
89 throw new \RuntimeException('The contact block failed.');