]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Console/GlobalCommunitySilence.php
Merge pull request #7068 from MrPetovan/task/7047-theme-error-page
[friendica.git] / src / Core / Console / GlobalCommunitySilence.php
index 72d5a4f88102d70fa003b9b72162fcf03b23bcb5..b0281241e360c003692ef92efeef0933cf543838 100644 (file)
@@ -3,10 +3,10 @@
 namespace Friendica\Core\Console;
 
 use Friendica\Core\Protocol;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
 use Friendica\Network\Probe;
-
-require_once 'include/text.php';
+use Friendica\Util\Strings;
+use RuntimeException;
 
 /**
  * @brief tool to silence accounts on the global community page
@@ -18,8 +18,8 @@ require_once 'include/text.php';
  *
  * License: AGPLv3 or later, same as Friendica
  *
- * @author Tobias Diekershoff
- * @author Hypolite Petovan <mrpetovan@gmail.com>
+ * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
  */
 class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
 {
@@ -47,7 +47,7 @@ HELP;
 
        protected function doExecute()
        {
-               $a = get_app();
+               $a = \get_app();
 
                if ($this->getOption('v')) {
                        $this->out('Class: ' . __CLASS__);
@@ -64,12 +64,8 @@ HELP;
                        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');
+               if ($a->getMode()->isInstall()) {
+                       throw new RuntimeException('Database isn\'t ready or populated yet');
                }
 
                /**
@@ -79,16 +75,16 @@ HELP;
                 * */
                $net = Probe::uri($this->getArgument(0));
                if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
-                       throw new \RuntimeException('This account seems not to exist.');
+                       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"]]);
+               $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');
                } else {
-                       throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
+                       throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
                }
 
                return 0;