Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

76 lines
2.0KB

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