Skip to content

Commit

Permalink
[FEATURE] Save site in all log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 22, 2024
1 parent a538923 commit 7f0c8fb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Classes/Domain/Model/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Log extends AbstractModel
protected ?Visitor $visitor = null;
protected ?DateTime $crdate = null;
protected string $properties = '';
protected string $site = '';

public function getVisitor(): ?Visitor
{
Expand Down Expand Up @@ -179,6 +180,17 @@ protected function getPropertyByKey(string $key): string
return $property;
}

public function getSite(): string
{
return $this->site;
}

public function setSite(string $site): self
{
$this->site = $site;
return $this;
}

public static function getIdentifiedStatus(): array
{
return [
Expand Down
8 changes: 7 additions & 1 deletion Classes/Domain/Service/LogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use In2code\Lux\Domain\Model\Visitor;
use In2code\Lux\Domain\Repository\LogRepository;
use In2code\Lux\Domain\Repository\VisitorRepository;
use In2code\Lux\Utility\FrontendUtility;
use In2code\Luxenterprise\Domain\Model\AbTestingPage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
Expand Down Expand Up @@ -302,8 +303,13 @@ protected function log(int $status, Visitor $visitor, array $properties = []): v
{
$logRepository = GeneralUtility::makeInstance(LogRepository::class);
$visitorRepository = GeneralUtility::makeInstance(VisitorRepository::class);
$siteService = GeneralUtility::makeInstance(SiteService::class);
$siteIdentifier = $siteService->getSiteIdentifierFromPageIdentifier(FrontendUtility::getCurrentPageIdentifier());

$log = GeneralUtility::makeInstance(Log::class)->setStatus($status)->setPropertiesArray($properties);
$log = GeneralUtility::makeInstance(Log::class)
->setStatus($status)
->setPropertiesArray($properties)
->setSite($siteIdentifier);
$logRepository->add($log);
$visitor->addLog($log);
if ($visitor->getUid() > 0) {
Expand Down
12 changes: 8 additions & 4 deletions Classes/Utility/FrontendUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class FrontendUtility
{
public static function getCurrentPageIdentifier(): int
{
return self::getTyposcriptFrontendController()->id;
$typoscriptFrontendController = self::getTyposcriptFrontendController();
if (self::getTyposcriptFrontendController() === null) {
return 0;
}
return $typoscriptFrontendController->id;
}

/**
Expand Down Expand Up @@ -62,11 +66,11 @@ public static function isFrontendMode(): bool
}

/**
* @return TypoScriptFrontendController
* @return ?TypoScriptFrontendController
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected static function getTyposcriptFrontendController()
protected static function getTyposcriptFrontendController(): ?TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
return $GLOBALS['TSFE'] ?? null;
}
}
11 changes: 10 additions & 1 deletion Configuration/TCA/tx_lux_domain_model_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'hideTable' => true,
],
'types' => [
'1' => ['showitem' => 'crdate,status,properties,visitor'],
'1' => ['showitem' => 'crdate,status,properties,site,visitor'],
],
'columns' => [
'sys_language_uid' => [
Expand Down Expand Up @@ -87,6 +87,15 @@
'readOnly' => true,
],
],
'site' => [
'exclude' => true,
'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Log::TABLE_NAME . '.site',
'config' => [
'type' => 'input',
'size' => 30,
'readOnly' => true,
],
],
'visitor' => [
'exclude' => true,
'label' => 'LLL:EXT:lux/Resources/Private/Language/locallang_db.xlf:' . Log::TABLE_NAME . '.visitor',
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@
<source>Properties</source>
<target state="translated">Eigenschaften</target>
</trans-unit>
<trans-unit id="tx_lux_domain_model_log.site">
<source>Site</source>
<target state="translated">Site</target>
</trans-unit>
<trans-unit id="tx_lux_domain_model_log.visitor">
<source>Lead</source>
<target state="translated">Lead</target>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@
<trans-unit id="tx_lux_domain_model_log.properties">
<source>Properties</source>
</trans-unit>
<trans-unit id="tx_lux_domain_model_log.site">
<source>Site</source>
</trans-unit>
<trans-unit id="tx_lux_domain_model_log.visitor">
<source>Lead</source>
</trans-unit>
Expand Down
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ CREATE TABLE tx_lux_domain_model_log (

status tinyint(4) unsigned DEFAULT '0' NOT NULL,
properties text NOT NULL,
site varchar(255) DEFAULT '' NOT NULL,

tstamp int(11) unsigned DEFAULT '0' NOT NULL,
crdate int(11) unsigned DEFAULT '0' NOT NULL,
Expand Down

0 comments on commit 7f0c8fb

Please sign in to comment.