ScanController.php 1.8 KB

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