Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchiveContact.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Friendica\Core\Console;
  3. use Friendica\App;
  4. use Friendica\Core\L10n;
  5. use Friendica\Database\DBA;
  6. use RuntimeException;
  7. /**
  8. * @brief tool to archive a contact on the server
  9. *
  10. * With this tool you can archive a contact when you know that it isn't existing anymore.
  11. * Normally this does happen automatically after a few days.
  12. *
  13. * License: AGPLv3 or later, same as Friendica
  14. *
  15. */
  16. class ArchiveContact extends \Asika\SimpleConsole\Console
  17. {
  18. protected $helpOptions = ['h', 'help', '?'];
  19. protected function getHelp()
  20. {
  21. $help = <<<HELP
  22. console archivecontact - archive a contact
  23. Usage
  24. bin/console archivecontact <profile_url> [-h|--help|-?] [-v]
  25. Description
  26. Archive a contact when you know that it isn't existing anymore. Normally this does happen automatically after a few days.
  27. Options
  28. -h|--help|-? Show help information
  29. -v Show more debug information.
  30. HELP;
  31. return $help;
  32. }
  33. protected function doExecute()
  34. {
  35. $a = \Friendica\BaseObject::getApp();
  36. if ($this->getOption('v')) {
  37. $this->out('Class: ' . __CLASS__);
  38. $this->out('Arguments: ' . var_export($this->args, true));
  39. $this->out('Options: ' . var_export($this->options, true));
  40. }
  41. if (count($this->args) == 0) {
  42. $this->out($this->getHelp());
  43. return 0;
  44. }
  45. if (count($this->args) > 1) {
  46. throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
  47. }
  48. if ($a->getMode()->isInstall()) {
  49. throw new RuntimeException('Friendica isn\'t properly installed yet.');
  50. }
  51. $nurl = normalise_link($this->getArgument(0));
  52. if (!DBA::exists('contact', ['nurl' => $nurl, 'archive' => false])) {
  53. throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
  54. }
  55. if (DBA::update('contact', ['archive' => true], ['nurl' => $nurl])) {
  56. $condition = ["`cid` IN (SELECT `id` FROM `contact` WHERE `archive`)"];
  57. DBA::delete('queue', $condition);
  58. $this->out(L10n::t('The contact entries have been archived'));
  59. } else {
  60. throw new RuntimeException('The contact archival failed.');
  61. }
  62. return 0;
  63. }
  64. }