]> git.mxchange.org Git - friendica.git/blob - src/Console/GlobalCommunitySilence.php
Fix formatting in Model\Group
[friendica.git] / src / Console / GlobalCommunitySilence.php
1 <?php
2
3 namespace Friendica\Console;
4
5 use Friendica\BaseObject;
6 use Friendica\Database\DBA;
7 use Friendica\Model\Contact;
8 use RuntimeException;
9
10 /**
11  * @brief tool to silence accounts on the global community page
12  *
13  * With this tool, you can silence an account on the global community page.
14  * Postings from silenced accounts will not be displayed on the community
15  * page. This silencing does only affect the display on the community page,
16  * accounts following the silenced accounts will still get their postings.
17  *
18  * License: AGPLv3 or later, same as Friendica
19  *
20  * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
21  * @author Hypolite Petovan <hypolite@mrpetovan.com>
22  */
23 class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
24 {
25         protected $helpOptions = ['h', 'help', '?'];
26
27         protected function getHelp()
28         {
29                 $help = <<<HELP
30 console globalcommunitysilence - Silence remote profile from global community page
31 Usage
32         bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
33
34 Description
35         With this tool, you can silence an account on the global community page.
36         Postings from silenced accounts will not be displayed on the community page.
37         This silencing does only affect the display on the community page, accounts
38         following the silenced accounts will still get their postings.
39
40 Options
41     -h|--help|-? Show help information
42     -v           Show more debug information.
43 HELP;
44                 return $help;
45         }
46
47         protected function doExecute()
48         {
49                 if ($this->getOption('v')) {
50                         $this->out('Class: ' . __CLASS__);
51                         $this->out('Arguments: ' . var_export($this->args, true));
52                         $this->out('Options: ' . var_export($this->options, true));
53                 }
54
55                 if (count($this->args) == 0) {
56                         $this->out($this->getHelp());
57                         return 0;
58                 }
59
60                 if (count($this->args) > 1) {
61                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
62                 }
63
64                 if (BaseObject::getApp()->getMode()->isInstall()) {
65                         throw new RuntimeException('Database isn\'t ready or populated yet');
66                 }
67
68                 $contact_id = Contact::getIdForURL($this->getArgument(0));
69                 if ($contact_id) {
70                         DBA::update('contact', ['hidden' => true], ['id' => $contact_id]);
71                         $this->out('The account has been successfully silenced from the global community page.');
72                 } else {
73                         throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')');
74                 }
75
76                 return 0;
77         }
78 }