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