Skip to content

Commit

Permalink
WIP|Add TYPO3 13 LTS Support
Browse files Browse the repository at this point in the history
Relates: #11322
  • Loading branch information
DanielSiepmann authored and d-s-codappix committed Oct 17, 2024
1 parent 60b752e commit e6ac861
Show file tree
Hide file tree
Showing 59 changed files with 622 additions and 386 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ jobs:
typo3-version: '^12.4'
- php-version: '8.3'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -119,6 +123,10 @@ jobs:
typo3-version: '^12.4'
- php-version: '8.3'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v3

Expand Down
11 changes: 4 additions & 7 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@

use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use TYPO3Fluid\Fluid\View\ViewInterface;
use TYPO3Fluid\Fluid\View\ViewInterface as FluidStandaloneViewInterface;
use WerkraumMedia\Events\Caching\CacheManager;

class AbstractController extends ActionController
abstract class AbstractController extends ActionController
{
/**
* @var CacheManager
Expand Down Expand Up @@ -60,17 +61,13 @@ protected function initializeAction(): void
/**
* Extend original to also add data from current cobject if available.
*/
protected function resolveView(): ViewInterface
protected function initializeView(ViewInterface|FluidStandaloneViewInterface $view): void
{
$view = parent::resolveView();

$view->assign('data', []);
$cObject = $this->request->getAttribute('currentContentObject');
if ($cObject instanceof ContentObjectRenderer && is_array($cObject->data)) {
$view->assign('data', $cObject->data);
}

return $view;
}

protected function trigger404(string $message): void
Expand Down
16 changes: 9 additions & 7 deletions Classes/Domain/DestinationData/ImportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace WerkraumMedia\Events\Domain\DestinationData;

use Exception;
use PDO;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
use TYPO3\CMS\Extbase\Persistence\Generic\Session;
use WerkraumMedia\Events\Domain\Model\Import;
use WerkraumMedia\Events\Service\ExtbaseConfigurationManagerService;

final class ImportFactory
{
Expand All @@ -24,7 +24,8 @@ public function __construct(
private readonly ConnectionPool $connectionPool,
private readonly Session $extbasePersistenceSession,
private readonly DataMapper $dataMapper,
private readonly ResourceFactory $resourceFactory
private readonly ResourceFactory $resourceFactory,
private readonly ExtbaseConfigurationManagerService $extbaseConfigurationManagerService,
) {
}

Expand All @@ -49,14 +50,14 @@ private function fetchImportRecord(int $uid): array
$qb = $this->connectionPool->getQueryBuilderForTable('tx_events_domain_model_import');
$qb->select('*');
$qb->from('tx_events_domain_model_import');
$qb->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid, PDO::PARAM_INT)));
$qb->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));

$result = $qb->executeQuery()->fetch();
$result = $qb->executeQuery()->fetchAssociative();
if (is_array($result) === false) {
throw new Exception('Could not fetch import record with uid "' . $uid . '".', 1643267492);
}

$result = array_map('strval', $result);
$result = array_map(strval(...), $result);

return $result;
}
Expand All @@ -67,13 +68,13 @@ private function fetchImportRecords(): array
$qb->select('*');
$qb->from('tx_events_domain_model_import');

$result = $qb->executeQuery()->fetchAll();
$result = $qb->executeQuery()->fetchAllAssociative();
if (count($result) === 0) {
throw new Exception('Could not fetch any import record.', 1643267492);
}

foreach ($result as $key => $entry) {
$result[$key] = array_map('strval', $entry);
$result[$key] = array_map(strval(...), $entry);
}

return $result;
Expand All @@ -94,6 +95,7 @@ private function createWorkarounds(array $data): void
{
$this->folderInstance = $this->resourceFactory->getFolderObjectFromCombinedIdentifier($data['files_folder']);
$this->extbasePersistenceSession->registerObject($this->folderInstance, $data['files_folder']);
$this->extbaseConfigurationManagerService->configureForBackend();
}

private function cleanupWorkarounds(): void
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function findAllCurrentlyAssigned(

return $this->dataMapper->map(
Category::class,
$qb->executeQuery()->fetchAll()
$qb->executeQuery()->fetchAllAssociative()
);
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Repository/DateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function findSearchWord(string $search): array
)->orderBy('tx_events_domain_model_date.start')
;

return $statement->executeQuery()->fetchAll();
return $statement->executeQuery()->fetchAllAssociative();
}

private function createEventConstraint(
Expand Down
11 changes: 11 additions & 0 deletions Classes/Domain/Repository/OrganizerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
*/

use TYPO3\CMS\Extbase\Persistence\Repository;
use WerkraumMedia\Events\Domain\Model\Organizer;

final class OrganizerRepository extends Repository
{
public function findOneByName(string $name): ?Organizer
{
$organizer = $this->findOneBy(['name' => $name]);

if ($organizer instanceof Organizer) {
return $organizer;
}

return null;
}
}
2 changes: 1 addition & 1 deletion Classes/Extbase/AddSpecialProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function getOriginalDate(int $uidOfReferencedDate): ?Date
$qb->where($qb->expr()->eq('postponed_date', $uidOfReferencedDate));
$qb->setMaxResults(1);

$result = $qb->executeQuery()->fetch();
$result = $qb->executeQuery()->fetchAssociative();

if ($result === false) {
return null;
Expand Down
32 changes: 13 additions & 19 deletions Classes/Service/CategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WerkraumMedia\Events\Service;

use RuntimeException;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Database\Connection;
Expand All @@ -13,9 +14,9 @@

final class CategoryService
{
private TimeTracker $timeTracker;
private readonly TimeTracker $timeTracker;

private FrontendInterface $cache;
private readonly FrontendInterface $cache;

public function __construct()
{
Expand Down Expand Up @@ -77,17 +78,18 @@ protected function getChildrenCategoriesRecursive($idList, $counter = 0): string
->executeQuery()
;

while ($row = $res->fetch()) {
if (is_array($row) === false) {
continue;
}

foreach ($res->fetchAllAssociative() as $row) {
$counter++;
if ($counter > 10000) {
$this->timeTracker->setTSlogMessage('EXT:dd_events: one or more recursive categories where found');
return implode(',', $result);
}
$subcategories = $this->getChildrenCategoriesRecursive($row['uid'], $counter);
$uid = $row['uid'];
if (is_numeric($uid) === false) {
throw new RuntimeException('Given uid was not numeric, which we never expect as UID column within DB is numeric.', 1728998121);
}

$subcategories = $this->getChildrenCategoriesRecursive((string)$uid, $counter);
$result[] = $row['uid'] . ($subcategories ? ',' . $subcategories : '');
}

Expand All @@ -100,28 +102,20 @@ protected function getChildrenCategoriesRecursive($idList, $counter = 0): string
*/
protected function getUidListFromRecords(string $idList): string
{
$list = [];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_category')
;
$rows = $queryBuilder
$uids = $queryBuilder
->select('uid')
->from('sys_category')
->where($queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY)
))
->executeQuery()
->fetchAll()
->fetchFirstColumn()
;
foreach ($rows as $row) {
if (is_array($row) === false) {
continue;
}

$list[] = $row['uid'];
}

return implode(',', $list);
return implode(',', $uids);
}
}
3 changes: 1 addition & 2 deletions Classes/Service/Cleanup/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/

use DateTimeImmutable;
use PDO;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;

Expand Down Expand Up @@ -88,7 +87,7 @@ public function deleteEventsWithoutDates(): void
$recordUids = $queryBuilder->select('event.uid')
->from(self::EVENT_TABLE, 'event')
->leftJoin('event', self::DATE_TABLE, 'date', $queryBuilder->expr()->eq('date.event', 'event.uid'))->where($queryBuilder->expr()->isNull('date.uid'))->executeQuery()
->fetchAll(PDO::FETCH_COLUMN)
->fetchFirstColumn()
;

$queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::EVENT_TABLE);
Expand Down
21 changes: 11 additions & 10 deletions Classes/Service/Cleanup/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* 02110-1301, USA.
*/

use PDO;
use RuntimeException;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\StorageRepository;
Expand Down Expand Up @@ -84,16 +84,12 @@ private function markFileReferencesDeletedIfForeignRecordIsMissing(): void
$referencesQuery->orderBy('tablenames');
$referencesQuery->addOrderBy('uid_foreign');

$references = $referencesQuery->executeQuery();
$references = $referencesQuery->executeQuery()->fetchAllAssociative();

$uidsPerTable = [];
$referenceUidsToMarkAsDeleted = [];

while ($reference = $references->fetch()) {
if (is_array($reference) === false) {
continue;
}

foreach ($references as $reference) {
if ($reference['tablenames'] === '') {
$referenceUidsToMarkAsDeleted[] = $reference['uid'];
continue;
Expand All @@ -112,7 +108,7 @@ private function markFileReferencesDeletedIfForeignRecordIsMissing(): void
...$referenceUidsToMarkAsDeleted,
...array_keys(array_diff(
$records,
$queryBuilder->executeQuery()->fetchAll(PDO::FETCH_COLUMN)
$queryBuilder->executeQuery()->fetchFirstColumn()
)),
];
}
Expand Down Expand Up @@ -249,11 +245,16 @@ private function filterPotentialFilesToDelete(array $files): array
foreach ($queryBuilder->executeQuery()->iterateAssociative() as $reference) {
$file = [];
$fileUid = (int)$reference['uid_local'];
$tableNames = $reference['tablenames'];

if (is_string($tableNames) === false) {
throw new RuntimeException('Fetched "tablenames" was not of type string. But it should be a string within the db.', 1728998600);
}

if (
(
str_starts_with((string)$reference['tablenames'], 'tx_events_domain_model_')
|| $reference['tablenames'] === ''
str_starts_with($tableNames, 'tx_events_domain_model_')
|| $tableNames === ''
) && $reference['deleted'] == 1
) {
$file = $files[$fileUid] ?? [];
Expand Down
9 changes: 8 additions & 1 deletion Classes/Service/DataProcessingForModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ public function process(

private function getData(AbstractEntity $entity): array
{
$row = $this->connection->select(['*'], $this->getTable($entity), ['uid' => $entity->getUid()])->fetch();
$row = $this->connection
->select(
['*'],
$this->getTable($entity),
['uid' => $entity->getUid()]
)
->fetchAssociative()
;
if (is_array($row)) {
return $row;
}
Expand Down
15 changes: 5 additions & 10 deletions Classes/Service/DestinationDataImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ final class DestinationDataImportService

private Event $tmpCurrentEvent;

/**
* @var Logger
*/
private $logger;
private readonly Logger $logger;

/**
* ImportService constructor.
*/
public function __construct(
private readonly EventRepository $eventRepository,
private readonly OrganizerRepository $organizerRepository,
Expand All @@ -60,8 +54,10 @@ public function __construct(
private readonly Slugger $slugger,
private readonly CacheManager $cacheManager,
private readonly DataHandler $dataHandler,
private readonly EventDispatcher $eventDispatcher
private readonly EventDispatcher $eventDispatcher,
LogManager $logManager,
) {
$this->logger = $logManager->getLogger(self::class);
}

public function import(
Expand All @@ -83,7 +79,6 @@ public function import(

// Set Configuration
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(self::class);
$this->logger->info('Starting Destination Data Import Service');

try {
Expand Down Expand Up @@ -412,7 +407,7 @@ private function setTexts(array $texts): void

private function getOrCreateEvent(string $globalId, string $title): Event
{
$event = $this->eventRepository->findOneByGlobalId($globalId);
$event = $this->eventRepository->findOneBy(['globalId' => $globalId]);

if ($event instanceof Event) {
$this->logger->info(
Expand Down
Loading

0 comments on commit e6ac861

Please sign in to comment.