]> git.mxchange.org Git - friendica.git/blob - src/Console/GlobalCommunitySilence.php
Use correct placeholder
[friendica.git] / src / Console / GlobalCommunitySilence.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Console;
23
24 use Friendica\App;
25 use Friendica\Database\Database;
26 use Friendica\Model\Contact;
27 use RuntimeException;
28
29 /**
30  * tool to silence accounts on the global community page
31  *
32  * With this tool, you can silence an account on the global community page.
33  * Postings from silenced accounts will not be displayed on the community
34  * page. This silencing does only affect the display on the community page,
35  * accounts following the silenced accounts will still get their postings.
36  */
37 class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
38 {
39         protected $helpOptions = ['h', 'help', '?'];
40
41         /**
42          * @var App\Mode
43          */
44         private $appMode;
45         /**
46          * @var Database
47          */
48         private $dba;
49
50         protected function getHelp()
51         {
52                 $help = <<<HELP
53 console globalcommunitysilence - Silence a profile from the global community page
54 Usage
55         bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
56
57 Description
58         With this tool, you can silence an account on the global community page.
59         Postings from silenced accounts will not be displayed on the community page.
60         This silencing does only affect the display on the community page, accounts
61         following the silenced accounts will still get their postings.
62
63 Options
64     -h|--help|-? Show help information
65     -v           Show more debug information.
66 HELP;
67                 return $help;
68         }
69
70         public function __construct(App\Mode $appMode, Database $dba, array $argv = null)
71         {
72                 parent::__construct($argv);
73
74                 $this->appMode = $appMode;
75                 $this->dba  =$dba;
76         }
77
78         protected function doExecute()
79         {
80                 if ($this->getOption('v')) {
81                         $this->out('Class: ' . __CLASS__);
82                         $this->out('Arguments: ' . var_export($this->args, true));
83                         $this->out('Options: ' . var_export($this->options, true));
84                 }
85
86                 if (count($this->args) == 0) {
87                         $this->out($this->getHelp());
88                         return 0;
89                 }
90
91                 if (count($this->args) > 1) {
92                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
93                 }
94
95                 if ($this->appMode->isInstall()) {
96                         throw new RuntimeException('Database isn\'t ready or populated yet');
97                 }
98
99                 $contact_id = Contact::getIdForURL($this->getArgument(0));
100                 if ($contact_id) {
101                         Contact::update(['hidden' => true], ['id' => $contact_id]);
102                         $this->out('The account has been successfully silenced from the global community page.');
103                 } else {
104                         throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')');
105                 }
106
107                 return 0;
108         }
109 }