Skip to content

Commit

Permalink
More generic cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Sep 29, 2024
1 parent 830faee commit a008724
Show file tree
Hide file tree
Showing 32 changed files with 63 additions and 122 deletions.
35 changes: 13 additions & 22 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace SFC\Staticfilecache\Controller;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -18,14 +20,19 @@
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class BackendController extends ActionController
class BackendController extends ActionController implements LoggerAwareInterface
{
public function __construct(protected QueueService $queueService, protected ModuleTemplateFactory $moduleTemplateFactory) {}
use LoggerAwareTrait;

public function __construct(
readonly protected QueueService $queueService,
readonly protected ModuleTemplateFactory $moduleTemplateFactory,
readonly protected ConfigurationService $configurationService
) {}

public function listAction(string $filter = ''): ResponseInterface
{
Expand All @@ -44,7 +51,6 @@ public function listAction(string $filter = ''): ResponseInterface

public function boostAction(bool $run = false): ResponseInterface
{
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$queueRepository = GeneralUtility::makeInstance(QueueRepository::class);
if ($run) {
$items = $queueRepository->findOpen(10);
Expand All @@ -60,7 +66,7 @@ public function boostAction(bool $run = false): ResponseInterface
$this->addFlashMessage('Run ' . \count($items) . ' entries', 'Runner', ContextualFeedbackSeverity::OK, true);
}
$viewVariables = [
'enable' => (bool) $configurationService->get('boostMode'),
'enable' => (bool) $this->configurationService->get('boostMode'),
'open' => \count($queueRepository->findOpen(99999999)),
'old' => \count($queueRepository->findOldUids()),
];
Expand Down Expand Up @@ -107,26 +113,19 @@ protected function setFilter(string $filter): string
return $filter;
}

/**
* Get backend user.
*/
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}

/**
* Get cache pages entries.
*/
protected function getCachePagesEntries(string $filter): array
{
$rows = [];

try {
$cache = GeneralUtility::makeInstance(CacheService::class)->get();
} catch (\Exception $exception) {
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->error('Problems by fetching the cache: ' . $exception->getMessage() . ' / ' . $exception->getFile() . ':' . $exception->getLine());
$this->logger->error('Problems by fetching the cache: ' . $exception->getMessage() . ' / ' . $exception->getFile() . ':' . $exception->getLine());

return $rows;
}
Expand Down Expand Up @@ -160,19 +159,11 @@ protected function getCachePagesEntries(string $filter): array
});
}

/**
* Get display mode.
*/
protected function getDisplayMode(): string
{
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);

return $configurationService->getBackendDisplayMode();
return $this->configurationService->getBackendDisplayMode();
}

/**
* Get the current UID.
*/
protected function getCurrentUid(): int
{
return (int) ($this->request->getQueryParams()['id'] ?? 0);
Expand Down
27 changes: 1 addition & 26 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,23 @@
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* AbstractRepository.
*
* @todo move methods to iterator?
*/
abstract class AbstractRepository
{
/**
* Delete records.
*/
public function delete(array $identifiers): void
{
$this->getConnection()->delete($this->getTableName(), $identifiers);
}

/**
* Truncate the table.
*/
public function truncate(): void
{
$this->getConnection()->truncate($this->getTableName());
}

/**
* Insert record.
*/
public function insert(array $data): void
{
$this->getConnection()->insert($this->getTableName(), $data);
}

/**
* Update records.
*/
public function update(array $data, array $identifiers): void
{
$this->getConnection()->update(
Expand All @@ -52,22 +35,14 @@ public function update(array $data, array $identifiers): void
);
}

/**
* Get the table name.
*/

abstract protected function getTableName(): string;

/**
* Create query.
*/
protected function createQuery(): QueryBuilder
{
return $this->getConnection()->createQueryBuilder();
}

/**
* Get connection.
*/
protected function getConnection(): Connection
{
return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->getTableName());
Expand Down
6 changes: 3 additions & 3 deletions Classes/Domain/Repository/CacheRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CacheRepository extends AbstractRepository
{
/**
* Get the expired cache identifiers.
* @todo move methods to iterator?
*/
public function findExpiredIdentifiers(): array
{
Expand All @@ -35,6 +36,7 @@ public function findExpiredIdentifiers(): array

/**
* Get all the cache identifiers.
* @todo move methods to iterator?
*/
public function findAllIdentifiers(): array
{
Expand All @@ -48,9 +50,7 @@ public function findAllIdentifiers(): array
return $cacheIdentifiers;
}

/**
* Get the table name.
*/

protected function getTableName(): string
{
$prefix = 'cache_';
Expand Down
7 changes: 1 addition & 6 deletions Classes/Domain/Repository/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

namespace SFC\Staticfilecache\Domain\Repository;

/**
* PageRepository.
*/
class PageRepository extends AbstractRepository
{
/**
* Get for backend output.
*
* @param int $pageId
* @param string $displayMode
* @todo move methods to iterator?
*/
public function findForBackend($pageId, $displayMode): array
{
Expand Down Expand Up @@ -48,9 +46,6 @@ public function findForBackend($pageId, $displayMode): array
;
}

/**
* Get the table name.
*/
protected function getTableName(): string
{
return 'pages';
Expand Down
14 changes: 5 additions & 9 deletions Classes/Domain/Repository/QueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

namespace SFC\Staticfilecache\Domain\Repository;

/**
* QueueRepository.
*/
class QueueRepository extends AbstractRepository
{
/**
* Find the entries for the worker.
*
* @param int $limit
* @todo move methods to iterator?
*/
public function findOpen($limit = 999): array
{
Expand All @@ -29,9 +26,9 @@ public function findOpen($limit = 999): array
}

/**
* Find open by identnfier.
* Find open by identifier.
*
* @param string $identifier
* @todo move methods to iterator?
*/
public function countOpenByIdentifier($identifier): int
{
Expand All @@ -52,6 +49,8 @@ public function countOpenByIdentifier($identifier): int
/**
* Find old entries.
* @return list<int>
*
* @todo move methods to iterator?
*/
public function findOldUids(): array
{
Expand All @@ -65,9 +64,6 @@ public function findOldUids(): array
;
}

/**
* Get the table name.
*/
protected function getTableName(): string
{
return 'tx_staticfilecache_queue';
Expand Down
2 changes: 1 addition & 1 deletion Classes/Event/CacheRuleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class CacheRuleEvent implements CacheRuleEventInterface
{
public function __construct(
private ServerRequestInterface $request,
readonly private ServerRequestInterface $request,
private array $explanation,
private bool $skipProcessing
) {}
Expand Down
6 changes: 5 additions & 1 deletion Classes/Event/CacheRuleFallbackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

final class CacheRuleFallbackEvent implements CacheRuleEventInterface
{
public function __construct(private ServerRequestInterface $request, private array $explanation, private bool $skipProcessing) {}
public function __construct(
readonly private ServerRequestInterface $request,
private array $explanation,
private bool $skipProcessing
) {}

public function getRequest(): ServerRequestInterface
{
Expand Down
6 changes: 5 additions & 1 deletion Classes/Event/ForceStaticFileCacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

final class ForceStaticFileCacheEvent
{
public function __construct(private bool $forceStatic, private ?TypoScriptFrontendController $frontendController, private ServerRequestInterface $request) {}
public function __construct(
private bool $forceStatic,
private ?TypoScriptFrontendController $frontendController,
private ServerRequestInterface $request
) {}

public function isForceStatic(): bool
{
Expand Down
2 changes: 0 additions & 2 deletions Classes/Event/GeneratorRemove.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace SFC\Staticfilecache\Event;

use Psr\Http\Message\ResponseInterface;

final class GeneratorRemove
{
public function __construct(
Expand Down
6 changes: 5 additions & 1 deletion Classes/Event/PreGenerateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

final class PreGenerateEvent
{
public function __construct(private string $uri, private ServerRequestInterface $request, private ResponseInterface $response) {}
public function __construct(
private string $uri,
readonly private ServerRequestInterface $request,
private ResponseInterface $response
) {}

public function getUri(): string
{
Expand Down
13 changes: 7 additions & 6 deletions Classes/EventListener/AfterPackageDeactivationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
use SFC\Staticfilecache\Service\CacheService;
use SFC\Staticfilecache\Service\ConfigurationService;
use TYPO3\CMS\Core\Package\Event\AfterPackageDeactivationEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class AfterPackageDeactivationListener
{
public function __construct(
readonly private ConfigurationService $configurationService,
readonly private CacheService $cacheService,
) {}

public function __invoke(AfterPackageDeactivationEvent $event): void
{
$configuration = GeneralUtility::makeInstance(ConfigurationService::class);
$configuration->override('boostMode', '0');

$cacheService = GeneralUtility::makeInstance(CacheService::class);
$cacheService->get()->flush();
$this->configurationService->override('boostMode', '0');
$this->cacheService->get()->flush();
}
}
7 changes: 0 additions & 7 deletions Classes/Service/AbstractService.php

This file was deleted.

5 changes: 1 addition & 4 deletions Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Cache Service.
*/
class CacheService extends AbstractService
class CacheService
{
/**
* Get the StaticFileCache.
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ClientService extends AbstractService implements LoggerAwareInterface
class ClientService implements LoggerAwareInterface
{
use LoggerAwareTrait;

Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Handle extension and TS configuration.
*/
class ConfigurationService extends AbstractService
class ConfigurationService
{
/**
* Current configuration.
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/CookieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Handle cookie related stuff.
*/
class CookieService extends AbstractService implements LoggerAwareInterface
class CookieService implements LoggerAwareInterface
{
use LoggerAwareTrait;

Expand Down
Loading

0 comments on commit a008724

Please sign in to comment.