102 lines
2.9 KiB
PHP
Executable File
102 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Evoweb\EwBase\Updates;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
use Psr\Log\LogLevel;
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
|
|
use TYPO3\CMS\Core\Log\LogManager;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Install\Attribute\UpgradeWizard;
|
|
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
|
|
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
|
|
|
|
/**
|
|
* Migrate gridelements elements to container elements
|
|
*/
|
|
#[UpgradeWizard('gridelementsToContainer')]
|
|
class GridelementsToContainerMigration implements UpgradeWizardInterface
|
|
{
|
|
private const TABLE_NAME = 'tt_content';
|
|
|
|
protected LoggerInterface $logger;
|
|
|
|
public function __construct(
|
|
protected GridelementsToContainerService $service,
|
|
protected LogManager $logManager,
|
|
) {
|
|
$this->logger = $logManager->getLogger(self::class);
|
|
}
|
|
|
|
public function getIdentifier(): string
|
|
{
|
|
return 'gridelementsToContainer';
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return 'Migrate gridelements to container';
|
|
}
|
|
|
|
public function getDescription(): string
|
|
{
|
|
return 'Migrates content elements that are type gridelements to corresponding container elements';
|
|
}
|
|
|
|
public function getPrerequisites(): array
|
|
{
|
|
return [
|
|
DatabaseUpdatedPrerequisite::class
|
|
];
|
|
}
|
|
|
|
public function updateNecessary(): bool
|
|
{
|
|
return $this->hasRecordsToUpdate();
|
|
}
|
|
|
|
public function executeUpdate(): bool
|
|
{
|
|
$updateSuccessful = true;
|
|
try {
|
|
$this->service->migrate();
|
|
} catch (\Exception $exception) {
|
|
$this->logger->log(LogLevel::ERROR, $exception->getMessage());
|
|
$updateSuccessful = false;
|
|
}
|
|
|
|
return $updateSuccessful;
|
|
}
|
|
|
|
protected function hasRecordsToUpdate(): bool
|
|
{
|
|
return (bool)$this->getPreparedQueryBuilder()->count('uid')->executeQuery()->fetchOne();
|
|
}
|
|
|
|
protected function getPreparedQueryBuilder(): QueryBuilder
|
|
{
|
|
$queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable(self::TABLE_NAME);
|
|
$queryBuilder->getRestrictions()
|
|
->removeByType(HiddenRestriction::class)
|
|
->removeByType(StartTimeRestriction::class)
|
|
->removeByType(EndTimeRestriction::class);
|
|
$queryBuilder
|
|
->from(self::TABLE_NAME)
|
|
->where(
|
|
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('gridelements_pi1'))
|
|
);
|
|
return $queryBuilder;
|
|
}
|
|
|
|
protected function getConnectionPool(): ConnectionPool
|
|
{
|
|
return GeneralUtility::makeInstance(ConnectionPool::class);
|
|
}
|
|
}
|