3 namespace Friendica\Core\Console;
5 use Friendica\Core\L10n;
6 use Friendica\Database\DBA;
7 use Friendica\Util\Strings;
11 * @brief 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', '?'];
23 protected function getHelp()
26 console archivecontact - archive a contact
28 bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
31 Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
34 -h|--help|-? Show help information
35 -v Show more debug information.
40 protected function doExecute()
42 $a = \Friendica\BaseObject::getApp();
44 if ($this->getOption('v')) {
45 $this->out('Class: ' . __CLASS__);
46 $this->out('Arguments: ' . var_export($this->args, true));
47 $this->out('Options: ' . var_export($this->options, true));
50 if (count($this->args) == 0) {
51 $this->out($this->getHelp());
55 if (count($this->args) > 1) {
56 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
59 if ($a->getMode()->isInstall()) {
60 throw new RuntimeException('Friendica isn\'t properly installed yet.');
63 $nurl = Strings::normaliseLink($this->getArgument(0));
64 if (!DBA::exists('contact', ['nurl' => $nurl, 'archive' => false])) {
65 throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
67 if (DBA::update('contact', ['archive' => true], ['nurl' => $nurl])) {
68 $condition = ["`cid` IN (SELECT `id` FROM `contact` WHERE `archive`)"];
69 DBA::delete('queue', $condition);
70 $this->out(L10n::t('The contact entries have been archived'));
72 throw new RuntimeException('The contact archival failed.');