Skip to content

Commit

Permalink
feat: save mapping to matched request instead of page
Browse files Browse the repository at this point in the history
  • Loading branch information
maikschneider committed Feb 14, 2024
1 parent 62f440b commit b373fcf
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 52 deletions.
43 changes: 27 additions & 16 deletions Classes/Command/UpdatePageStatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,41 @@ protected function configure(): void

public function execute(InputInterface $input, OutputInterface $output): int
{
$dailyLogs = $this->dataProviderService->getDailyJsonLogs();
$mappings = $this->mappingRepository->getAllPageMappings();
$dailyLogs = $this->dataProviderService->getUnparsedDailyJsonLogs();
$mappings = $this->mappingRepository->getAllPageAndActionMappings();

foreach ($dailyLogs as $log) {

$data = ['tx_xmgoaccess_domain_model_request' => []];
$timestamp = $this->dataProviderService::getTimestampFromLogDate($log['general']->start_date);

foreach ($log['requests']->data as $key => $pathData) {
foreach ($mappings as $key2 => $mapping) {
if ($mapping['path'] === $pathData->data) {
$data['tx_xmgoaccess_domain_model_request']['NEW' . $key .'-' . $key2] = [
'pid' => 0,
'date' => $timestamp,
'page' => $mapping['page'],
'hits' => $pathData->hits->count,
'visitors' => $pathData->visitors->count,
];
foreach ($mappings as $key => $mapping) {

$data['tx_xmgoaccess_domain_model_request']['NEW-' . $key] = [
'pid' => 0,
'date' => $timestamp,
'mapping' => $mapping['uid'],
'hits' => 0,
'visitors' => 0,
];

foreach ($log['requests']->data as $key2 => $pathData) {
// check regex
if ($mapping['regex'] === 1) {
preg_match('/' . $mapping['path'] . '/', $pathData->data, $matches);
if (!count($matches)) {
continue;
}
}
}
}

if (!count($data['tx_xmgoaccess_domain_model_request'])) {
continue;
// check path 1:1
if ($mapping['regex'] === 0 && $mapping['path'] !== $pathData->data) {
continue;
}

$data['tx_xmgoaccess_domain_model_request']['NEW-' . $key]['hits'] += $pathData->hits->count;
$data['tx_xmgoaccess_domain_model_request']['NEW-' . $key]['visitors'] += $pathData->visitors->count;
}
}

// persist data
Expand Down
14 changes: 9 additions & 5 deletions Classes/Domain/Repository/MappingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ public function getAllNonRegexPaths(): array
return array_column($mappings, 'path');
}

public function getAllPageMappings(): array
public function getAllPageAndActionMappings(): array
{
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_xmgoaccess_domain_model_mapping');
$result = $qb->select('page', 'path')
$result = $qb->select('*')
->from('tx_xmgoaccess_domain_model_mapping')
->where($qb->expr()->eq('record_type', $qb->createNamedParameter(0, \PDO::PARAM_INT)))
->where(
$qb->expr()->or(
$qb->expr()->eq('record_type', $qb->createNamedParameter(0, \PDO::PARAM_INT)),
$qb->expr()->eq('record_type', $qb->createNamedParameter(1, \PDO::PARAM_INT))
)
)
->execute();

return $result->fetchAllAssociative();
}

}
}
15 changes: 11 additions & 4 deletions Classes/Domain/Repository/RequestRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ public function getAllDates(): array
public function getChartDataForPage(int $pageUid): array
{
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_xmgoaccess_domain_model_request');
$query = $qb->select('date', 'hits', 'visitors')
->from('tx_xmgoaccess_domain_model_request')
->where($qb->expr()->eq('page', $qb->createNamedParameter($pageUid, \PDO::PARAM_INT)))
->groupBy('page', 'date')
$query = $qb->select('r.date', 'r.hits', 'r.visitors')
->from('tx_xmgoaccess_domain_model_request', 'r')
->innerJoin('r', 'tx_xmgoaccess_domain_model_mapping', 'm',
$qb->expr()->eq('m.uid', $qb->quoteIdentifier('r.mapping')))
->where(
$qb->expr()->and(
$qb->expr()->eq('m.page', $qb->createNamedParameter($pageUid, \PDO::PARAM_INT)),
$qb->expr()->eq('m.record_type', $qb->createNamedParameter(0, \PDO::PARAM_INT))
)
)
->groupBy('m.page', 'r.date')
->execute();

return $query->fetchAllAssociative();
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/DataProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
) {
}

public function getDailyJsonLogs(): array
public function getUnparsedDailyJsonLogs(): array
{
$logPath = $this->extensionConfiguration->get('xm_goaccess', 'daily_log_path');

Expand Down
23 changes: 4 additions & 19 deletions Configuration/TCA/tx_xmgoaccess_domain_model_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
'types' => [
0 => [
'showitem' => 'date,page,hits,visitors',
'showitem' => 'date,page,hits,visitors,mapping',
],
],
'columns' => [
Expand Down Expand Up @@ -45,26 +45,11 @@
'max' => 255,
],
],
'page' => [
'mapping' => [
'exclude' => false,
'label' => 'LLL:EXT:xm_goaccess/Resources/Private/Language/locallang.xlf:request.page',
'label' => 'Mapping',
'config' => [
'type' => 'group',
'allowed' => 'pages',
'size' => 1,
'minitems' => 1,
'maxitems' => 1,
'fieldControl' => [
'addRecord' => [
'disabled' => true,
],
],
'fieldWizard' => [
'recordsOverview' => [
'disabled' => true,
],
],
'default' => 0,
'type' => 'input',
],
],
],
Expand Down
14 changes: 7 additions & 7 deletions ext_tables.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
create table tx_xmgoaccess_domain_model_mapping (
path varchar(255) not null default '',
path varchar(255) not null default '',
record_type int(11) unsigned default '0' not null,
page int(11) unsigned default '0' not null,
regex tinyint(4) unsigned default '0' not null,
title varchar(255) not null default '',
page int(11) unsigned default '0' not null,
regex tinyint(4) unsigned default '0' not null,
title varchar(255) not null default '',
);

create table tx_xmgoaccess_domain_model_request (
date int(11) unsigned default 0 not null,
page int(11) unsigned default 0 not null,
hits int(11) unsigned default 0 not null,
date int(11) unsigned default 0 not null,
mapping int(11) unsigned default 0 not null,
hits int(11) unsigned default 0 not null,
visitors int(11) unsigned default 0 not null,
);

0 comments on commit b373fcf

Please sign in to comment.