X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConsole%2FGlobalCommunitySilence.php;h=6330d08a12afc3f8055f733aae8673d8e0e18ad7;hb=daa1177e3a1e42b4c95e0a8759f1610942b952c7;hp=069750afc6f86b8ccde5b28e46a7c83cb354da70;hpb=27d94023eef0263a3ce9750f79a73ac941a25304;p=friendica.git diff --git a/src/Core/Console/GlobalCommunitySilence.php b/src/Core/Console/GlobalCommunitySilence.php index 069750afc6..6330d08a12 100644 --- a/src/Core/Console/GlobalCommunitySilence.php +++ b/src/Core/Console/GlobalCommunitySilence.php @@ -1,94 +1,94 @@ - - */ -class GlobalCommunitySilence extends \Asika\SimpleConsole\Console -{ - protected $helpOptions = ['h', 'help', '?']; - - protected function getHelp() - { - $help = << [-h|--help|-?] [-v] - -Description - With this tool, you can silence an account on the global community page. - Postings from silenced accounts will not be displayed on the community page. - This silencing does only affect the display on the community page, accounts - following the silenced accounts will still get their postings. - -Options - -h|--help|-? Show help information - -v Show more debug information. -HELP; - return $help; - } - - protected function doExecute() - { - if ($this->getOption('v')) { - $this->out('Class: ' . __CLASS__); - $this->out('Arguments: ' . var_export($this->args, true)); - $this->out('Options: ' . var_export($this->options, true)); - } - - if (count($this->args) == 0) { - $this->out($this->getHelp()); - return 0; - } - - if (count($this->args) > 1) { - throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); - } - - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); - } - - /** - * 1. make nurl from last parameter - * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID - * 3. set the flag hidden=1 for the contact entry with the found ID - * */ - $net = Probe::uri($this->getArgument(0)); - if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) { - throw new \RuntimeException('This account seems not to exist.'); - } - - $nurl = normalise_link($net['url']); - $contact = \dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]); - if (DBM::is_result($contact)) { - \dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]); - $this->out('NOTICE: The account should be silenced from the global community page'); - } else { - throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')'); - } - - return 0; - } -} + + */ +class GlobalCommunitySilence extends \Asika\SimpleConsole\Console +{ + protected $helpOptions = ['h', 'help', '?']; + + protected function getHelp() + { + $help = << [-h|--help|-?] [-v] + +Description + With this tool, you can silence an account on the global community page. + Postings from silenced accounts will not be displayed on the community page. + This silencing does only affect the display on the community page, accounts + following the silenced accounts will still get their postings. + +Options + -h|--help|-? Show help information + -v Show more debug information. +HELP; + return $help; + } + + protected function doExecute() + { + $a = get_app(); + + if ($this->getOption('v')) { + $this->out('Class: ' . __CLASS__); + $this->out('Arguments: ' . var_export($this->args, true)); + $this->out('Options: ' . var_export($this->options, true)); + } + + if (count($this->args) == 0) { + $this->out($this->getHelp()); + return 0; + } + + if (count($this->args) > 1) { + throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); + } + + if ($a->isInstallMode()) { + throw new RuntimeException('Database isn\'t ready or populated yet'); + } + + /** + * 1. make nurl from last parameter + * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID + * 3. set the flag hidden=1 for the contact entry with the found ID + * */ + $net = Probe::uri($this->getArgument(0)); + if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) { + throw new RuntimeException('This account seems not to exist.'); + } + + $nurl = normalise_link($net['url']); + $contact = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]); + if (DBM::is_result($contact)) { + dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]); + $this->out('NOTICE: The account should be silenced from the global community page'); + } else { + throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')'); + } + + return 0; + } +}