3 namespace Friendica\Console;
6 use Friendica\Database\Database;
7 use Friendica\Util\Strings;
11 * tool to archive a contact on the server
13 * With this tool you can archive a contact when you know that it isn't existing anymore.
14 * Normally this does happen automatically after a few days.
16 * License: AGPLv3 or later, same as Friendica
19 class ArchiveContact extends \Asika\SimpleConsole\Console
21 protected $helpOptions = ['h', 'help', '?'];
32 * @var \Friendica\Core\L10n
36 protected function getHelp()
39 console archivecontact - archive a contact
41 bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
44 Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
47 -h|--help|-? Show help information
48 -v Show more debug information.
53 public function __construct(App\Mode $appMode, Database $dba, \Friendica\Core\L10n $l10n, array $argv = null)
55 parent::__construct($argv);
57 $this->appMode = $appMode;
62 protected function doExecute()
64 if ($this->getOption('v')) {
65 $this->out('Class: ' . __CLASS__);
66 $this->out('Arguments: ' . var_export($this->args, true));
67 $this->out('Options: ' . var_export($this->options, true));
70 if (count($this->args) == 0) {
71 $this->out($this->getHelp());
75 if (count($this->args) > 1) {
76 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
79 if ($this->appMode->isInstall()) {
80 throw new RuntimeException('Friendica isn\'t properly installed yet.');
83 $nurl = Strings::normaliseLink($this->getArgument(0));
84 if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
85 throw new RuntimeException(DI::l10n()->t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
87 if ($this->dba->update('contact', ['archive' => true], ['nurl' => $nurl])) {
88 $this->out($this->l10n->t('The contact entries have been archived'));
90 throw new RuntimeException('The contact archival failed.');