Update "mrpetovan" email address
[friendica.git/.git] / src / Core / Console / GlobalCommunityBlock.php
1 <?php
2
3 namespace Friendica\Core\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> [-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
33 Options
34     -h|--help|-? Show help information
35     -v           Show more debug information.
36 HELP;
37                 return $help;
38         }
39
40         protected function doExecute()
41         {
42                 $a = get_app();
43
44                 if ($this->getOption('v')) {
45                         $this->out('Class: ' . __CLASS__);
46                         $this->out('Arguments: ' . var_export($this->args, true));
47                         $this->out('Options: ' . var_export($this->options, true));
48                 }
49
50                 if (count($this->args) == 0) {
51                         $this->out($this->getHelp());
52                         return 0;
53                 }
54
55                 if (count($this->args) > 1) {
56                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
57                 }
58
59                 if ($a->isInstallMode()) {
60                         throw new \RuntimeException('Database isn\'t ready or populated yet');
61                 }
62
63                 $contact_id = Contact::getIdForURL($this->getArgument(0));
64                 if (!$contact_id) {
65                         throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));
66                 }
67                 if(Contact::block($contact_id)) {
68                         $this->out(L10n::t('The contact has been blocked from the node'));
69                 } else {
70                         throw new \RuntimeException('The contact block failed.');
71                 }
72
73                 return 0;
74         }
75 }