3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Console;
25 use Friendica\Database\Database;
27 use Friendica\Util\Strings;
31 * tool to archive a contact on the server
33 * With this tool you can archive a contact when you know that it isn't existing anymore.
34 * Normally this does happen automatically after a few days.
36 * License: AGPLv3 or later, same as Friendica
39 class ArchiveContact extends \Asika\SimpleConsole\Console
41 protected $helpOptions = ['h', 'help', '?'];
52 * @var \Friendica\Core\L10n
56 protected function getHelp()
59 console archivecontact - archive a contact
61 bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
64 Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
67 -h|--help|-? Show help information
68 -v Show more debug information.
73 public function __construct(App\Mode $appMode, Database $dba, \Friendica\Core\L10n $l10n, array $argv = null)
75 parent::__construct($argv);
77 $this->appMode = $appMode;
82 protected function doExecute()
84 if ($this->getOption('v')) {
85 $this->out('Class: ' . __CLASS__);
86 $this->out('Arguments: ' . var_export($this->args, true));
87 $this->out('Options: ' . var_export($this->options, true));
90 if (count($this->args) == 0) {
91 $this->out($this->getHelp());
95 if (count($this->args) > 1) {
96 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
99 if ($this->appMode->isInstall()) {
100 throw new RuntimeException('Friendica isn\'t properly installed yet.');
103 $nurl = Strings::normaliseLink($this->getArgument(0));
104 if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
105 throw new RuntimeException(DI::l10n()->t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
107 if ($this->dba->update('contact', ['archive' => true], ['nurl' => $nurl])) {
108 $this->out($this->l10n->t('The contact entries have been archived'));
110 throw new RuntimeException('The contact archival failed.');