]> git.mxchange.org Git - friendica.git/blob - src/Core/Console/GlobalCommunityBlock.php
6c2453307e3164df02400c9434bc6b9c4457fcd6
[friendica.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 <mrpetovan@gmail.com>
17  * @author Hypolite Petovan <mrpetovan@gmail.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                 require_once 'config/.htconfig.php';
60                 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
61                 unset($db_host, $db_user, $db_pass, $db_data);
62
63                 if (!$result) {
64                         throw new \RuntimeException('Unable to connect to database');
65                 }
66
67                 $contact_id = Contact::getIdForURL($this->getArgument(0));
68                 if (!$contact_id) {
69                         throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));
70                 }
71                 if(Contact::block($contact_id)) {
72                         $this->out(L10n::t('The contact has been blocked from the node'));
73                 } else {
74                         throw new \RuntimeException('The contact block failed.');
75                 }
76
77                 return 0;
78         }
79 }