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