ScanController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  19. * Perform a full scan of the Typo3 DB, and confront it to the
  20. * Opentalent organizations list.
  21. *
  22. * @param bool $fullScan If true, a 'warnings' entry will be added to the result of each site status,
  23. * and a full scan of the website pages will be performed.
  24. * @param callable|null $progressCallback Expects a function that takes 2 parameters : the current step, and the max
  25. * @return ScanReport
  26. */
  27. public function scanAllAction(bool $fullScan = false, ?callable $progressCallback = null): ScanReport
  28. {
  29. $report = new ScanReport();
  30. $organizationsCollection = $this->organizationRepository->getAll();
  31. $i = 0;
  32. $total = count($organizationsCollection->getMembers());
  33. foreach ($organizationsCollection->getMembers() as $organization) {
  34. $i++;
  35. $status = $this->siteController->getSiteStatusAction($organization->getId(), $fullScan);
  36. $report->setResultFor($organization->getId(), $status);
  37. if ($progressCallback !== null) {
  38. $progressCallback($i, $total);
  39. }
  40. }
  41. return $report;
  42. }
  43. }