Skip to content

Commit

Permalink
[TASK] Add update wizard to update the page of form log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrodala committed Jan 10, 2025
1 parent a74d281 commit e4550b3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Classes/Updates/FormLogEntryPageUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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
{
private ConnectionPool $connectionPool;

public function __construct(ConnectionPool $connectionPool)
{
$this->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: 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
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

0 comments on commit e4550b3

Please sign in to comment.