3 namespace Friendica\Console;
6 use Friendica\Core\L10n;
7 use Friendica\Database\Database;
8 use Friendica\Util\Strings;
12 * @brief tool to archive a contact on the server
14 * With this tool you can archive a contact when you know that it isn't existing anymore.
15 * Normally this does happen automatically after a few days.
17 * License: AGPLv3 or later, same as Friendica
20 class ArchiveContact extends \Asika\SimpleConsole\Console
22 protected $helpOptions = ['h', 'help', '?'];
37 protected function getHelp()
40 console archivecontact - archive a contact
42 bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
45 Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
48 -h|--help|-? Show help information
49 -v Show more debug information.
54 public function __construct(App\Mode $appMode, Database $dba, L10n\L10n $l10n, array $argv = null)
56 parent::__construct($argv);
58 $this->appMode = $appMode;
63 protected function doExecute()
65 if ($this->getOption('v')) {
66 $this->out('Class: ' . __CLASS__);
67 $this->out('Arguments: ' . var_export($this->args, true));
68 $this->out('Options: ' . var_export($this->options, true));
71 if (count($this->args) == 0) {
72 $this->out($this->getHelp());
76 if (count($this->args) > 1) {
77 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
80 if ($this->appMode->isInstall()) {
81 throw new RuntimeException('Friendica isn\'t properly installed yet.');
84 $nurl = Strings::normaliseLink($this->getArgument(0));
85 if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
86 throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
88 if ($this->dba->update('contact', ['archive' => true], ['nurl' => $nurl])) {
89 $this->out($this->l10n->t('The contact entries have been archived'));
91 throw new RuntimeException('The contact archival failed.');