3 namespace Friendica\Core\Console;
5 use Friendica\Core\L10n;
9 * @brief tool to archive a contact on the server
11 * With this tool you can archive a contact when you know that it isn't existing anymore.
12 * Normally this does happen automatically after a few days.
14 * License: AGPLv3 or later, same as Friendica
17 class ArchiveContact extends \Asika\SimpleConsole\Console
19 protected $helpOptions = ['h', 'help', '?'];
21 protected function getHelp()
24 console archivecontact - archive a contact
26 bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
29 Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
32 -h|--help|-? Show help information
33 -v Show more debug information.
38 protected function doExecute()
42 if ($this->getOption('v')) {
43 $this->out('Class: ' . __CLASS__);
44 $this->out('Arguments: ' . var_export($this->args, true));
45 $this->out('Options: ' . var_export($this->options, true));
48 if (count($this->args) == 0) {
49 $this->out($this->getHelp());
53 if (count($this->args) > 1) {
54 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
57 if ($a->mode === App::MODE_INSTALL) {
58 throw new \RuntimeException('Friendica isn\'t properly installed yet.');
61 $nurl = normalise_link($this->getArgument(0));
62 if (!dba::exists('contact', ['nurl' => $nurl, 'archive' => false])) {
63 throw new \RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
65 if (dba::update('contact', ['archive' => true], ['nurl' => $nurl])) {
66 $condition = ["`cid` IN (SELECT `id` FROM `contact` WHERE `archive`)"];
67 dba::delete('queue', $condition);
68 $this->out(L10n::t('The contact entries have been archived'));
70 throw new \RuntimeException('The contact archival failed.');