]> git.mxchange.org Git - friendica.git/blobdiff - src/Console/GlobalCommunitySilence.php
Remove deprecated code
[friendica.git] / src / Console / GlobalCommunitySilence.php
index daaf55149979f7098cd962326883f1e1c1396873..f944fcbe27e3fe122722d3c819dc75e5ef02f5ac 100644 (file)
@@ -2,14 +2,13 @@
 
 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
@@ -25,6 +24,15 @@ class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
 {
        protected $helpOptions = ['h', 'help', '?'];
 
+       /**
+        * @var App\Mode
+        */
+       private $appMode;
+       /**
+        * @var Database
+        */
+       private $dba;
+
        protected function getHelp()
        {
                $help = <<<HELP
@@ -45,10 +53,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()
+       {
                if ($this->getOption('v')) {
                        $this->out('Class: ' . __CLASS__);
                        $this->out('Arguments: ' . var_export($this->args, true));
@@ -64,27 +78,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) {
+                       $this->dba->update('contact', ['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;