]> git.mxchange.org Git - friendica.git/blob - src/Core/Console/GlobalCommunityBlock.php
Add Console classes
[friendica.git] / src / Core / Console / GlobalCommunityBlock.php
1 <?php\r
2 \r
3 namespace Friendica\Core\Console;\r
4 \r
5 use Friendica\Core\L10n;\r
6 use Friendica\Model\Contact;\r
7 \r
8 /**\r
9  * Description of GlobalCommunityBlock\r
10  *\r
11  * @author Hypolite Petovan <mrpetovan@gmail.com>\r
12  */\r
13 class GlobalCommunityBlock extends \Asika\SimpleConsole\Console\r
14 {\r
15         protected $helpOptions = ['h', 'help', '?'];\r
16 \r
17         protected function getHelp()\r
18         {\r
19                 $help = <<<HELP\r
20 console globalcommunityblock - Silence remote profile from global community page\r
21 Usage\r
22         bin/console globalcommunityblock <profile_url> [-h|--help|-?] [-v]\r
23 \r
24 Description\r
25         bin/console globalcommunityblock <profile_url>\r
26                 Silences the provided remote profile URL from the global community page\r
27 \r
28 Options\r
29     -h|--help|-? Show help information\r
30     -v           Show more debug information.\r
31 HELP;\r
32                 return $help;\r
33         }\r
34 \r
35         protected function doExecute()\r
36         {\r
37                 if ($this->getOption('v')) {\r
38                         $this->out('Class: ' . __CLASS__);\r
39                         $this->out('Arguments: ' . var_export($this->args, true));\r
40                         $this->out('Options: ' . var_export($this->options, true));\r
41                 }\r
42 \r
43                 if (count($this->args) == 0) {\r
44                         $this->out($this->getHelp());\r
45                         return 0;\r
46                 }\r
47 \r
48                 if (count($this->args) > 1) {\r
49                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
50                 }\r
51 \r
52                 require_once '.htconfig.php';\r
53                 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
54                 unset($db_host, $db_user, $db_pass, $db_data);\r
55 \r
56                 if (!$result) {\r
57                         throw new \RuntimeException('Unable to connect to database');\r
58                 }\r
59 \r
60                 $contact_id = Contact::getIdForURL($argv[1]);\r
61                 if (!$contact_id) {\r
62                         throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));\r
63                 }\r
64                 Contact::block($contact_id);\r
65                 $this->out(L10n::t('The contact has been blocked from the node'));\r
66 \r
67                 return 0;\r
68         }\r
69 \r
70 }\r