| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace Opentalent\OtStats\Controller;
- use Opentalent\OtCore\Cache\OtCacheManager;
- use Opentalent\OtCore\Controller\SelectedSiteController;
- use Opentalent\OtCore\Logging\OtLogger;
- use Opentalent\OtCore\Messaging\FlashMessageService;
- use Opentalent\OtStats\Domain\Repository\MatomoWebsiteRepository;
- use Opentalent\OtStats\Settings\StatsSettingsRepository;
- use TYPO3\CMS\Core\Messaging\AbstractMessage;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
- /**
- * Controller for the OtStats backend submodule
- *
- * @author olivier.massot
- */
- class OtStatsController extends SelectedSiteController {
- /**
- * Index action (default action)
- * Displays the customizer page on the backend
- */
- public function indexAction() {
- $this->view->assign('rootPage', $this->currentRootUid);
- $statsSettingsRepository = GeneralUtility::makeInstance(StatsSettingsRepository::class);
- $matomoId = $statsSettingsRepository->getMatomoSiteId($this->currentRootUid);
- if ($matomoId == null) {
- $this->forward('askForActivationConfirmation');
- }
- $this->view->assign('matomoSiteId', (int)$matomoId);
- }
- /**
- * Display a confirmation page before enabling the stats module
- */
- public function askForActivationConfirmationAction() {}
- /**
- * Display a confirmation page before disabling the stats module
- */
- public function askForDeactivationConfirmationAction() {
- $this->view->assign('rootUid', $this->currentRootUid);
- }
- /**
- * Creates a matomo site record if none exists and
- * save its id
- */
- public function enableStatsAction() {
- $matomoRepository = GeneralUtility::makeInstance(MatomoWebsiteRepository::class);
- try {
- $matomoRepository->createFor($this->currentRootUid);
- } catch (\RuntimeException $e) {
- OtLogger::error("OtStats - " . $e);
- $this->addFlashMessage(
- "Une erreur s'est produite lors de l'opération, veuillez contacter un administrateur.",
- '',
- AbstractMessage::ERROR
- );
- $this->forward('askForActivationConfirmation');
- }
- $this->forward('index');
- }
- /**
- * Disable the stats monitoring
- *
- * @param int $rootUid Pass the rootUid of the site as an argument to confirm of the decision
- * of disabling the website. If no rootUid is passed, the user will be redirected to a
- * confirmation page.
- * @throws StopActionException
- */
- public function disableStatsAction(int $rootUid) {
- $matomoRepository = GeneralUtility::makeInstance(MatomoWebsiteRepository::class);
- try {
- $matomoRepository->disableFor($rootUid);
- } catch (\RuntimeException $e) {
- OtLogger::error("OtStats - " . $e);
- $this->addFlashMessage(
- "Une erreur s'est produite lors de l'opération, veuillez contacter un administrateur.",
- '',
- AbstractMessage::ERROR
- );
- }
- $this->forward('askForActivationConfirmation');
- }
- }
|