X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FConsole%2FGlobalCommunitySilence.php;h=5d1f692634246e01ac2b8d007f20a166e5493f38;hb=d4a5a8051ad34a7be72238967afb3e6b140afdc8;hp=daaf55149979f7098cd962326883f1e1c1396873;hpb=d716a3326f4e7846e19ec2454054f6d20a71507a;p=friendica.git diff --git a/src/Console/GlobalCommunitySilence.php b/src/Console/GlobalCommunitySilence.php index daaf551499..5d1f692634 100644 --- a/src/Console/GlobalCommunitySilence.php +++ b/src/Console/GlobalCommunitySilence.php @@ -1,34 +1,56 @@ . + * + */ namespace Friendica\Console; -use Friendica\Core\Protocol; -use Friendica\Database\DBA; -use Friendica\Network\Probe; -use Friendica\Util\Strings; +use Friendica\App; +use Friendica\Database\Database; +use Friendica\Model\Contact; use RuntimeException; /** - * @brief tool to silence accounts on the global community page + * tool to silence accounts on the global community page * * 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. - * - * License: AGPLv3 or later, same as Friendica - * - * @author Tobias Diekershoff - * @author Hypolite Petovan */ class GlobalCommunitySilence extends \Asika\SimpleConsole\Console { protected $helpOptions = ['h', 'help', '?']; + /** + * @var App\Mode + */ + private $appMode; + /** + * @var Database + */ + private $dba; + protected function getHelp() { $help = << [-h|--help|-?] [-v] @@ -45,10 +67,16 @@ HELP; return $help; } - protected function doExecute() + public function __construct(App\Mode $appMode, Database $dba, array $argv = null) { - $a = \get_app(); + parent::__construct($argv); + + $this->appMode = $appMode; + $this->dba =$dba; + } + protected function doExecute(): int + { if ($this->getOption('v')) { $this->out('Class: ' . __CLASS__); $this->out('Arguments: ' . var_export($this->args, true)); @@ -64,27 +92,16 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - if ($a->getMode()->isInstall()) { + if ($this->appMode->isInstall()) { 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 = Strings::normaliseLink($net['url']); - $contact = DBA::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]); - if (DBA::isResult($contact)) { - DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]); - $this->out('NOTICE: The account should be silenced from the global community page'); + $contact_id = Contact::getIdForURL($this->getArgument(0)); + if ($contact_id) { + Contact::update(['hidden' => true], ['id' => $contact_id]); + $this->out('The account has been successfully silenced from the global community page.'); } else { - throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')'); + throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')'); } return 0;