]> git.mxchange.org Git - friendica.git/blob - src/Core/Console/GlobalCommunitySilence.php
Rename Friendica\Database\dba to Friendica\Database\DBA
[friendica.git] / src / Core / Console / GlobalCommunitySilence.php
1 <?php
2
3 namespace Friendica\Core\Console;
4
5 use Friendica\Core\Protocol;
6 use Friendica\Database\DBA;
7 use Friendica\Database\DBM;
8 use Friendica\Network\Probe;
9 use RuntimeException;
10
11 require_once 'include/text.php';
12
13 /**
14  * @brief tool to silence accounts on the global community page
15  *
16  * With this tool, you can silence an account on the global community page.
17  * Postings from silenced accounts will not be displayed on the community
18  * page. This silencing does only affect the display on the community page,
19  * accounts following the silenced accounts will still get their postings.
20  *
21  * License: AGPLv3 or later, same as Friendica
22  *
23  * @author Tobias Diekershoff
24  * @author Hypolite Petovan <mrpetovan@gmail.com>
25  */
26 class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
27 {
28         protected $helpOptions = ['h', 'help', '?'];
29
30         protected function getHelp()
31         {
32                 $help = <<<HELP
33 console globalcommunitysilence - Silence remote profile from global community page
34 Usage
35         bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
36
37 Description
38         With this tool, you can silence an account on the global community page.
39         Postings from silenced accounts will not be displayed on the community page.
40         This silencing does only affect the display on the community page, accounts
41         following the silenced accounts will still get their postings.
42
43 Options
44     -h|--help|-? Show help information
45     -v           Show more debug information.
46 HELP;
47                 return $help;
48         }
49
50         protected function doExecute()
51         {
52                 $a = get_app();
53
54                 if ($this->getOption('v')) {
55                         $this->out('Class: ' . __CLASS__);
56                         $this->out('Arguments: ' . var_export($this->args, true));
57                         $this->out('Options: ' . var_export($this->options, true));
58                 }
59
60                 if (count($this->args) == 0) {
61                         $this->out($this->getHelp());
62                         return 0;
63                 }
64
65                 if (count($this->args) > 1) {
66                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
67                 }
68
69                 if ($a->isInstallMode()) {
70                         throw new RuntimeException('Database isn\'t ready or populated yet');
71                 }
72
73                 /**
74                  * 1. make nurl from last parameter
75                  * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
76                  * 3. set the flag hidden=1 for the contact entry with the found ID
77                  * */
78                 $net = Probe::uri($this->getArgument(0));
79                 if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
80                         throw new RuntimeException('This account seems not to exist.');
81                 }
82
83                 $nurl = normalise_link($net['url']);
84                 $contact = DBA::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
85                 if (DBM::is_result($contact)) {
86                         DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
87                         $this->out('NOTICE: The account should be silenced from the global community page');
88                 } else {
89                         throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
90                 }
91
92                 return 0;
93         }
94 }