ScanController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Opentalent\OtAdmin\Controller;
  3. use Opentalent\OtAdmin\Domain\Entity\ScanReport;
  4. use Opentalent\OtCore\Controller\ActionController;
  5. use Opentalent\OtCore\Domain\Repository\OrganizationRepository;
  6. use TYPO3\CMS\Core\Database\ConnectionPool;
  7. use TYPO3\CMS\Core\Utility\GeneralUtility;
  8. use TYPO3\CMS\Extbase\Object\ObjectManager;
  9. /**
  10. * ScanController scan the Typo3 DB to find potential issues
  11. */
  12. class ScanController extends ActionController
  13. {
  14. public function __construct(
  15. private readonly SiteController $siteController,
  16. private readonly OrganizationRepository $organizationRepository
  17. ) {
  18. parent::__construct();
  19. }
  20. /**
  21. * Perform a full scan of the Typo3 DB, and confront it to the
  22. * Opentalent organizations list.
  23. *
  24. * @param bool $fullScan If true, a 'warnings' entry will be added to the result of each site status,
  25. * and a full scan of the website pages will be performed.
  26. * @param callable|null $progressCallback Expects a function that takes 2 parameters : the current step, and the max
  27. * @return ScanReport
  28. */
  29. public function scanAllAction(bool $fullScan = false, ?callable $progressCallback = null): ScanReport
  30. {
  31. $report = new ScanReport();
  32. $organizationsCollection = $this->organizationRepository->getAll();
  33. $i = 0;
  34. $total = count($organizationsCollection->getMembers());
  35. foreach ($organizationsCollection->getMembers() as $organization) {
  36. $i++;
  37. $status = $this->siteController->getSiteStatusAction($organization->getId(), $fullScan);
  38. $report->setResultFor($organization->getId(), $status);
  39. if ($progressCallback !== null) {
  40. $progressCallback($i, $total);
  41. }
  42. }
  43. return $report;
  44. }
  45. }