Skip to content

Commit

Permalink
[TASK] Clean up code, adapt to PHP versions, drop usage of Extbase's …
Browse files Browse the repository at this point in the history
…localization utility in BE context, references #359, resolves #193
  • Loading branch information
fsuter committed Jan 20, 2025
1 parent f3f4339 commit 1c43377
Show file tree
Hide file tree
Showing 46 changed files with 286 additions and 527 deletions.
3 changes: 1 addition & 2 deletions Classes/Controller/DataModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Cobweb\ExternalImport\Domain\Repository\ConfigurationRepository;
use Cobweb\ExternalImport\Domain\Repository\SchedulerRepository;
use Cobweb\ExternalImport\Importer;
use Cobweb\ExternalImport\Utility\CompatibilityUtility;
use Cobweb\ExternalImport\Utility\CsvUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
Expand Down Expand Up @@ -385,7 +384,7 @@ public function newTaskAction(string $table, string $index = ''): ResponseInterf
{
// Add a close button to the toolbar
$this->prepareView('', 'listSynchronizable');
// $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker');
// $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker');

$this->view->assignMultiple(
[
Expand Down
1 change: 0 additions & 1 deletion Classes/Controller/LogModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

use Cobweb\ExternalImport\Domain\Repository\LogRepository;
use Cobweb\ExternalImport\Utility\CompatibilityUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/ConfigurationKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function setTableAndIndex(string $table, string $index): void
// Handle special cases for "all tables" and "group" configurations
if ($table === 'all') {
$this->configurationKey = 'all';
} elseif (strpos($table, 'group:') === 0) {
} elseif (str_starts_with($table, 'group:')) {
$this->configurationKey = $table;
} else {
$this->configurationKey = $table . self::CONCATENATOR . $index;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Dto/ChildrenSorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function replaceAllNewIds(array $replacements): void
{
foreach ($this->sortingInformation as $table => $items) {
foreach ($items as $key => $value) {
if (is_string($key) && strpos($key, 'NEW') === 0) {
if (is_string($key) && str_starts_with($key, 'NEW')) {
if (isset($replacements[$key])) {
$this->sortingInformation[$table][$replacements[$key]] = $value;
unset($this->sortingInformation[$table][$key]);
Expand Down
8 changes: 4 additions & 4 deletions Classes/Domain/Model/Dto/QueryParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class QueryParameters
*
* @param array|null $parameters Query parameters from the AJAX query
*/
public function __construct(?array $parameters)
public function __construct(?array $parameters = null)
{
if ($parameters !== null) {
$this->setAllParameters($parameters);
Expand All @@ -79,9 +79,9 @@ public function __construct(?array $parameters)
public function setAllParameters(array $parameters): void
{
// Set simple parameters
$this->setDraw((int)$parameters['draw']);
$this->setLimit((int)$parameters['length']);
$this->setOffset((int)$parameters['start']);
$this->setDraw(isset($parameters['draw']) ? (int)$parameters['draw'] : 0);
$this->setLimit(isset($parameters['length']) ? (int)$parameters['length'] : 0);
$this->setOffset(isset($parameters['start']) ? (int)$parameters['start'] : 0);
$this->setSearch((string)$parameters['search']['value']);
// Assemble list of search columns
$this->setSearchColumns($parameters['columns']);
Expand Down
4 changes: 1 addition & 3 deletions Classes/Domain/Repository/BackendUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@

use TYPO3\CMS\Extbase\Persistence\Repository;

class BackendUserRepository extends Repository
{
}
class BackendUserRepository extends Repository {}
10 changes: 5 additions & 5 deletions Classes/Domain/Repository/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* Pseudo-repository for fetching external import configurations from the TCA
Expand Down Expand Up @@ -213,6 +212,7 @@ public function findAllGroups(): array
*/
public function findConfigurationObject(string $table, $index, ?array $defaultSteps = null): Configuration
{
/** @var Configuration $configuration */
$configuration = GeneralUtility::makeInstance(Configuration::class);
$externalConfiguration = $this->findByTableAndIndex($table, $index);

Expand Down Expand Up @@ -272,14 +272,14 @@ public function findBySync(bool $isSynchronizable): array
}
$description = '';
if (isset($externalConfiguration['description'])) {
if (strpos($externalConfiguration['description'], 'LLL:') === 0) {
$description = LocalizationUtility::translate($externalConfiguration['description']);
if (str_starts_with($externalConfiguration['description'], 'LLL:')) {
$description = $GLOBALS['LANG']->sL($externalConfiguration['description']);
} else {
$description = $externalConfiguration['description'];
}
}
if (strpos($sections['ctrl']['title'] ?? '', 'LLL:') === 0) {
$tableTitle = LocalizationUtility::translate($sections['ctrl']['title']);
if (str_starts_with($sections['ctrl']['title'] ?? '', 'LLL:')) {
$tableTitle = $GLOBALS['LANG']->sL($sections['ctrl']['title']);
} else {
$tableTitle = $sections['ctrl']['title'] ?? 'untitled';
}
Expand Down
21 changes: 8 additions & 13 deletions Classes/Domain/Repository/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

use Cobweb\ExternalImport\Domain\Model\Dto\QueryParameters;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -27,15 +28,15 @@
*/
class LogRepository
{
static protected string $table = 'tx_externalimport_domain_model_log';
protected static string $table = 'tx_externalimport_domain_model_log';

public function countAll(): int
{
$query = $this->getQueryBuilder();
try {
return $query->count('*')
->from(self::$table)
->execute()
->executeQuery()
->fetchOne();
} catch (\Throwable) {
return 0;
Expand All @@ -47,8 +48,6 @@ public function countAll(): int
*
* @param QueryParameters $queryParameters
* @return array
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
*/
public function findBySearch(QueryParameters $queryParameters): array
Expand Down Expand Up @@ -79,7 +78,7 @@ public function findBySearch(QueryParameters $queryParameters): array
$query->setMaxResults($queryParameters->getLimit());
$query->setFirstResult($queryParameters->getOffset());
}
return $query->execute()->fetchAllAssociative();
return $query->executeQuery()->fetchAllAssociative();
}

/**
Expand All @@ -90,8 +89,7 @@ public function findBySearch(QueryParameters $queryParameters): array
*
* @param QueryParameters $queryParameters
* @return int
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
*/
public function countBySearch(QueryParameters $queryParameters): int
{
Expand All @@ -109,7 +107,7 @@ public function countBySearch(QueryParameters $queryParameters): int
)
);
}
return $query->execute()->fetchOne();
return $query->executeQuery()->fetchOne();
}

/**
Expand All @@ -123,19 +121,16 @@ public function countBySearch(QueryParameters $queryParameters): int
protected function assembleSearchConditions(QueryBuilder $query, string $search, array $searchColumns): array
{
$searchConditions = [];
$search = '%' . $search . '%';
$search = '%' . $query->escapeLikeWildcards($search) . '%';
foreach ($searchColumns as $column) {
$searchConditions[] = $query->expr()->like(
$column,
$search
$query->createNamedParameter($search)
);
}
return $searchConditions;
}

/**
* @throws \Doctrine\DBAL\DBALException
*/
public function insert(array $logData): void
{
$queryBuilder = $this->getQueryBuilder();
Expand Down
13 changes: 4 additions & 9 deletions Classes/Domain/Repository/SchedulerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Scheduler\CronCommand\NormalizeCommand;
use TYPO3\CMS\Scheduler\Domain\Repository\SchedulerTaskRepository;
use TYPO3\CMS\Scheduler\Exception\InvalidTaskException;
Expand Down Expand Up @@ -204,10 +203,9 @@ protected function assembleTaskInformation(AutomatedSyncTask $taskObject): array
'interval' => $interval,
'croncmd' => $cronCommand,
'frequency' => ($cronCommand !== '') ? $cronCommand : $interval,
'frequencyText' => ($cronCommand !== '') ? $cronCommand : LocalizationUtility::translate(
'number_of_seconds',
'external_import',
[$interval]
'frequencyText' => ($cronCommand !== '') ? $cronCommand : sprintf(
$GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/locallang.xlf:number_of_seconds'),
$interval
),
'group' => $taskObject->getTaskGroup(),
// Format date and time as needed for form input
Expand Down Expand Up @@ -262,10 +260,7 @@ public function saveTask(array $taskData): void
}
if ($result === false) {
throw new SchedulerRepositoryException(
LocalizationUtility::translate(
'taskSaveFailed',
'external_import'
),
'Creating or updating the task has failed (I know this is not very helpful, sorry).',
1509896783
);
}
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/DatamapPostprocessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function __construct(
* @var Importer Back-reference to the calling Importer instance
*/
protected Importer $importer
)
{
}
) {}

public function getImporter(): Importer
{
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/DeleteRecordsPreprocessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public function __construct(
* @var Importer Back-reference to the calling Importer instance
*/
protected Importer $importer
)
{
}
) {}

/**
* @return Importer
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/InsertRecordPreprocessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public function __construct(
* @var Importer Back-reference to the calling Importer instance
*/
protected Importer $importer
)
{
}
) {}

/**
* @return Importer
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/ProcessConnectorParametersEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public function __construct(
* @var Configuration Current External Import configuration
*/
protected Configuration $externalConfiguration
)
{
}
) {}

/**
* Returns the parameters.
Expand Down
4 changes: 1 addition & 3 deletions Classes/Event/ReportEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
*/
class ReportEvent
{
public function __construct(protected Importer $importer)
{
}
public function __construct(protected Importer $importer) {}

/**
* @return Importer
Expand Down
4 changes: 1 addition & 3 deletions Classes/Exception/CriticalFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
* Exception that should be thrown whenever a failed operation should stop the whole import,
* rather than just having a single record fail. See the documentation for more information.
*/
class CriticalFailureException extends Exception
{
}
class CriticalFailureException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/InvalidConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for missing configuration.
*/
class InvalidConfigurationException extends Exception
{
}
class InvalidConfigurationException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/InvalidCustomStepConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for invalid custom step configuration.
*/
class InvalidCustomStepConfiguration extends Exception
{
}
class InvalidCustomStepConfiguration extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/InvalidPayloadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
/**
* Exception to be thrown when the payload sent for import is not correct
*/
class InvalidPayloadException extends \RuntimeException
{
}
class InvalidPayloadException extends \RuntimeException {}
4 changes: 1 addition & 3 deletions Classes/Exception/InvalidPreviewStepException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for invalid step given for preview.
*/
class InvalidPreviewStepException extends Exception
{
}
class InvalidPreviewStepException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/InvalidRecordException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for invalidating a record during a process step.
*/
class InvalidRecordException extends Exception
{
}
class InvalidRecordException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/MissingConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for missing configuration.
*/
class MissingConfigurationException extends Exception
{
}
class MissingConfigurationException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/NoConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception when no configuration.
*/
class NoConfigurationException extends Exception
{
}
class NoConfigurationException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/NoSuchColumnException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception when the requested column does not exist or has no configuration.
*/
class NoSuchColumnException extends Exception
{
}
class NoSuchColumnException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/NoSuchRecordException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception when a searched for record is not found in the database.
*/
class NoSuchRecordException extends Exception
{
}
class NoSuchRecordException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/ReactionFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for missing configuration.
*/
class ReactionFailedException extends Exception
{
}
class ReactionFailedException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/SchedulerRepositoryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for errors in the SchedulerRepository.
*/
class SchedulerRepositoryException extends Exception
{
}
class SchedulerRepositoryException extends Exception {}
4 changes: 1 addition & 3 deletions Classes/Exception/UnknownReportingKeyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
/**
* Exception for invalid key in the reporting utility.
*/
class UnknownReportingKeyException extends Exception
{
}
class UnknownReportingKeyException extends Exception {}
Loading

0 comments on commit 1c43377

Please sign in to comment.