3 * @copyright Copyright (C) 2010-2022, 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\Model\Contact;
28 use Friendica\Util\Strings;
32 * tool to archive a contact on the server
34 * With this tool you can archive a contact when you know that it isn't existing anymore.
35 * Normally this does happen automatically after a few days.
37 * License: AGPLv3 or later, same as Friendica
40 class ArchiveContact extends \Asika\SimpleConsole\Console
42 protected $helpOptions = ['h', 'help', '?'];
53 * @var \Friendica\Core\L10n
57 protected function getHelp()
60 console archivecontact - archive a contact
62 bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
65 Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
68 -h|--help|-? Show help information
69 -v Show more debug information.
74 public function __construct(App\Mode $appMode, Database $dba, \Friendica\Core\L10n $l10n, array $argv = null)
76 parent::__construct($argv);
78 $this->appMode = $appMode;
83 protected function doExecute(): int
85 if ($this->getOption('v')) {
86 $this->out('Class: ' . __CLASS__);
87 $this->out('Arguments: ' . var_export($this->args, true));
88 $this->out('Options: ' . var_export($this->options, true));
91 if (count($this->args) == 0) {
92 $this->out($this->getHelp());
96 if (count($this->args) > 1) {
97 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
100 if ($this->appMode->isInstall()) {
101 throw new RuntimeException('Friendica isn\'t properly installed yet.');
104 $nurl = Strings::normaliseLink($this->getArgument(0));
105 if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
106 throw new RuntimeException(DI::l10n()->t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
108 if (Contact::update(['archive' => true], ['nurl' => $nurl])) {
109 $this->out($this->l10n->t('The contact entries have been archived'));
111 throw new RuntimeException('The contact archival failed.');