Skip to content

Commit

Permalink
Merge pull request #235 from pagemachine/decouple-page
Browse files Browse the repository at this point in the history
Decouple page info in log entries
  • Loading branch information
mbrodala authored Jan 10, 2025
2 parents c828e38 + d7fa6b5 commit 564d5d7
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Classes/Domain/Form/Finishers/LoggerFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ protected function executeInternal()
}

$data = [
'pid' => $this->getTypoScriptFrontendController()->id,
'crdate' => $now,
'tstamp' => $now,
'page' => $this->getTypoScriptFrontendController()->id,
'language' => (int)$context->getPropertyFromAspect('language', 'id', 0),
'identifier' => $formDefinition->getIdentifier(),
'data' => $encodedFormValues,
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/FormLog/Suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getForProperty(string $property): array
'tx_formlog_entries',
'pages',
'page',
$queryBuilder->expr()->eq('page.uid', $queryBuilder->quoteIdentifier('tx_formlog_entries.pid'))
$queryBuilder->expr()->eq('page.uid', $queryBuilder->quoteIdentifier('tx_formlog_entries.page'))
)
->orderBy($property)
->groupBy($property);
Expand Down
70 changes: 70 additions & 0 deletions Classes/Updates/FormLogEntryPageUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Pagemachine\Formlog\Updates;

/*
* This file is part of the Pagemachine TYPO3 Formlog project.
*/

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;

final class FormLogEntryPageUpdate implements UpgradeWizardInterface
{
public function __construct(
private readonly ConnectionPool $connectionPool
) {}

public function getIdentifier(): string
{
return self::class;
}

public function getTitle(): string
{
return 'Form Log Entry Page Update';
}

public function getDescription(): string
{
return 'Move page info of form log entries to a dedicated field';
}

public function executeUpdate(): bool
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_formlog_entries');

$affectedRowCount = $queryBuilder
->update('tx_formlog_entries')
->set('page', $queryBuilder->quoteIdentifier('pid'), false)
->set('pid', 0)
->where($queryBuilder->expr()->eq('page', 0))
->executeStatement();

return $affectedRowCount > 0;
}

public function updateNecessary(): bool
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_formlog_entries');

$entriesWithoutPageCount = $queryBuilder
->count('*')
->from('tx_formlog_entries')
->where($queryBuilder->expr()->eq('page', 0))
->executeQuery()
->fetchOne();

return $entriesWithoutPageCount > 0;
}

public function getPrerequisites(): array
{
return [
DatabaseUpdatedPrerequisite::class,
];
}
}
3 changes: 0 additions & 3 deletions Configuration/Extbase/Persistence/Classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
'submissionDate' => [
'fieldName' => 'crdate',
],
'page' => [
'fieldName' => 'pid',
],
],
],
\Pagemachine\Formlog\Domain\Model\FormLogEntry\Page::class => [
Expand Down
3 changes: 3 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ services:

Pagemachine\Formlog\Controller\Backend\FormLogSuggestController:
public: true

Pagemachine\Formlog\Updates\FormLogEntryPageUpdate:
public: true
21 changes: 14 additions & 7 deletions Configuration/TCA/tx_formlog_entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@
'crdate' => 'crdate',
'tstamp' => 'tstamp',
'delete' => 'deleted',
'rootLevel' => -1,
'readOnly' => true,
'iconfile' => 'EXT:formlog/Resources/Public/Icons/tx_formlog_entries.svg',
],
'types' => [
'0' => [
'showitem' => 'crdate, language, identifier, data, finisher_variables',
'showitem' => 'crdate, page, language, identifier, data, finisher_variables',
],
],
'columns' => [
'pid' => [
'config' => [
'type' => 'passthrough',
'foreign_table' => 'pages',
],
],
'crdate' => [
'exclude' => 1,
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate',
Expand All @@ -34,6 +29,18 @@
'eval' => 'datetime',
],
],
'page' => [
'exclude' => 1,
'label' => 'LLL:EXT:formlog/Resources/Private/Language/locallang_db.xml:tx_formlog_entries.page',
'config' => [
'type' => 'group',
'allowed' => 'pages',
'foreign_table' => 'pages',
'maxitems' => 1,
'size' => 1,
'readOnly' => true,
],
],
'language' => [
'exclude' => 1,
'label' => 'LLL:EXT:formlog/Resources/Private/Language/locallang_db.xml:tx_formlog_entries.language',
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<source>Form log entry</source>
</trans-unit>

<trans-unit id="tx_formlog_entries.page">
<source>Form page</source>
</trans-unit>

<trans-unit id="tx_formlog_entries.language">
<source>Form language</source>
</trans-unit>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Domain/Form/Finishers/LoggerFinisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function logsSubmittedFormData(array $fields, array $formValues, string $
->select(['*'], 'tx_formlog_entries')
->fetchAssociative();

self::assertSame(123, $logEntry['pid'] ?? null);
self::assertSame(123, $logEntry['page'] ?? null);
self::assertSame($formDefinition->getIdentifier(), $logEntry['identifier'] ?? null);
self::assertSame($expectedData, $logEntry['data'] ?? null);
self::assertSame('[]', $logEntry['finisher_variables'] ?? null);
Expand Down Expand Up @@ -232,7 +232,7 @@ public function logsFinisherVariables()
->select(['*'], 'tx_formlog_entries')
->fetchAssociative();

self::assertSame(123, $logEntry['pid'] ?? null);
self::assertSame(123, $logEntry['page'] ?? null);
self::assertSame($formDefinition->getIdentifier(), $logEntry['identifier'] ?? null);
self::assertSame('{"name":"Tester"}', $logEntry['data'] ?? null);
self::assertSame('{"SaveToDatabase":{"insertedUids.0":124}}', $logEntry['finisher_variables'] ?? null);
Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/Domain/FormLog/SuggestionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public function returnsSuggestionsForProperty(string $property, array $expected)
'tx_formlog_entries' => [
[
'uid' => 1,
'pid' => 2,
'page' => 2,
'identifier' => 'foo',
],
[
'uid' => 2,
'pid' => 2,
'page' => 2,
'identifier' => 'foo',
],
[
'uid' => 3,
'pid' => 1,
'page' => 1,
'identifier' => 'bar',
],
],
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"typo3/cms-fluid": "^11.5.4 || ^12.4",
"typo3/cms-form": "^11.5.4 || ^12.4",
"typo3/cms-frontend": "^11.5.4 || ^12.4",
"typo3/cms-install": "^11.5.4 || ^12.4",
"typo3fluid/fluid": "^2.3 || ^4.0"
},
"require-dev": {
Expand Down
3 changes: 3 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Pagemachine\Formlog\Form\Element\JSONDataElement;
use Pagemachine\Formlog\Updates\FormLogEntryPageUpdate;
use TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask;

defined('TYPO3') or die();
Expand All @@ -14,6 +15,8 @@
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:form/Resources/Private/Language/Database.xlf'][1519643592] = 'EXT:formlog/Resources/Private/Language/Database.xlf';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['de']['EXT:form/Resources/Private/Language/Database.xlf'][1519643592] = 'EXT:formlog/Resources/Private/Language/de.Database.xlf';

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][FormLogEntryPageUpdate::class] = FormLogEntryPageUpdate::class;

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][TableGarbageCollectionTask::class]['options']['tables']['tx_formlog_entries'] = [
'dateField' => 'tstamp',
'expirePeriod' => 180,
Expand Down
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE TABLE tx_formlog_entries (
page int(11) unsigned DEFAULT '0' NOT NULL,
language int(11) unsigned DEFAULT '0' NOT NULL,
identifier varchar(255) DEFAULT '' NOT NULL,
data mediumtext,
Expand Down

0 comments on commit 564d5d7

Please sign in to comment.