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.

GlobalCommunityBlock.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Friendica\Core\Console;
  3. use Friendica\Core\L10n;
  4. use Friendica\Model\Contact;
  5. /**
  6. * @brief tool to block an account from the node
  7. *
  8. * With this tool, you can block an account in such a way, that no postings
  9. * or comments this account writes are accepted to the node.
  10. *
  11. * License: AGPLv3 or later, same as Friendica
  12. *
  13. * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
  14. * @author Hypolite Petovan <hypolite@mrpetovan.com>
  15. */
  16. class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
  17. {
  18. protected $helpOptions = ['h', 'help', '?'];
  19. protected function getHelp()
  20. {
  21. $help = <<<HELP
  22. console globalcommunityblock - Block remote profile from interacting with this node
  23. Usage
  24. bin/console globalcommunityblock <profile_url> [-h|--help|-?] [-v]
  25. Description
  26. Blocks an account in such a way that no postings or comments this account writes are accepted to this node.
  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 = get_app();
  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('Database isn\'t ready or populated yet');
  50. }
  51. $contact_id = Contact::getIdForURL($this->getArgument(0));
  52. if (!$contact_id) {
  53. throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $nurl));
  54. }
  55. if(Contact::block($contact_id)) {
  56. $this->out(L10n::t('The contact has been blocked from the node'));
  57. } else {
  58. throw new \RuntimeException('The contact block failed.');
  59. }
  60. return 0;
  61. }
  62. }