]> git.mxchange.org Git - friendica.git/blob - src/Console/GlobalCommunityBlock.php
2eef427dba103d0ada64a328fe634e26b84b058e
[friendica.git] / src / Console / GlobalCommunityBlock.php
1 <?php
2
3 namespace Friendica\Console;
4
5 use Friendica\Core\L10n;
6 use Friendica\Model\Contact;
7
8 /**
9  * @brief tool to block an account from the node
10  *
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.
13  *
14  * License: AGPLv3 or later, same as Friendica
15  *
16  * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
17  * @author Hypolite Petovan <hypolite@mrpetovan.com>
18  */
19 class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
20 {
21         protected $helpOptions = ['h', 'help', '?'];
22
23         protected function getHelp()
24         {
25                 $help = <<<HELP
26 console globalcommunityblock - Block remote profile from interacting with this node
27 Usage
28         bin/console globalcommunityblock <profile_url> [<reason>] [-h|--help|-?] [-v]
29
30 Description
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.
33
34 Options
35     -h|--help|-? Show help information
36     -v           Show more debug information.
37 HELP;
38                 return $help;
39         }
40
41         protected function doExecute()
42         {
43                 $a = \get_app();
44
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));
49                 }
50
51                 if (count($this->args) == 0) {
52                         $this->out($this->getHelp());
53                         return 0;
54                 }
55
56                 if (count($this->args) > 2) {
57                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
58                 }
59
60                 if ($a->getMode()->isInstall()) {
61                         throw new \RuntimeException('Database isn\'t ready or populated yet');
62                 }
63
64                 $contact_url = Contact::getIdForURL($this->getArgument(0));
65                 if (!$contact_url) {
66                         throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
67                 }
68
69                 $block_reason = $this->getArgument(1);
70                 if(Contact::block($contact_url, $block_reason)) {
71                         $this->out(L10n::t('The contact has been blocked from the node'));
72                 } else {
73                         throw new \RuntimeException('The contact block failed.');
74                 }
75
76                 return 0;
77         }
78 }