getCurrentRootUidOrAbort(); } catch (NoSiteSelected $e) { $this->view->assign('pageSelected', 0); return; } $this->view->assign('pageSelected', 1); $this->view->assign('rootPage', $rootUid); $statsSettingsRepository = GeneralUtility::makeInstance(StatsSettingsRepository::class); $matomoId = $statsSettingsRepository->getMatomoSiteId($rootUid); $statsActivated = ($matomoId !== null); $this->view->assign('statsActivated', (int)$statsActivated); if (!$statsActivated) { return; } $this->view->assign('matomoSiteId', (int)$matomoId); } /** * Creates a matomo site record if none exists and * save its id */ public function enableStatsAction() { // Get the current page uid try { $rootUid = $this->getCurrentRootUidOrAbort(); } catch (NoSiteSelected $e) { $this->forward('index'); } $matomoRepository = GeneralUtility::makeInstance(MatomoWebsiteRepository::class); try { $matomoRepository->createFor($rootUid); } catch (\RuntimeException $e) { $this->view->assign( 'errorMsg', "Une erreur s'est produite lors de l'opération, veuillez contacter un administrateur" ); } $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) { $this->view->assign( 'errorMsg', "Une erreur s'est produite lors de l'opération, veuillez contacter un administrateur" ); } $this->forward('index'); } /** * Display a confirmation page */ public function confirmDeletionAction() { try { $rootUid = $this->getCurrentRootUidOrAbort(); } catch (NoSiteSelected $e) { $this->forward('index'); } $this->view->assign('rootUid', $rootUid); } /** * Return the root uid of the currently selected website if any, * or throw a NoSiteSelected exception * * @return int|mixed * @throws NoSiteSelected */ private function getCurrentRootUidOrAbort() { $rootUid = (int)GeneralUtility::_GP('id'); $otPageRepository = GeneralUtility::makeInstance(OtPageRepository::class); $rootPage = $otPageRepository->getRootPageFor($rootUid); $rootUid = $rootPage['uid'] ?? 0; if (!$rootUid > 0) { throw new NoSiteSelected(); } return $rootUid; } }