]> git.mxchange.org Git - friendica.git/blob - src/Core/Console/GlobalCommunityBlock.php
Line feeds fixed, not change in functionality
[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                 if ($this->getOption('v')) {
43                         $this->out('Class: ' . __CLASS__);
44                         $this->out('Arguments: ' . var_export($this->args, true));
45                         $this->out('Options: ' . var_export($this->options, true));
46                 }
47
48                 if (count($this->args) == 0) {
49                         $this->out($this->getHelp());
50                         return 0;
51                 }
52
53                 if (count($this->args) > 1) {
54                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
55                 }
56
57                 require_once '.htconfig.php';
58                 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
59                 unset($db_host, $db_user, $db_pass, $db_data);
60
61                 if (!$result) {
62                         throw new \RuntimeException('Unable to connect to database');
63                 }
64
65                 $contact_id = Contact::getIdForURL($this->getArgument(0));
66                 if (!$contact_id) {
67                         throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));
68                 }
69                 if(Contact::block($contact_id)) {
70                         $this->out(L10n::t('The contact has been blocked from the node'));
71                 } else {
72                         throw new \RuntimeException('The contact block failed.');
73                 }
74
75                 return 0;
76         }
77 }