/Controllers/Cli/Moderation.php

https://github.com/Minds/engine · PHP · 159 lines · 120 code · 35 blank · 4 comment · 11 complexity · 0a8204d34ddba217b99578d2452c9644 MD5 · raw file

  1. <?php
  2. namespace Minds\Controllers\Cli;
  3. use Minds\Core;
  4. use Minds\Core\Di\Di;
  5. use Minds\Cli;
  6. use Minds\Core\Reports\Strikes\Strike;
  7. use Minds\Core\Reports\Summons\Summons;
  8. use Minds\Interfaces;
  9. use Minds\Entities;
  10. class Moderation extends Cli\Controller implements Interfaces\CliControllerInterface
  11. {
  12. public function __construct()
  13. {
  14. }
  15. public function help($command = null)
  16. {
  17. $this->out('TBD');
  18. }
  19. public function exec()
  20. {
  21. error_reporting(E_ALL);
  22. ini_set('display_errors', 1);
  23. }
  24. public function runVerdicts()
  25. {
  26. error_reporting(E_ALL);
  27. ini_set('display_errors', 1);
  28. $manager = Di::_()->get('Moderation\Verdict\Manager');
  29. $manager->run($this->getOpt('jury') ?? 'initial');
  30. }
  31. public function summon()
  32. {
  33. error_reporting(E_ALL);
  34. ini_set('display_errors', 1);
  35. /** @var Core\Reports\Repository $reportsRepository */
  36. $reportsRepository = Di::_()->get('Reports\Repository');
  37. /** @var Core\Queue\Interfaces\QueueClient $queueClient */
  38. $queueClient = Core\Queue\Client::build();
  39. $reportUrn = $this->getOpt('report');
  40. $cohort = $this->getOpt('cohort');
  41. if (!$reportUrn || !$cohort) {
  42. $this->out([
  43. 'Usage:',
  44. ' - cli.php moderation summon --report=<report_urn> --cohort=<guid1, guid2, ..., guidN>',
  45. ' - cli.php moderation summon --report=<report_urn> --cohort=auto',
  46. ]);
  47. exit(1);
  48. }
  49. $guids = null;
  50. if ($cohort !== 'auto') {
  51. $guids = explode(',', $cohort);
  52. }
  53. $report = $reportsRepository->get($reportUrn);
  54. if (!$report) {
  55. $this->out('Error: Invalid report');
  56. exit(1);
  57. } elseif ($report->getState() !== 'initial_jury_decided') {
  58. $this->out("Error: Report is not appealable. State is [{$report->getState()}].");
  59. exit(1);
  60. }
  61. $appeal = new Core\Reports\Appeals\Appeal();
  62. $appeal
  63. ->setReport($report)
  64. ->setOwnerGuid($report->getEntityOwnerGuid());
  65. $queueClient
  66. ->setQueue('ReportsAppealSummon')
  67. ->send([
  68. 'appeal' => $appeal,
  69. 'cohort' => $guids ?: null,
  70. ]);
  71. $this->out('Sent to summon queue!');
  72. }
  73. public function dev_only_summon_individual()
  74. {
  75. error_reporting(E_ALL);
  76. ini_set('display_errors', 1);
  77. /** @var Core\Reports\Repository $reportsRepository */
  78. $reportsRepository = Di::_()->get('Reports\Repository');
  79. /** @var Core\Reports\Summons\Manager $summonsManager */
  80. $summonsManager = Di::_()->get('Moderation\Summons\Manager');
  81. $userId = $this->getOpt('user');
  82. $reportUrn = $this->getOpt('report');
  83. $juryType = $this->getOpt('jury-type') ?? null;
  84. $respond = $this->getOpt('respond') ?? null;
  85. $activeThreshold = $this->getOpt('active-threshold') ?? 5 * 60;
  86. if (!$userId || !$reportUrn) {
  87. $this->out([
  88. 'Usage:',
  89. '- Summoning: cli.php moderation dev_only_summon_individual --user=<username_or_guid> --report=<report_urn>',
  90. '- Responding: cli.php moderation dev_only_summon_individual --user=<username_or_guid> --report=<report_urn> --jury-type=<initial_jury|appeal_jury> --respond=<accepted|declined>',
  91. ]);
  92. exit(1);
  93. }
  94. $user = new Entities\User($userId, false);
  95. if (!$user || !$user->guid) {
  96. $this->out('Error: Invalid user');
  97. exit(1);
  98. }
  99. if (!$respond) {
  100. $report = $reportsRepository->get($reportUrn);
  101. if (!$report) {
  102. $this->out('Error: Invalid report');
  103. exit(1);
  104. }
  105. $appeal = new Core\Reports\Appeals\Appeal();
  106. $appeal->setReport($report);
  107. $missing = $summonsManager->summon($appeal, [
  108. 'include_only' => [ (string) $user->guid ],
  109. 'active_threshold' => (int) $activeThreshold,
  110. ]);
  111. $this->out("Summoned {$user->guid} to {$reportUrn}");
  112. $this->out("${missing} juror(s) missing.");
  113. } else {
  114. $summons = new Summons();
  115. $summons
  116. ->setReportUrn($reportUrn)
  117. ->setJuryType($juryType)
  118. ->setJurorGuid((string) $user->guid)
  119. ->setStatus($respond);
  120. $summonsManager->respond($summons);
  121. $this->out("Responded to {$user->guid}'s summons to {$reportUrn} with {$respond}");
  122. }
  123. }
  124. }