ScanController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Opentalent\OtAdmin\Controller;
  3. use Opentalent\OtCore\Controller\ActionController;
  4. use Opentalent\OtCore\Domain\Repository\OrganizationRepository;
  5. use TYPO3\CMS\Core\Utility\GeneralUtility;
  6. use TYPO3\CMS\Extbase\Object\ObjectManager;
  7. /**
  8. * The ScanController allows to scan the Typo3 DB to find potential issues
  9. */
  10. class ScanController extends ActionController
  11. {
  12. /**
  13. * Perform a full scan of the Typo3 DB, and confront it to the
  14. * Opentalent organizations list.
  15. *
  16. * Result is an array of the form:
  17. *
  18. * [
  19. * 'date' => Datetime,
  20. * 'stats' => [
  21. * status => count,
  22. * ...
  23. * ]
  24. * 'results' => [
  25. * organization_id => status,
  26. * ...
  27. * ]
  28. * ]
  29. *
  30. *
  31. * @param bool $fullScan If true, a 'warnings' entry will be added to the result of each site status,
  32. * and a full scan of the website pages will be performed.
  33. * @return array
  34. */
  35. public function scanAllAction(bool $fullScan = false): array
  36. {
  37. $organizationRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OrganizationRepository::class);
  38. $siteController = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
  39. $results = [];
  40. $stats = [];
  41. $organizationsCollection = $organizationRepository->getAll();
  42. foreach ($organizationsCollection->getMembers() as $organization) {
  43. $status = $siteController->getSiteStatusAction($organization->getId(), $fullScan);
  44. $results[$organization->getId()] = $status;
  45. if (!isset($stats[$status['status']])) {
  46. $stats[$status['status']] = 0;
  47. }
  48. $stats[$status['status']] += 1;
  49. }
  50. return [
  51. 'date' => new \DateTime(),
  52. 'stats' => $stats,
  53. 'results' => $results
  54. ];
  55. }
  56. }