diff --git a/Classes/Backend/Units/AbstractUnit.php b/Classes/Backend/Units/AbstractUnit.php new file mode 100644 index 00000000..8e1ac8c6 --- /dev/null +++ b/Classes/Backend/Units/AbstractUnit.php @@ -0,0 +1,125 @@ +arguments = $arguments; + } + + public function get(): string + { + $this->initialize(); + return $this->getHtml(); + } + + protected function initialize(): void + { + $this->initializeFilter(); + $this->initializeCacheLayer(); + } + + protected function initializeFilter(): void + { + $filter = ObjectUtility::getFilterDto(); + if ($this->filterClass !== '' && $this->filterFunction !== '') { + $filterFromSession = BackendUtility::getSessionValue('filter', $this->filterFunction, $this->filterClass); + if (is_a($filterFromSession, FilterDto::class)) { + $filter = $filterFromSession; + } + } + $this->filter = $filter; + } + + protected function initializeCacheLayer(): void + { + if ($this->cacheLayerClass !== '' && $this->cacheLayerFunction !== '') { + $this->cacheLayer = GeneralUtility::makeInstance(CacheLayer::class); + $this->cacheLayer->initialize($this->cacheLayerClass, $this->cacheLayerFunction); + } + } + + protected function getHtml(): string + { + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setTemplateRootPaths([$this->templateRootPath]); + $view->setPartialRootPaths([$this->partialRootPath]); + $view->setTemplate($this->getTemplatePath()); + $view->assignMultiple([ + 'cacheLayerClass' => $this->cacheLayerClass, + 'cacheLayerFunction' => $this->cacheLayerFunction, + 'filterClass' => $this->filterClass, + 'filterFunction' => $this->filterFunction, + 'cacheLayer' => $this->cacheLayer, + 'filter' => $this->filter, + 'arguments' => $this->arguments, + ] + $this->assignAdditionalVariables()); + return $view->render(); + } + + protected function assignAdditionalVariables(): array + { + return []; + } + + protected function getArgument(string $key): string + { + if (array_key_exists($key, $this->arguments)) { + return (string)$this->arguments[$key]; + } + return ''; + } + + protected function getTemplatePath(): string + { + $path = StringUtility::removeStringPrefix(static::class, $this->classPrefix); + return str_replace('\\', '/', $path); + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Browser.php b/Classes/Backend/Units/Analysis/Dashboard/Browser.php new file mode 100644 index 00000000..0a122e67 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Browser.php @@ -0,0 +1,29 @@ +cacheLayer->isCacheAvailable('Box/Analysis/Browser/' . $this->filter->getHash())) { + return []; + } + return [ + 'browserData' => GeneralUtility::makeInstance(BrowserAmountDataProvider::class, $this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Downloads.php b/Classes/Backend/Units/Analysis/Dashboard/Downloads.php new file mode 100644 index 00000000..d32badc8 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Downloads.php @@ -0,0 +1,29 @@ +cacheLayer->isCacheAvailable('Box/Analysis/Downloads/' . $this->filter->getHash())) { + return []; + } + return [ + 'numberOfDownloadsData' => GeneralUtility::makeInstance(DownloadsDataProvider::class, $this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Pagevisits.php b/Classes/Backend/Units/Analysis/Dashboard/Pagevisits.php new file mode 100644 index 00000000..42572ff3 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Pagevisits.php @@ -0,0 +1,29 @@ +cacheLayer->isCacheAvailable('Box/Analysis/Pagevisits/' . $this->filter->getHash())) { + return []; + } + return [ + 'numberOfVisitorsData' => GeneralUtility::makeInstance(PagevisistsDataProvider::class), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Pagevisitsleads.php b/Classes/Backend/Units/Analysis/Dashboard/Pagevisitsleads.php new file mode 100644 index 00000000..7924122d --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Pagevisitsleads.php @@ -0,0 +1,27 @@ + $pagevisitsRepository->findLatestPagevisits($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Socialmedia.php b/Classes/Backend/Units/Analysis/Dashboard/Socialmedia.php new file mode 100644 index 00000000..c7e7b633 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Socialmedia.php @@ -0,0 +1,29 @@ +cacheLayer->isCacheAvailable('Box/Analysis/SocialMedia/' . $this->filter->getHash())) { + return []; + } + return [ + 'socialMediaData' => GeneralUtility::makeInstance(SocialMediaDataProvider::class, $this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Top/Downloads.php b/Classes/Backend/Units/Analysis/Dashboard/Top/Downloads.php new file mode 100644 index 00000000..d1333745 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Top/Downloads.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Analysis/TopDownloads/' . $this->filter->getHash())) { + return []; + } + $downloadRepository = GeneralUtility::makeInstance(DownloadRepository::class); + return [ + 'downloads' => $downloadRepository->findCombinedByHref($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Top/News.php b/Classes/Backend/Units/Analysis/Dashboard/Top/News.php new file mode 100644 index 00000000..d787d204 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Top/News.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Analysis/TopNews/' . $this->filter->getHash())) { + return []; + } + $newsvisitRepository = GeneralUtility::makeInstance(NewsvisitRepository::class); + return [ + 'news' => $newsvisitRepository->findCombinedByNewsIdentifier($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Top/Pages.php b/Classes/Backend/Units/Analysis/Dashboard/Top/Pages.php new file mode 100644 index 00000000..b8a48ff1 --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Top/Pages.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Analysis/TopPages/' . $this->filter->getHash())) { + return []; + } + $pagevisitsRepository = GeneralUtility::makeInstance(PagevisitRepository::class); + return [ + 'pages' => $pagevisitsRepository->findCombinedByPageIdentifier($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Analysis/Dashboard/Top/Search.php b/Classes/Backend/Units/Analysis/Dashboard/Top/Search.php new file mode 100644 index 00000000..4b7bfbbe --- /dev/null +++ b/Classes/Backend/Units/Analysis/Dashboard/Top/Search.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Analysis/TopSearch/' . $this->filter->getHash())) { + return []; + } + $searchRepository = GeneralUtility::makeInstance(SearchRepository::class); + return [ + 'searchterms' => $searchRepository->findCombinedBySearchIdentifier($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Countrylist.php b/Classes/Backend/Units/Lead/Dashboard/Countrylist.php new file mode 100644 index 00000000..2ce419e6 --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Countrylist.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Leads/CountryList/' . $this->filter->getHash())) { + return []; + } + $ipinformationRepository = GeneralUtility::makeInstance(IpinformationRepository::class); + return [ + 'countries' => $ipinformationRepository->findAllCountryCodesGrouped($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Hottest.php b/Classes/Backend/Units/Lead/Dashboard/Hottest.php new file mode 100644 index 00000000..b3b8ed5c --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Hottest.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Leads/Hottest/' . $this->filter->getHash())) { + return []; + } + $visitorRepository = GeneralUtility::makeInstance(VisitorRepository::class); + return [ + 'hottestVisitors' => $visitorRepository->findByHottestScorings($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Identified.php b/Classes/Backend/Units/Lead/Dashboard/Identified.php new file mode 100644 index 00000000..bd2d9060 --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Identified.php @@ -0,0 +1,31 @@ +cacheLayer->isCacheAvailable('Box/Leads/Identified/' . $this->filter->getHash())) { + return []; + } + $visitorRepository = GeneralUtility::makeInstance(VisitorRepository::class); + return [ + 'numberOfIdentifiedVisitors' => $visitorRepository->findIdentified($this->filter)->count(), + 'numberOfUnknownVisitors' => $visitorRepository->findUnknown($this->filter)->count(), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Identifiedpermethod.php b/Classes/Backend/Units/Lead/Dashboard/Identifiedpermethod.php new file mode 100644 index 00000000..a70f7bc2 --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Identifiedpermethod.php @@ -0,0 +1,32 @@ +cacheLayer->isCacheAvailable('Box/Leads/IdentifiedPerMethod/' . $this->filter->getHash())) { + return []; + } + return [ + 'identificationMethods' => GeneralUtility::makeInstance( + IdentificationMethodsDataProvider::class, + $this->filter + ), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php b/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php new file mode 100644 index 00000000..d35df8cb --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Identifiedpermonth.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Leads/IdentifiedPerMonth/' . $this->filter->getHash())) { + return []; + } + $logRepository = GeneralUtility::makeInstance(LogRepository::class); + return [ + 'identifiedPerMonth' => $logRepository->findIdentifiedLogsFromMonths(), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Map.php b/Classes/Backend/Units/Lead/Dashboard/Map.php new file mode 100644 index 00000000..cce8606c --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Map.php @@ -0,0 +1,30 @@ +cacheLayer->isCacheAvailable('Box/Leads/Map/' . $this->filter->getHash())) { + return []; + } + $ipinformationRepository = GeneralUtility::makeInstance(IpinformationRepository::class); + return [ + 'countries' => $ipinformationRepository->findAllCountryCodesGrouped($this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Recurring.php b/Classes/Backend/Units/Lead/Dashboard/Recurring.php new file mode 100644 index 00000000..e79722ab --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Recurring.php @@ -0,0 +1,31 @@ +cacheLayer->isCacheAvailable('Box/Leads/Recurring/' . $this->filter->getHash())) { + return []; + } + $visitorRepository = GeneralUtility::makeInstance(VisitorRepository::class); + return [ + 'numberOfRecurringSiteVisitors' => $visitorRepository->findByRecurringSiteVisits($this->filter)->count(), + 'numberOfUniqueSiteVisitors' => $visitorRepository->findByUniqueSiteVisits($this->filter)->count(), + ]; + } +} diff --git a/Classes/Backend/Units/Lead/Dashboard/Referrer.php b/Classes/Backend/Units/Lead/Dashboard/Referrer.php new file mode 100644 index 00000000..e8f801aa --- /dev/null +++ b/Classes/Backend/Units/Lead/Dashboard/Referrer.php @@ -0,0 +1,29 @@ +cacheLayer->isCacheAvailable('Box/Leads/Referrer/' . $this->filter->getHash())) { + return []; + } + return [ + 'referrerAmountData' => GeneralUtility::makeInstance(ReferrerAmountDataProvider::class, $this->filter), + ]; + } +} diff --git a/Classes/Backend/Units/Pageoverview/Analysis/Body.php b/Classes/Backend/Units/Pageoverview/Analysis/Body.php new file mode 100644 index 00000000..9fbc4e68 --- /dev/null +++ b/Classes/Backend/Units/Pageoverview/Analysis/Body.php @@ -0,0 +1,78 @@ + $this->getArgument('pageidentifier'), + 'view' => ucfirst(ConfigurationUtility::getPageOverviewView()), + ]; + + if ($this->cacheLayer->isCacheAvailable('PageOverviewContent' . $this->getArgument('pageidentifier'))) { + return $additionalVariables; + } + + $downloadRepository = GeneralUtility::makeInstance(DownloadRepository::class); + $logRepository = GeneralUtility::makeInstance(LogRepository::class); + $linkclickRepository = GeneralUtility::makeInstance(LinkclickRepository::class); + $pagevisitRepository = GeneralUtility::makeInstance(PagevisitRepository::class); + $filter = ObjectUtility::getFilterDto(FilterDto::PERIOD_LAST7DAYS) + ->setSearchterm($this->getArgument('pageidentifier')); + + $additionalVariables = array_merge($additionalVariables, [ + 'conversionAmount' => $logRepository->findAmountOfIdentifiedLogsByPageIdentifierAndTimeFrame( + (int)$this->getArgument('pageidentifier'), + $filter + ), + 'downloadAmount' => $downloadRepository->findAmountByPageIdentifierAndTimeFrame( + (int)$this->getArgument('pageidentifier'), + $filter + ), + 'gotinExternal' => GeneralUtility::makeInstance(GotinExternalDataProvider::class, $filter)->get(), + 'gotinInternal' => GeneralUtility::makeInstance(GotinInternalDataProvider::class, $filter)->get(), + 'gotoutInternal' => GeneralUtility::makeInstance(GotoutInternalDataProvider::class, $filter)->get(), + 'linkclickAmount' => $linkclickRepository->getAmountOfLinkclicksByPageIdentifierAndTimeframe( + (int)$this->getArgument('pageidentifier'), + $filter + ), + 'numberOfVisitorsData' => GeneralUtility::makeInstance( + PagevisistsDataProvider::class, + ObjectUtility::getFilterDto()->setSearchterm($this->getArgument('pageidentifier')) + ), + 'visits' => $pagevisitRepository->findAmountPerPage( + (int)$this->getArgument('pageidentifier'), + $filter + ), + 'visitsLastWeek' => $pagevisitRepository->findAmountPerPage( + (int)$this->getArgument('pageidentifier'), + ObjectUtility::getFilterDto(FilterDto::PERIOD_7DAYSBEFORELAST7DAYS) + ), + ]); + + return $additionalVariables; + } +} diff --git a/Classes/Backend/Units/Pageoverview/Analysis/Title.php b/Classes/Backend/Units/Pageoverview/Analysis/Title.php new file mode 100644 index 00000000..0d744172 --- /dev/null +++ b/Classes/Backend/Units/Pageoverview/Analysis/Title.php @@ -0,0 +1,53 @@ + $this->getArgument('pageidentifier'), + 'status' => $session['status'] ?? 'show', + 'view' => ucfirst(ConfigurationUtility::getPageOverviewView()), + ]; + + if ($this->cacheLayer->isCacheAvailable('PageOverviewTitle' . $this->getArgument('pageidentifier'))) { + return $additionalVariables; + } + + $pagevisitRepository = GeneralUtility::makeInstance(PagevisitRepository::class); + $filter = ObjectUtility::getFilterDto(FilterDto::PERIOD_LAST7DAYS) + ->setSearchterm($this->getArgument('pageidentifier')); + $delta = $pagevisitRepository->compareAmountPerPage( + (int)$this->getArgument('pageidentifier'), + $filter, + ObjectUtility::getFilterDto(FilterDto::PERIOD_7DAYSBEFORELAST7DAYS) + ); + + $additionalVariables = array_merge($additionalVariables, [ + 'abandons' => $pagevisitRepository->findAbandonsForPage((int)$this->getArgument('pageidentifier'), $filter), + 'delta' => $delta, + 'deltaIconPath' => $delta >= 0 ? 'Icons/increase.svg' : 'Icons/decrease.svg', + 'visits' => $pagevisitRepository->findAmountPerPage((int)$this->getArgument('pageidentifier'), $filter), + ]); + + return $additionalVariables; + } +} diff --git a/Classes/Backend/Units/Pageoverview/Leads/Body.php b/Classes/Backend/Units/Pageoverview/Leads/Body.php new file mode 100644 index 00000000..f8dde287 --- /dev/null +++ b/Classes/Backend/Units/Pageoverview/Leads/Body.php @@ -0,0 +1,38 @@ + $this->getArgument('pageidentifier'), + 'view' => ucfirst(ConfigurationUtility::getPageOverviewView()), + ]; + + if ($this->cacheLayer->isCacheAvailable('PageOverviewContent' . $this->getArgument('pageidentifier'))) { + return $additionalVariables; + } + + $visitorRepository = GeneralUtility::makeInstance(VisitorRepository::class); + + $additionalVariables = array_merge($additionalVariables, [ + 'visitors' => $visitorRepository->findByVisitedPageIdentifier((int)$this->getArgument('pageidentifier')), + ]); + + return $additionalVariables; + } +} diff --git a/Classes/Backend/Units/Pageoverview/Leads/Title.php b/Classes/Backend/Units/Pageoverview/Leads/Title.php new file mode 100644 index 00000000..4098fcae --- /dev/null +++ b/Classes/Backend/Units/Pageoverview/Leads/Title.php @@ -0,0 +1,40 @@ + $session['status'] ?? 'show', + 'view' => ucfirst(ConfigurationUtility::getPageOverviewView()), + ]; + + if ($this->cacheLayer->isCacheAvailable('PageOverviewTitle' . $this->getArgument('pageidentifier'))) { + return $additionalVariables; + } + + $additionalVariables = array_merge($additionalVariables, [ + 'visitors' => $visitorRepository->findByVisitedPageIdentifier((int)$this->getArgument('pageidentifier')), + ]); + + return $additionalVariables; + } +} diff --git a/Classes/Backend/Units/UnitFinder.php b/Classes/Backend/Units/UnitFinder.php new file mode 100644 index 00000000..2207a7f7 --- /dev/null +++ b/Classes/Backend/Units/UnitFinder.php @@ -0,0 +1,35 @@ +arguments = $arguments; + } + + /** + * @param string $path + * @return UnitInterface + * @throws ConfigurationException + */ + public function find(string $path): UnitInterface + { + $pathParts = StringUtility::splitCamelcaseString($path); + $classNameUnit = 'In2code\Lux\Backend\Units\\' . implode('\\', $pathParts); + if (class_exists($classNameUnit) === false) { + throw new ConfigurationException('Given class ' . $classNameUnit . ' does not exists', 1694522397); + } + /** @noinspection PhpParamsInspection */ + return GeneralUtility::makeInstance($classNameUnit, $this->arguments); + } +} diff --git a/Classes/Backend/Units/UnitInterface.php b/Classes/Backend/Units/UnitInterface.php new file mode 100644 index 00000000..c01ac80b --- /dev/null +++ b/Classes/Backend/Units/UnitInterface.php @@ -0,0 +1,10 @@ +addArgument( - 'domain', - InputArgument::OPTIONAL, - 'Specify domain if no domain in siteconfiguration like "https://domain.org"', - '' - ); } /** @@ -58,6 +53,7 @@ public function configure() * @throws RouteNotFoundException * @throws UnexpectedValueException * @throws ExceptionDbal + * @throws DBALException */ public function execute(InputInterface $input, OutputInterface $output): int { @@ -75,9 +71,9 @@ public function execute(InputInterface $input, OutputInterface $output): int $configuration = CacheLayerUtility::getCacheLayerConfigurationByRoute($route); if ($configuration['multiple'] === false) { - $this->warmupSingleLayer($route, $input->getArgument('domain'), $configuration); + $this->warmupSingleLayer($route, $configuration); } else { - $this->warmupMultipleLayers($route, $input->getArgument('domain'), $configuration); + $this->warmupMultipleLayers($route, $configuration); } } return self::SUCCESS; @@ -85,21 +81,19 @@ public function execute(InputInterface $input, OutputInterface $output): int /** * @param string $route - * @param string $domain * @param array $configuration * @return void * @throws RouteNotFoundException * @throws UnexpectedValueException * @throws ConfigurationException */ - protected function warmupSingleLayer(string $route, string $domain, array $configuration): void + protected function warmupSingleLayer(string $route, array $configuration): void { - $this->cacheWarmup->warmup($route, $domain, $configuration['arguments'], $this->output); + $this->cacheWarmup->warmup($route, $configuration['arguments'], $this->output); } /** * @param string $route - * @param string $domain * @param array $configuration * @return void * @throws ExceptionDbalDriver @@ -107,14 +101,14 @@ protected function warmupSingleLayer(string $route, string $domain, array $confi * @throws UnexpectedValueException * @throws ConfigurationException * @throws ExceptionDbal + * @throws DBALException */ - protected function warmupMultipleLayers(string $route, string $domain, array $configuration): void + protected function warmupMultipleLayers(string $route, array $configuration): void { $pageRepository = GeneralUtility::makeInstance(PageRepository::class); foreach ($pageRepository->getPageIdentifiersFromNormalDokTypes() as $row) { $this->cacheWarmup->warmup( $route, - $domain, $this->substituteVariablesInArguments($configuration['arguments'], $row), $this->output ); diff --git a/Classes/Controller/AnalysisController.php b/Classes/Controller/AnalysisController.php index 650cabe2..ff9a3c4b 100644 --- a/Classes/Controller/AnalysisController.php +++ b/Classes/Controller/AnalysisController.php @@ -3,11 +3,11 @@ declare(strict_types=1); namespace In2code\Lux\Controller; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver; use Doctrine\DBAL\Exception as ExceptionDbal; use Exception; use In2code\Lux\Domain\DataProvider\AllLinkclickDataProvider; -use In2code\Lux\Domain\DataProvider\BrowserAmountDataProvider; use In2code\Lux\Domain\DataProvider\DomainDataProvider; use In2code\Lux\Domain\DataProvider\DomainNewsDataProvider; use In2code\Lux\Domain\DataProvider\DownloadsDataProvider; @@ -17,7 +17,6 @@ use In2code\Lux\Domain\DataProvider\NewsvisistsDataProvider; use In2code\Lux\Domain\DataProvider\PagevisistsDataProvider; use In2code\Lux\Domain\DataProvider\SearchDataProvider; -use In2code\Lux\Domain\DataProvider\SocialMediaDataProvider; use In2code\Lux\Domain\DataProvider\UtmCampaignDataProvider; use In2code\Lux\Domain\DataProvider\UtmDataProvider; use In2code\Lux\Domain\DataProvider\UtmMediaDataProvider; @@ -26,21 +25,18 @@ use In2code\Lux\Domain\Model\News; use In2code\Lux\Domain\Model\Page; use In2code\Lux\Domain\Model\Transfer\FilterDto; -use In2code\Lux\Exception\ConfigurationException; -use In2code\Lux\Exception\UnexpectedValueException; use In2code\Lux\Utility\FileUtility; use In2code\Lux\Utility\LocalizationUtility; use In2code\Lux\Utility\ObjectUtility; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException; use TYPO3\CMS\Extbase\Http\ForwardResponse; use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException; +use TYPO3\CMS\Extbase\Object\Exception as ExceptionExtbaseObject; use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException; use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; @@ -58,39 +54,18 @@ public function initializeDashboardAction(): void /** * @param FilterDto $filter * @return ResponseInterface - * @throws ConfigurationException * @throws ExceptionDbal * @throws InvalidConfigurationTypeException * @throws InvalidQueryException - * @throws UnexpectedValueException - * @throws ExtensionConfigurationExtensionNotConfiguredException - * @throws ExtensionConfigurationPathDoesNotExistException * @throws ExceptionDbalDriver */ public function dashboardAction(FilterDto $filter): ResponseInterface { - $this->cacheLayer->initialize(__CLASS__, __FUNCTION__); $this->view->assignMultiple([ - 'cacheLayer' => $this->cacheLayer, 'filter' => $filter, 'interestingLogs' => $this->logRepository->findInterestingLogs($filter), ]); - if ($this->cacheLayer->isCacheAvailable('Box/Analysis/Pagevisits/' . $filter->getHash()) === false) { - $this->view->assignMultiple([ - 'numberOfVisitorsData' => GeneralUtility::makeInstance(PagevisistsDataProvider::class, $filter), - 'numberOfDownloadsData' => GeneralUtility::makeInstance(DownloadsDataProvider::class, $filter), - 'pages' => $this->pagevisitsRepository->findCombinedByPageIdentifier($filter), - 'downloads' => $this->downloadRepository->findCombinedByHref($filter), - 'news' => $this->newsvisitRepository->findCombinedByNewsIdentifier($filter), - 'searchterms' => $this->searchRepository->findCombinedBySearchIdentifier($filter), - 'browserData' => GeneralUtility::makeInstance(BrowserAmountDataProvider::class, $filter), - 'domainData' => GeneralUtility::makeInstance(DomainDataProvider::class, $filter), - 'socialMediaData' => GeneralUtility::makeInstance(SocialMediaDataProvider::class, $filter), - 'latestPagevisits' => $this->pagevisitsRepository->findLatestPagevisits($filter), - ]); - } - $this->addDocumentHeaderForCurrentController(); return $this->defaultRendering(); } @@ -111,8 +86,10 @@ public function initializeContentAction(): void * @param string $export * @return ResponseInterface * @throws ExceptionDbal - * @throws InvalidQueryException * @throws ExceptionDbalDriver + * @throws InvalidQueryException + * @throws DBALException + * @throws ExceptionExtbaseObject */ public function contentAction(FilterDto $filter, string $export = ''): ResponseInterface { @@ -142,6 +119,7 @@ public function contentAction(FilterDto $filter, string $export = ''): ResponseI * @throws ExceptionDbal * @throws InvalidQueryException * @throws ExceptionDbalDriver + * @throws ExceptionExtbaseObject */ public function contentCsvAction(FilterDto $filter): ResponseInterface { @@ -193,6 +171,7 @@ public function newsAction(FilterDto $filter, string $export = ''): ResponseInte * @return ResponseInterface * @throws ExceptionDbal * @throws ExceptionDbalDriver + * @throws DBALException */ public function newsCsvAction(FilterDto $filter): ResponseInterface { @@ -218,6 +197,7 @@ public function initializeUtmAction(): void * @throws ExceptionDbalDriver * @throws InvalidQueryException * @throws ExceptionDbal + * @throws DBALException */ public function utmAction(FilterDto $filter, string $export = ''): ResponseInterface { @@ -347,6 +327,7 @@ public function deleteLinkListenerAction(LinkListener $linkListener): ResponseIn * @return ResponseInterface * @throws ExceptionDbal * @throws ExceptionDbalDriver + * @throws DBALException */ public function detailPageAction(Page $page): ResponseInterface { @@ -365,6 +346,7 @@ public function detailPageAction(Page $page): ResponseInterface * @return ResponseInterface * @throws ExceptionDbalDriver * @throws ExceptionDbal + * @throws DBALException */ public function detailNewsAction(News $news): ResponseInterface { @@ -442,6 +424,7 @@ public function detailSearchAction(string $searchterm): ResponseInterface * @return ResponseInterface * @noinspection PhpUnused * @throws ExceptionDbalDriver + * @throws DBALException */ public function detailAjaxPage(ServerRequestInterface $request): ResponseInterface { @@ -471,6 +454,7 @@ public function detailAjaxPage(ServerRequestInterface $request): ResponseInterfa * @return ResponseInterface * @noinspection PhpUnused * @throws ExceptionDbalDriver + * @throws DBALException */ public function detailNewsAjaxPage(ServerRequestInterface $request): ResponseInterface { @@ -499,6 +483,7 @@ public function detailNewsAjaxPage(ServerRequestInterface $request): ResponseInt * * @param ServerRequestInterface $request * @return ResponseInterface + * @throws Exception */ public function detailUtmAjaxPage(ServerRequestInterface $request): ResponseInterface { diff --git a/Classes/Controller/GeneralController.php b/Classes/Controller/GeneralController.php index 67d5a011..87d51511 100644 --- a/Classes/Controller/GeneralController.php +++ b/Classes/Controller/GeneralController.php @@ -3,16 +3,22 @@ declare(strict_types=1); namespace In2code\Lux\Controller; +use Doctrine\DBAL\DBALException; +use In2code\Lux\Backend\Units\UnitFinder; use In2code\Lux\Domain\Model\Company; use In2code\Lux\Domain\Model\Linklistener; use In2code\Lux\Domain\Model\Log; use In2code\Lux\Domain\Model\Transfer\FilterDto; use In2code\Lux\Domain\Model\Visitor; +use In2code\Lux\Exception\ConfigurationException; use In2code\Lux\Utility\BackendUtility; use In2code\Lux\Utility\ExtensionUtility; use In2code\Lux\Utility\ObjectUtility; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; +use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; +use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -81,6 +87,8 @@ public function showOrHidePageOverviewAjax(ServerRequestInterface $request): Res /** * @param ServerRequestInterface $request * @return ResponseInterface + * @throws ExtensionConfigurationExtensionNotConfiguredException + * @throws ExtensionConfigurationPathDoesNotExistException */ public function getVisitorImageUrlAjax(ServerRequestInterface $request): ResponseInterface { @@ -113,6 +121,7 @@ public function getCompanyImageUrlAjax(ServerRequestInterface $request): Respons /** * @param ServerRequestInterface $request * @return ResponseInterface + * @throws DBALException */ public function getLinkListenerPerformanceAjax(ServerRequestInterface $request): ResponseInterface { @@ -125,4 +134,17 @@ public function getLinkListenerPerformanceAjax(ServerRequestInterface $request): } return GeneralUtility::makeInstance(JsonResponse::class, ['performance' => $performance]); } + + /** + * @param ServerRequestInterface $request + * @return ResponseInterface + * @throws ConfigurationException + */ + public function getUnitAjax(ServerRequestInterface $request): ResponseInterface + { + $path = $request->getQueryParams()['path'] ?? ''; + $arguments = $request->getQueryParams()['arguments'] ?? []; + $unitFinder = GeneralUtility::makeInstance(UnitFinder::class, $arguments); + return GeneralUtility::makeInstance(HtmlResponse::class, $unitFinder->find($path)->get()); + } } diff --git a/Classes/Controller/LeadController.php b/Classes/Controller/LeadController.php index bf9e8bc7..8fb467ef 100644 --- a/Classes/Controller/LeadController.php +++ b/Classes/Controller/LeadController.php @@ -4,16 +4,15 @@ namespace In2code\Lux\Controller; use DateTime; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver; use Doctrine\DBAL\Exception as ExceptionDbal; use Exception; use In2code\Lux\Domain\DataProvider\CompanyAmountPerMonthDataProvider; use In2code\Lux\Domain\DataProvider\CompanyCategoryScoringsDataProvider; use In2code\Lux\Domain\DataProvider\CompanyScoringWeeksDataProvider; -use In2code\Lux\Domain\DataProvider\IdentificationMethodsDataProvider; use In2code\Lux\Domain\DataProvider\LeadsPerTimeDataProvider; use In2code\Lux\Domain\DataProvider\PagevisistsDataProvider; -use In2code\Lux\Domain\DataProvider\ReferrerAmountDataProvider; use In2code\Lux\Domain\DataProvider\RevenueClassDataProvider; use In2code\Lux\Domain\DataProvider\VisitorCategoryScoringsDataProvider; use In2code\Lux\Domain\DataProvider\VisitorScoringWeeksDataProvider; @@ -24,15 +23,11 @@ use In2code\Lux\Domain\Repository\CompanyRepository; use In2code\Lux\Domain\Repository\VisitorRepository; use In2code\Lux\Domain\Service\CompanyConfigurationService; -use In2code\Lux\Exception\ConfigurationException; -use In2code\Lux\Exception\UnexpectedValueException; use In2code\Lux\Utility\LocalizationUtility; use In2code\Lux\Utility\ObjectUtility; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Throwable; -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Messaging\AbstractMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -58,42 +53,17 @@ public function initializeDashboardAction(): void /** * @param FilterDto $filter * @return ResponseInterface - * @throws ConfigurationException - * @throws ExceptionDbal - * @throws ExceptionDbalDriver - * @throws ExtensionConfigurationExtensionNotConfiguredException - * @throws ExtensionConfigurationPathDoesNotExistException * @throws InvalidConfigurationTypeException * @throws InvalidQueryException - * @throws UnexpectedValueException */ public function dashboardAction(FilterDto $filter): ResponseInterface { - $this->cacheLayer->initialize(__CLASS__, __FUNCTION__); $this->view->assignMultiple([ - 'cacheLayer' => $this->cacheLayer, 'filter' => $filter, 'interestingLogs' => $this->logRepository->findInterestingLogs($filter, 10), 'whoisonline' => $this->visitorRepository->findOnline(8), ]); - if ($this->cacheLayer->isCacheAvailable('Box/Leads/Recurring/' . $filter->getHash()) === false) { - $this->view->assignMultiple([ - 'numberOfUniqueSiteVisitors' => $this->visitorRepository->findByUniqueSiteVisits($filter)->count(), - 'numberOfRecurringSiteVisitors' => - $this->visitorRepository->findByRecurringSiteVisits($filter)->count(), - 'identifiedPerMonth' => $this->logRepository->findIdentifiedLogsFromMonths(6), - 'numberOfIdentifiedVisitors' => $this->visitorRepository->findIdentified($filter)->count(), - 'numberOfUnknownVisitors' => $this->visitorRepository->findUnknown($filter)->count(), - 'identificationMethods' => - GeneralUtility::makeInstance(IdentificationMethodsDataProvider::class, $filter), - 'referrerAmountData' => GeneralUtility::makeInstance(ReferrerAmountDataProvider::class, $filter), - 'countries' => $this->ipinformationRepository->findAllCountryCodesGrouped($filter), - 'hottestVisitors' => $this->visitorRepository->findByHottestScorings($filter), - 'renderingTime' => $this->renderingTimeService->getTime(), - ]); - } - $this->addDocumentHeaderForCurrentController(); return $this->defaultRendering(); } @@ -167,6 +137,7 @@ public function downloadCsvAction(FilterDto $filter): ResponseInterface * * @param Visitor $visitor * @return ResponseInterface + * @throws DBALException */ public function removeAction(Visitor $visitor): ResponseInterface { @@ -180,6 +151,7 @@ public function removeAction(Visitor $visitor): ResponseInterface * @return ResponseInterface * @throws IllegalObjectTypeException * @throws UnknownObjectException + * @throws DBALException */ public function deactivateAction(Visitor $visitor): ResponseInterface { @@ -285,6 +257,7 @@ public function companyAction(Company $company): ResponseInterface * @param FilterDto $filter * @return ResponseInterface * @throws ExceptionDbal + * @throws ExceptionDbalDriver */ public function downloadCsvCompaniesAction(FilterDto $filter): ResponseInterface { diff --git a/Classes/Domain/Cache/BackendSessionFaker.php b/Classes/Domain/Cache/BackendSessionFaker.php deleted file mode 100644 index 08d2a561..00000000 --- a/Classes/Domain/Cache/BackendSessionFaker.php +++ /dev/null @@ -1,155 +0,0 @@ -dbSessionBackend = GeneralUtility::makeInstance(DatabaseSessionBackend::class); - } - - public function __destruct() - { - $this->removeBackendSession(); - } - - /** - * @return void - * @throws EnvironmentException - * @throws Exception - * @throws ExceptionDbal - * @throws MfaRequiredException - */ - public function fake(): void - { - $this->createBackendSession(); - $this->createBackendUserGlobalObject(); - } - - /** - * @return void - * @throws EnvironmentException - * @throws Exception - * @throws ExceptionDbal - */ - protected function createBackendSession(): void - { - $sessionData = ['formProtectionSessionToken' => $this->getFormProtectionSessionToken()]; - $properties = [ - 'ses_id' => $this->dbSessionBackend->hash($this->getSessionIdentifier()), - 'ses_iplock' => IpLocker::DISABLED_LOCK_VALUE, - 'ses_userid' => $this->getBackendUserAdminIdentifier(), - 'ses_tstamp' => time(), - 'ses_data' => serialize($sessionData), - ]; - - $queryBuilder = DatabaseUtility::getQueryBuilderForTable(self::TABLE_BACKENDUSERSESSION); - $queryBuilder->insert(self::TABLE_BACKENDUSERSESSION)->values($properties)->executeStatement(); - } - - protected function removeBackendSession(): void - { - $queryBuilder = DatabaseUtility::getQueryBuilderForTable(self::TABLE_BACKENDUSERSESSION); - $queryBuilder - ->delete(self::TABLE_BACKENDUSERSESSION) - ->where( - $queryBuilder->expr()->eq( - 'ses_id', - $queryBuilder->createNamedParameter($this->dbSessionBackend->hash($this->getSessionIdentifier())) - ) - ) - ->executeStatement(); - } - - /** - * We do need to create a backend user authentication object to create a valid link to a backend module - * from CLI context - * - * @return void - * @throws EnvironmentException - * @throws Exception - * @throws ExceptionDbal - * @throws MfaRequiredException - * @SuppressWarnings(PHPMD.Superglobals) - */ - protected function createBackendUserGlobalObject(): void - { - $request = GeneralUtility::makeInstance(ServerRequest::class); - $newRequest = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); - - $GLOBALS['TYPO3_CONF_VARS']['SYS']['cookieSecure'] = 0; - $GLOBALS['BE_USER'] = GeneralUtility::makeInstance(BackendUserAuthentication::class); - $GLOBALS['BE_USER']->start($newRequest); - $GLOBALS['BE_USER']->setBeUserByUid($this->getBackendUserAdminIdentifier()); - $GLOBALS['BE_USER']->backendCheckLogin(); - $GLOBALS['BE_USER']->setSessionData('formProtectionSessionToken', $this->getFormProtectionSessionToken()); - } - - /** - * @return int - * @throws EnvironmentException - * @throws Exception - * @throws ExceptionDbal - */ - protected function getBackendUserAdminIdentifier(): int - { - static $identifier = 0; - if ($identifier === 0) { - $queryBuilder = DatabaseUtility::getQueryBuilderForTable(self::TABLE_BACKENDUSERS); - $identifier = (int)$queryBuilder - ->select('uid') - ->from(self::TABLE_BACKENDUSERS) - ->where('admin=1') - ->executeQuery() - ->fetchOne(); - if ($identifier === 0) { - throw new EnvironmentException('No administration backend user found', 1645125690); - } - } - return $identifier; - } - - /** - * Used for be_typo_user cookie value - * - * @return string - */ - public function getSessionIdentifier(): string - { - static $sessionIdentifier = ''; - if ($sessionIdentifier === '') { - $sessionIdentifier = StringUtility::getRandomString(32, false); - } - return $sessionIdentifier; - } - - protected function getFormProtectionSessionToken(): string - { - static $sessionToken = ''; - if ($sessionToken === '') { - $sessionToken = StringUtility::getRandomString(64, false); - } - return $sessionToken; - } -} diff --git a/Classes/Domain/Cache/CacheWarmup.php b/Classes/Domain/Cache/CacheWarmup.php index 640f48db..04d22d12 100644 --- a/Classes/Domain/Cache/CacheWarmup.php +++ b/Classes/Domain/Cache/CacheWarmup.php @@ -4,117 +4,68 @@ namespace In2code\Lux\Domain\Cache; -use Doctrine\DBAL\Driver\Exception; -use Doctrine\DBAL\Exception as ExceptionDbal; -use GuzzleHttp\Cookie\CookieJar; -use In2code\Lux\Domain\Service\SiteService; +use In2code\Lux\Backend\Units\UnitFinder; use In2code\Lux\Exception\ConfigurationException; -use In2code\Lux\Exception\EnvironmentException; -use In2code\Lux\Exception\UnexpectedValueException; -use In2code\Lux\Utility\UrlUtility; use Symfony\Component\Console\Output\OutputInterface; -use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; -use TYPO3\CMS\Backend\Routing\UriBuilder; -use TYPO3\CMS\Core\Authentication\Mfa\MfaRequiredException; -use TYPO3\CMS\Core\Http\RequestFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; final class CacheWarmup { - protected BackendSessionFaker $backendSessionFaker; + protected UnitFinder $unitFinder; - protected string $domain = ''; - - /** - * Constructor - * - * @throws EnvironmentException - * @throws MfaRequiredException - * @throws Exception - * @throws ExceptionDbal - */ - public function __construct() - { - $this->backendSessionFaker = GeneralUtility::makeInstance(BackendSessionFaker::class); - $this->backendSessionFaker->fake(); - } + protected array $routesAndPaths = [ + 'lux_LuxAnalysis' => [ + 'AnalysisDashboardPagevisits', + 'AnalysisDashboardDownloads', +// 'AnalysisDashboardPagevisitsleads', // would need BackendAuthentication + 'AnalysisDashboardBrowser', + 'AnalysisDashboardTopPages', + 'AnalysisDashboardTopDownloads', + 'AnalysisDashboardTopNews', + 'AnalysisDashboardTopSearch', + 'AnalysisDashboardSocialmedia', + ], + 'lux_LuxLead' => [ + 'LeadDashboardRecurring', + 'LeadDashboardHottest', + 'LeadDashboardIdentified', + 'LeadDashboardIdentifiedpermonth', + 'LeadDashboardIdentifiedpermethod', + 'LeadDashboardReferrer', + 'LeadDashboardMap', + 'LeadDashboardCountrylist', + ], + 'web_layout' => [ + 'PageoverviewAnalysisBody', +// 'PageoverviewAnalysisTitle', // can not be cached CLI + 'PageoverviewLeadsBody', +// 'PageoverviewLeadsTitle', // can not be cached from CLI + ], + ]; /** * @param string $route - * @param string $domain * @param array $arguments * @param OutputInterface $output * @return void - * @throws RouteNotFoundException - * @throws UnexpectedValueException * @throws ConfigurationException */ - public function warmup(string $route, string $domain, array $arguments, OutputInterface $output): void + public function warmup(string $route, array $arguments, OutputInterface $output): void { - $this->domain = $domain; + $this->unitFinder = GeneralUtility::makeInstance(UnitFinder::class, $arguments); $message = 'Cache warmup for route ' . $route; if ($arguments !== []) { $message .= ' (' . http_build_query($arguments) . ')'; } $output->writeln('Start: ' . $message . ' ...'); - $this->sendRequestToBackendModule($route, $arguments); - $output->writeln('Done: ' . $message . ' successfully build up!'); - } - - /** - * Example request - * curl -Ik --cookie "be_typo_user=sessid" https://domain.org/typo3/index.php\?route\=%2Fmodule%2Flux%2FLuxLeads\&token\=tokenid - * - * @param string $route - * @param array $arguments - * @return void - * @throws RouteNotFoundException - * @throws UnexpectedValueException - * @throws ConfigurationException - */ - protected function sendRequestToBackendModule(string $route, array $arguments): void - { - $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); - $path = $uriBuilder->buildUriFromRoute($route); - $url = $this->getDomain() . $path->__toString() . '&' . http_build_query($arguments); - - $jar = CookieJar::fromArray( - ['be_typo_user' => $this->backendSessionFaker->getSessionIdentifier()], - $this->getDomain(false) - ); - $requestFactory = GeneralUtility::makeInstance(RequestFactory::class); - $response = $requestFactory->request($url, 'GET', ['cookies' => $jar]); - if ($response->getStatusCode() === 200) { - if (stristr($response->getBody()->getContents(), 'lux') === false) { - // If e.g. backend login form is shown, throw an exception - throw new UnexpectedValueException('Could not warmup cache', 1645131190); - } - } - } - - /** - * @param bool $withProtocol - * @return string - * @throws ConfigurationException - */ - protected function getDomain(bool $withProtocol = true): string - { - $domain = $this->domain; - if ($domain === '') { - $siteService = GeneralUtility::makeInstance(SiteService::class); - $domain = $siteService->getFirstDomain(); - } - $domain = UrlUtility::removeSlashPrefixAndPostfix($domain); - if (UrlUtility::isAbsoluteUri($domain) === false) { - throw new ConfigurationException( - 'Could not get valid domain from site configuration for CURL request. Please pass a domain when calling - this command.', - 1645271865 - ); + if (array_key_exists($route, $this->routesAndPaths) === false) { + throw new ConfigurationException('Route ' . $route . ' not defined', 1695125113); } - if ($withProtocol === false) { - $domain = UrlUtility::removeProtocolFromDomain($domain); + foreach ($this->routesAndPaths[$route] as $path) { + $output->writeln('Path: ' . $path); + // Call to get the HTML for caching only + $this->unitFinder->find($path)->get(); } - return $domain; + $output->writeln('Done: ' . $message . ' successfully build up!'); } } diff --git a/Classes/Hooks/PageOverview.php b/Classes/Hooks/PageOverview.php index 55813368..834bb1a0 100644 --- a/Classes/Hooks/PageOverview.php +++ b/Classes/Hooks/PageOverview.php @@ -2,14 +2,9 @@ namespace In2code\Lux\Hooks; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver; use Doctrine\DBAL\Exception as ExceptionDbal; -use In2code\Lux\Domain\Cache\CacheLayer; -use In2code\Lux\Domain\DataProvider\PageOverview\GotinExternalDataProvider; -use In2code\Lux\Domain\DataProvider\PageOverview\GotinInternalDataProvider; -use In2code\Lux\Domain\DataProvider\PageOverview\GotoutInternalDataProvider; -use In2code\Lux\Domain\DataProvider\PagevisistsDataProvider; -use In2code\Lux\Domain\Model\Transfer\FilterDto; use In2code\Lux\Domain\Repository\DownloadRepository; use In2code\Lux\Domain\Repository\LinkclickRepository; use In2code\Lux\Domain\Repository\LogRepository; @@ -20,7 +15,6 @@ use In2code\Lux\Exception\UnexpectedValueException; use In2code\Lux\Utility\BackendUtility; use In2code\Lux\Utility\ConfigurationUtility; -use In2code\Lux\Utility\ObjectUtility; use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent; use TYPO3\CMS\Backend\Controller\PageLayoutController; use TYPO3\CMS\Backend\Utility\BackendUtility as BackendUtilityCore; @@ -43,7 +37,6 @@ class PageOverview protected DownloadRepository $downloadRepository; protected LogRepository $logRepository; protected RenderingTimeService $renderingTimeService; - protected CacheLayer $cacheLayer; public function __construct( VisitorRepository $visitorRepository, @@ -51,8 +44,7 @@ public function __construct( LinkclickRepository $linkclickRepository, DownloadRepository $downloadRepository, LogRepository $logRepository, - RenderingTimeService $renderingTimeService, - CacheLayer $cacheLayer + RenderingTimeService $renderingTimeService ) { $this->visitorRepository = $visitorRepository; $this->pagevisitRepository = $pagevisitRepository; @@ -60,7 +52,6 @@ public function __construct( $this->downloadRepository = $downloadRepository; $this->logRepository = $logRepository; $this->renderingTimeService = $renderingTimeService; // initialize renderingTimes - $this->cacheLayer = $cacheLayer; } /** @@ -74,6 +65,7 @@ public function __construct( * @throws ExtensionConfigurationExtensionNotConfiguredException * @throws ExtensionConfigurationPathDoesNotExistException * @throws UnexpectedValueException + * @throws DBALException */ public function eventRegistration(ModifyPageLayoutContentEvent $event): void { @@ -95,6 +87,7 @@ public function eventRegistration(ModifyPageLayoutContentEvent $event): void * @throws ExtensionConfigurationPathDoesNotExistException * @throws UnexpectedValueException * @throws ExceptionDbalDriver + * @throws DBALException */ public function render(array $parameters, PageLayoutController $plController): string { @@ -111,10 +104,10 @@ public function render(array $parameters, PageLayoutController $plController): s * @throws ExtensionConfigurationExtensionNotConfiguredException * @throws ExtensionConfigurationPathDoesNotExistException * @throws UnexpectedValueException + * @throws DBALException */ protected function renderContent(int $pageIdentifier): string { - $this->cacheLayer->initialize(__CLASS__, 'render'); $content = ''; if ($this->isPageOverviewEnabled($pageIdentifier)) { $session = BackendUtility::getSessionValue('toggle', 'pageOverview', 'General'); @@ -129,68 +122,15 @@ protected function renderContent(int $pageIdentifier): string * @param int $pageIdentifier * @param array $session * @return array - * @throws ExceptionDbal - * @throws ExtensionConfigurationExtensionNotConfiguredException - * @throws ExtensionConfigurationPathDoesNotExistException - * @throws ConfigurationException - * @throws UnexpectedValueException - * @throws ExceptionDbalDriver */ protected function getArguments(string $view, int $pageIdentifier, array $session): array { - $arguments = [ + return [ 'pageIdentifier' => $pageIdentifier, - 'cacheLayer' => $this->cacheLayer, 'status' => $session['status'] ?? 'show', 'view' => ucfirst($view), 'visitors' => $this->visitorRepository->findByVisitedPageIdentifier($pageIdentifier), ]; - - if ($this->cacheLayer->isCacheAvailable('PageOverviewTitle' . $pageIdentifier) === false) { - $filter = ObjectUtility::getFilterDto(FilterDto::PERIOD_LAST7DAYS)->setSearchterm($pageIdentifier); - $delta = $this->pagevisitRepository->compareAmountPerPage( - $pageIdentifier, - $filter, - ObjectUtility::getFilterDto(FilterDto::PERIOD_7DAYSBEFORELAST7DAYS) - ); - $arguments += [ - 'abandons' => $this->pagevisitRepository->findAbandonsForPage($pageIdentifier, $filter), - 'delta' => $delta, - 'deltaIconPath' => $delta >= 0 ? 'Icons/increase.svg' : 'Icons/decrease.svg', - 'visits' => $this->pagevisitRepository->findAmountPerPage($pageIdentifier, $filter), - 'visitsLastWeek' => $this->pagevisitRepository->findAmountPerPage( - $pageIdentifier, - ObjectUtility::getFilterDto(FilterDto::PERIOD_7DAYSBEFORELAST7DAYS) - ), - 'gotinInternal' => GeneralUtility::makeInstance( - GotinInternalDataProvider::class, - $filter - )->get(), - 'gotinExternal' => GeneralUtility::makeInstance( - GotinExternalDataProvider::class, - $filter - )->get(), - 'gotoutInternal' => GeneralUtility::makeInstance(GotoutInternalDataProvider::class, $filter)->get(), - 'gotout' => '', - 'numberOfVisitorsData' => GeneralUtility::makeInstance( - PagevisistsDataProvider::class, - ObjectUtility::getFilterDto()->setSearchterm((string)$pageIdentifier) - ), - 'downloadAmount' => $this->downloadRepository->findAmountByPageIdentifierAndTimeFrame( - $pageIdentifier, - $filter - ), - 'conversionAmount' => $this->logRepository->findAmountOfIdentifiedLogsByPageIdentifierAndTimeFrame( - $pageIdentifier, - $filter - ), - 'linkclickAmount' => $this->linkclickRepository->getAmountOfLinkclicksByPageIdentifierAndTimeframe( - $pageIdentifier, - $filter - ), - ]; - } - return $arguments; } protected function getContent(array $arguments): string diff --git a/Classes/Utility/CacheLayerUtility.php b/Classes/Utility/CacheLayerUtility.php index 64bc1b32..fd7d91f7 100644 --- a/Classes/Utility/CacheLayerUtility.php +++ b/Classes/Utility/CacheLayerUtility.php @@ -33,7 +33,7 @@ public static function registerCacheLayers(): void 'lifetime' => 86400, 'route' => 'web_layout', 'arguments' => [ - 'id' => '{uid}', // {uid} can only be replaced with pages.uid when multiple is set to true + 'pageidentifier' => '{uid}', // {uid} can only be replaced with pages.uid when multiple is set to true ], 'multiple' => true, // iterate per page identifier ]; diff --git a/Classes/Utility/StringUtility.php b/Classes/Utility/StringUtility.php index 8322ab47..deffe696 100644 --- a/Classes/Utility/StringUtility.php +++ b/Classes/Utility/StringUtility.php @@ -122,4 +122,17 @@ public static function isShortMd5(string $string, int $length = 6): bool { return preg_replace('~[a-f0-9]{' . $length . '}~', '', $string) === ''; } + + /** + * Example result: + * "CamelCaseString" => ["Camel", "Case", "String"] + * + * @param string $string + * @return array + */ + public static function splitCamelcaseString(string $string): array + { + preg_match_all('~((?:^|[A-Z])[a-z]+)~', $string, $matches); + return $matches[0]; + } } diff --git a/Classes/ViewHelpers/Backend/CacheViewHelper.php b/Classes/ViewHelpers/Backend/CacheViewHelper.php index 2d21fccb..c04c21e1 100644 --- a/Classes/ViewHelpers/Backend/CacheViewHelper.php +++ b/Classes/ViewHelpers/Backend/CacheViewHelper.php @@ -5,10 +5,14 @@ namespace In2code\Lux\ViewHelpers\Backend; use In2code\Lux\Domain\Cache\CacheLayer; +use In2code\Lux\Domain\Service\RenderingTimeService; use In2code\Lux\Exception\ConfigurationException; use In2code\Lux\Exception\UnexpectedValueException; +use In2code\Lux\Utility\BackendUtility; +use In2code\Lux\Utility\ConfigurationUtility; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; class CacheViewHelper extends AbstractViewHelper @@ -37,10 +41,22 @@ public function render(): string if ($cacheLayer->isCacheAvailable($identifier)) { $content = $cacheLayer->getHtml($identifier); + $content .= $this->getCacheContentPostfix(); } else { $content = $this->renderChildren(); $cacheLayer->setHtml($content, $identifier); } return $content; } + + protected function getCacheContentPostfix(): string + { + $content = PHP_EOL . ''; + return $content; + } } diff --git a/Configuration/Backend/AjaxRoutes.php b/Configuration/Backend/AjaxRoutes.php index d6a05274..908af28f 100644 --- a/Configuration/Backend/AjaxRoutes.php +++ b/Configuration/Backend/AjaxRoutes.php @@ -61,6 +61,10 @@ 'path' => '/lux/pageoverview', 'target' => GeneralController::class . '::showOrHidePageOverviewAjax', ], + '/lux/unitajax' => [ + 'path' => '/lux/unitajax', + 'target' => GeneralController::class . '::getUnitAjax', + ], '/lux/visitorcompany' => [ 'path' => '/lux/visitorcompany', 'target' => LeadController::class . '::detailCompanyrecordAjax', diff --git a/Documentation/Technical/Commands/Index.md b/Documentation/Technical/Commands/Index.md index 64d953f8..8fa688b0 100644 --- a/Documentation/Technical/Commands/Index.md +++ b/Documentation/Technical/Commands/Index.md @@ -210,9 +210,6 @@ Example usage: # Warmup specific views ./vendor/bin/typo3 lux:cachewarmup lux_LuxAnalysis,lux_LuxLead - -# Warmup all views and pass a domain (if you don't store a domain in siteconfiguration or if you want to use a specific domain for backend requests) -./vendor/bin/typo3 lux:cachewarmup lux_LuxAnalysis,lux_LuxLead,web_layout https://domainforbackend.de ``` **Note:** Every call of this command will clean all LUX cachelayer caches at the beginning of the task. diff --git a/Resources/Private/Build/JavaScript/Backend/Diagram.js b/Resources/Private/Build/JavaScript/Backend/Diagram.js index b4ab8c25..a155b059 100644 --- a/Resources/Private/Build/JavaScript/Backend/Diagram.js +++ b/Resources/Private/Build/JavaScript/Backend/Diagram.js @@ -12,15 +12,16 @@ define(['jquery', 'TYPO3/CMS/Lux/Vendor/Chart.min'], function($) { * * @returns {void} */ - this.initialize = function() { - diagramListener(); + this.initialize = function(dom) { + dom = dom || document; + diagramListener(dom); }; /** * @returns {void} */ - var diagramListener = function() { - var diagrams = document.querySelectorAll('[data-chart]'); + var diagramListener = function(dom) { + var diagrams = dom.querySelectorAll('[data-chart]'); for (var i = 0; i < diagrams.length; i++) { var type = diagrams[i].getAttribute('data-chart'); if (type === 'doughnut') { diff --git a/Resources/Private/Build/JavaScript/Backend/Module.js b/Resources/Private/Build/JavaScript/Backend/Module.js index 0252f635..133bd3e8 100644 --- a/Resources/Private/Build/JavaScript/Backend/Module.js +++ b/Resources/Private/Build/JavaScript/Backend/Module.js @@ -40,6 +40,7 @@ define(['jquery'], function($) { asynchronousLinkListenerPerformanceLoading(); asynchronousCompaniesInformationLoading(); addToggleListener(); + addUnitAjaxListener(); }; /** @@ -288,6 +289,35 @@ define(['jquery'], function($) { }); }; + const addUnitAjaxListener = function() { + const elements = document.querySelectorAll('[data-lux-unitajax]'); + elements.forEach(function(element) { + const data = new URLSearchParams(); + data.append('path', element.getAttribute('data-lux-unitajax')); + + // add any parameters to request from data-lux-unitajax-parameter-key="value" + for (var key in element.dataset) { + if (key.indexOf('luxUnitajaxParameter') === 0) { + data.append('arguments[' + key.substring('luxUnitajaxParameter'.length).toLowerCase() + ']', element.dataset[key]); + } + } + + fetch(TYPO3.settings.ajaxUrls['/lux/unitajax'] + '&' + data) + .then((resp) => resp.text()) + .then(function(html) { + const parent = element.parentNode; + parent.innerHTML = html; + window.LuxDiagramObject.initialize(parent); + if (parent.querySelector('[data-lux-toggle]') !== null) { + LuxPageOverviewObject.initialize(parent); + } + }) + .catch(function(error) { + console.log(error); + }); + }); + } + /** * @param {string} elements * @param {string} className diff --git a/Resources/Private/Build/JavaScript/Backend/PageOverview.js b/Resources/Private/Build/JavaScript/Backend/PageOverview.js index f32bec52..aaddb0c0 100644 --- a/Resources/Private/Build/JavaScript/Backend/PageOverview.js +++ b/Resources/Private/Build/JavaScript/Backend/PageOverview.js @@ -12,19 +12,19 @@ function LuxPageOverview() { var that = this; /** - * Initialize - * + * @param {Document} optional * @returns {void} */ - this.initialize = function() { - toggleListener(); + this.initialize = function(dom) { + dom = dom || document; + toggleListener(dom); }; /** * @returns {void} */ - var toggleListener = function() { - var elements = document.querySelectorAll('[data-lux-toggle]'); + var toggleListener = function(dom) { + var elements = dom.querySelectorAll('[data-lux-toggle]'); for (var i = 0; i < elements.length; i++) { elements[i].addEventListener('click', function(event) { var thisElement = event.currentTarget; diff --git a/Resources/Private/Partials/Box/Leads/IdentifiedPerMonth.html b/Resources/Private/Partials/Box/Leads/IdentifiedPerMonth.html index 3c34231b..4085a79a 100644 --- a/Resources/Private/Partials/Box/Leads/IdentifiedPerMonth.html +++ b/Resources/Private/Partials/Box/Leads/IdentifiedPerMonth.html @@ -5,7 +5,7 @@