Skip to content

Commit

Permalink
[UPDATE] IchHabRecht#81: update for TYPO3 v13
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryd committed Mar 21, 2024
1 parent be12bf3 commit 23e7cb6
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 168 deletions.
13 changes: 7 additions & 6 deletions Classes/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace IchHabRecht\Filefill\Command;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\ParameterType;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -20,20 +21,20 @@ protected function getEnabledStorages(): array
$rows = $queryBuilder->select('uid', 'name')
->from('sys_file_storage')
->where(
$expressionBuilder->orX(
$expressionBuilder->or(
$expressionBuilder->eq(
'tx_filefill_enable',
$queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter(1, ParameterType::INTEGER)
),
$expressionBuilder->in(
'uid',
$queryBuilder->createNamedParameter($configuredStorages, Connection::PARAM_INT_ARRAY)
$queryBuilder->createNamedParameter($configuredStorages, ArrayParameterType::INTEGER)
)
)
)
->orderBy('uid')
->execute()
->fetchAll();
->executeQuery()
->fetchAllAssociative();

return array_combine(array_map('intval', array_column($rows, 'uid')), $rows);
}
Expand Down
10 changes: 2 additions & 8 deletions Classes/Command/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@

class DeleteCommand extends AbstractCommand
{
/**
* @var FileRepository
*/
protected $fileRepository;
protected FileRepository $fileRepository;

/**
* @var LanguageService
*/
protected $languageService;
protected LanguageService $languageService;

public function __construct(string $name = null, FileRepository $fileRepository = null, $languageService = null)
{
Expand Down
26 changes: 11 additions & 15 deletions Classes/Command/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace IchHabRecht\Filefill\Command;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use IchHabRecht\Filefill\Repository\FileRepository;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -14,15 +16,9 @@

class ResetCommand extends AbstractCommand
{
/**
* @var \TYPO3\CMS\Core\Database\Connection
*/
protected $connection;
protected Connection $connection;

/**
* @var FileRepository
*/
protected $fileRepository;
protected FileRepository $fileRepository;

public function __construct(string $name = null, Connection $connection = null, FileRepository $fileRepository = null)
{
Expand Down Expand Up @@ -76,28 +72,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->where(
$expressionBuilder->in(
'f.storage',
$queryBuilder->createNamedParameter(array_keys($enabledStorages), Connection::PARAM_INT_ARRAY)
$queryBuilder->createNamedParameter(array_keys($enabledStorages), ArrayParameterType::INTEGER)
),
$expressionBuilder->eq(
'f.missing',
$queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter(1, ParameterType::INTEGER)
)
)
->groupBy('f.storage')
->orderBy('f.storage')
->execute();
->executeQuery();

while ($row = $statement->fetch()) {
while ($row = $statement->fetchAssociative()) {
$updateQueryBuilder = $this->connection->createQueryBuilder();
$updateQueryBuilder->update('sys_file')
->where(
$updateQueryBuilder->expr()->eq(
'storage',
$updateQueryBuilder->createNamedParameter($row['storage'], \PDO::PARAM_INT)
$updateQueryBuilder->createNamedParameter($row['storage'], ParameterType::INTEGER)
)
)
->set('missing', 0, true, \PDO::PARAM_INT)
->execute();
->set('missing', 0, true, ParameterType::INTEGER)
->executeStatement();
$output->writeln(sprintf(
'Reset %d file(s) in storage "%s" (uid: %d)',
$row['count'],
Expand Down
34 changes: 11 additions & 23 deletions Classes/Form/Element/ShowDeleteFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,36 @@

use IchHabRecht\Filefill\Repository\FileRepository;
use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ShowDeleteFiles extends AbstractFormElement
{
/**
* @var FileRepository|null
*/
protected $fileRepository;

/**
* @var LanguageService
*/
protected $languageService;

/**
* Container objects give $nodeFactory down to other containers.
*
* @param NodeFactory $nodeFactory
* @param array $data
* @param FileRepository|null $fileRepository
* @param LanguageService|null $languageService
* @param FileRepository $fileRepository
* @param LanguageService $languageService
*/
public function __construct(NodeFactory $nodeFactory, array $data, FileRepository $fileRepository = null, $languageService = null)
{
parent::__construct($nodeFactory, $data);
$this->fileRepository = $fileRepository ?: GeneralUtility::makeInstance(FileRepository::class);
$this->languageService = $languageService ?: $GLOBALS['LANG'];
public function __construct(
protected readonly FileRepository $fileRepository,
protected readonly LanguageService $languageService
) {
}

/**
* @return array
*/
public function render()
public function render(): array
{
$result = $this->initializeResultArray();

$rows = $this->fileRepository->countByIdentifier($this->data['vanillaUid']);

// TODO https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-97330-FormEngineElementClassesMustCreateLabelOrLegend.html

$html = [];
$html[] = '<div class="form-control-wrap">';

Expand All @@ -75,7 +63,7 @@ public function render()
$html[] = '</div>';
$html[] = '<div class="form-control-wrap t3js-module-docheader">';
$html[] = '<a class="btn btn-default t3js-editform-submitButton" data-name="_save_tx_filefill_delete" data-form="EditDocumentController" data-value="' . $row['tx_filefill_identifier'] . '">';
$html[] = $iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL);
$html[] = $iconFactory->getIcon('actions-edit-delete', IconSize::SMALL);
$html[] = ' ' . sprintf(
$this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.delete_files'),
$row['count'],
Expand Down
30 changes: 11 additions & 19 deletions Classes/Form/Element/ShowMissingFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,30 @@
* LICENSE file that was distributed with this source code.
*/

use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ShowMissingFiles extends AbstractFormElement
{
/**
* @var LanguageService
*/
protected $languageService;

/**
* Container objects give $nodeFactory down to other containers.
*
* @param NodeFactory $nodeFactory
* @param array $data
* @param LanguageService|null $languageService
* @throws \InvalidArgumentException
*/
public function __construct(NodeFactory $nodeFactory, array $data, $languageService = null)
public function __construct(protected readonly LanguageService $languageService)
{
parent::__construct($nodeFactory, $data);
$this->languageService = $languageService ?: $GLOBALS['LANG'];
}

/**
* @return array
*/
public function render()
public function render(): array
{
$result = $this->initializeResultArray();

Expand All @@ -61,15 +51,17 @@ public function render()
->where(
$expressionBuilder->eq(
'storage',
$queryBuilder->createNamedParameter($this->data['vanillaUid'], \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($this->data['vanillaUid'], ParameterType::INTEGER)
),
$expressionBuilder->eq(
'missing',
$queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter(1, ParameterType::INTEGER)
)
)
->execute()
->fetch(FetchMode::NUMERIC)[0] ?? 0;
->executeQuery()
->fetchNumeric()[0] ?? 0;

// TODO https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-97330-FormEngineElementClassesMustCreateLabelOrLegend.html

$html = [];
$html[] = '<div class="form-control-wrap">';
Expand All @@ -89,7 +81,7 @@ public function render()
$html[] = '</div>';
$html[] = '<div class="form-control-wrap t3js-module-docheader">';
$html[] = '<a class="btn btn-default t3js-editform-submitButton" data-name="_save_tx_filefill_missing" data-form="EditDocumentController" data-value="1">';
$html[] = $iconFactory->getIcon('actions-database-reload', Icon::SIZE_SMALL);
$html[] = $iconFactory->getIcon('actions-database-reload', IconSize::SMALL);
$html[] = ' ' . $this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.reset');
$html[] = '</a>';
}
Expand Down
5 changes: 3 additions & 2 deletions Classes/Hooks/ResetMissingFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* LICENSE file that was distributed with this source code.
*/

use Doctrine\DBAL\ParameterType;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand All @@ -42,10 +43,10 @@ public function processDatamap_afterDatabaseOperations($status, $table, $id)
->where(
$expressionBuilder->eq(
'storage',
$queryBuilder->createNamedParameter((int)$id, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter((int)$id, ParameterType::INTEGER)
)
)
->set('missing', 0)
->execute();
->executeStatement();
}
}
4 changes: 2 additions & 2 deletions Classes/Imaging/GifBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

class GifBuilder extends \TYPO3\CMS\Frontend\Imaging\GifBuilder
{
public function fileName($pre)
public function fileName(): string
{
$fileName = parent::fileName($pre);
$fileName = parent::fileName();
$temporaryPath = Environment::getVarPath() . '/transient/';
if (!is_dir($temporaryPath)) {
GeneralUtility::mkdir_deep($temporaryPath);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Repository/DomainResourceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DomainResourceRepository
/**
* @return DomainResource[]
*/
public function findAll()
public function findAll(): array
{
$domainResources = [];

Expand Down
Loading

0 comments on commit 23e7cb6

Please sign in to comment.