-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add update wizard to update the page of form log entries
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters