]> git.mxchange.org Git - friendica.git/blob - src/Console/GlobalCommunitySilence.php
The value is used twice, so use a variable
[friendica.git] / src / Console / GlobalCommunitySilence.php
1 <?php
2
3 namespace Friendica\Console;
4
5 use Friendica\App;
6 use Friendica\Database\Database;
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         /**
28          * @var App\Mode
29          */
30         private $appMode;
31         /**
32          * @var Database
33          */
34         private $dba;
35
36         protected function getHelp()
37         {
38                 $help = <<<HELP
39 console globalcommunitysilence - Silence remote profile from global community page
40 Usage
41         bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
42
43 Description
44         With this tool, you can silence an account on the global community page.
45         Postings from silenced accounts will not be displayed on the community page.
46         This silencing does only affect the display on the community page, accounts
47         following the silenced accounts will still get their postings.
48
49 Options
50     -h|--help|-? Show help information
51     -v           Show more debug information.
52 HELP;
53                 return $help;
54         }
55
56         public function __construct(App\Mode $appMode, Database $dba, array $argv = null)
57         {
58                 parent::__construct($argv);
59
60                 $this->appMode = $appMode;
61                 $this->dba  =$dba;
62         }
63
64         protected function doExecute()
65         {
66                 if ($this->getOption('v')) {
67                         $this->out('Class: ' . __CLASS__);
68                         $this->out('Arguments: ' . var_export($this->args, true));
69                         $this->out('Options: ' . var_export($this->options, true));
70                 }
71
72                 if (count($this->args) == 0) {
73                         $this->out($this->getHelp());
74                         return 0;
75                 }
76
77                 if (count($this->args) > 1) {
78                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
79                 }
80
81                 if ($this->appMode->isInstall()) {
82                         throw new RuntimeException('Database isn\'t ready or populated yet');
83                 }
84
85                 $contact_id = Contact::getIdForURL($this->getArgument(0));
86                 if ($contact_id) {
87                         $this->dba->update('contact', ['hidden' => true], ['id' => $contact_id]);
88                         $this->out('The account has been successfully silenced from the global community page.');
89                 } else {
90                         throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')');
91                 }
92
93                 return 0;
94         }
95 }