<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
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 <tobias.diekershoff@gmx.net>
- * @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var Database
+ */
+ private $dba;
+
protected function getHelp()
{
$help = <<<HELP
-console globalcommunitysilence - Silence remote profile from global community page
+console globalcommunitysilence - Silence a profile from the global community page
Usage
bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
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));
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;