Skip to content
Snippets Groups Projects

[TASK] Require TYPO3 12

Merged Kevin Ditscheid requested to merge upgrade_TYPO3v12_phase3 into master
All threads resolved!
Compare and
130 files
+ 1291
16159
Compare changes
  • Side-by-side
  • Inline
Files
130
@@ -26,6 +26,8 @@
namespace SGalinski\SgMail\Command;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Exception;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -37,7 +39,6 @@ use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\Exception;
/**
* Class DeleteOldMailsCommand
@@ -53,12 +54,12 @@ class DeleteOldMailsCommand extends Command {
/**
* @var int
*/
private $amountOfDeletedRecords = 0;
private int $amountOfDeletedRecords = 0;
/**
* Configure the command by defining the name, options and arguments
*/
protected function configure() {
protected function configure(): void {
$this->setDescription(
'Automatically deletes records from `tx_sgmail_domain_model_mail`, which are older than the specified age. Attachments sent as part of the email are deleted as well.'
)->addArgument(
@@ -73,10 +74,10 @@ class DeleteOldMailsCommand extends Command {
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$io = new SymfonyStyle($input, $output);
$io->title($this->getDescription());
$maxAgeArg = $input->getArgument('maxAge');
@@ -84,7 +85,7 @@ class DeleteOldMailsCommand extends Command {
if ($maxAgeInDays <= 0) {
$io->error('Please enter a maximum age (in days) for the mail\'s to be deleted.');
return 0;
return self::SUCCESS;
}
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
@@ -92,7 +93,7 @@ class DeleteOldMailsCommand extends Command {
$mailUidsForDeletion = $mailRepository->findMailsForDeletion($maxAgeInDays);
if (!$mailUidsForDeletion) {
$io->success("No matching mails found for deletion criteria: older than $maxAgeInDays days");
return 0;
return self::SUCCESS;
}
$this->deleteAttachments($mailUidsForDeletion);
@@ -104,7 +105,7 @@ class DeleteOldMailsCommand extends Command {
$io->note('No records deleted');
}
return 0;
return self::SUCCESS;
}
/**
@@ -117,18 +118,15 @@ class DeleteOldMailsCommand extends Command {
self::TABLE_NAME_MAIL
);
$this->amountOfDeletedRecords += $queryBuilder
->delete(self::TABLE_NAME_MAIL)
->where(
$queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter($mailUidsForDeletion, Connection::PARAM_INT_ARRAY)
)
)->execute();
->delete(self::TABLE_NAME_MAIL)->where($queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter($mailUidsForDeletion, ArrayParameterType::INTEGER)
))->executeStatement();
}
/**
* Deletes the attachments (sys_file_reference / sys_file records), referenced in the mails to be deleted.
* For every file reference found in a mail record, we check if it is the only reference,
* For every file-reference found in a mail record, we check if it is the only reference,
* or if we can find more records, referencing the same sys_file.
*
* The sys_file_reference found in the mail record is always deleted.
@@ -136,6 +134,7 @@ class DeleteOldMailsCommand extends Command {
* the actual file in the file system is deleted as well.
*
* @param array $mailUidsForDeletion
* @throws Exception
*/
private function deleteAttachments(array $mailUidsForDeletion): void {
$fileReferenceQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
@@ -144,24 +143,19 @@ class DeleteOldMailsCommand extends Command {
// Fetch all sys_file_reference records, with a relation to the mails we want to delete.
$sysFileReferencesToDelete = $fileReferenceQueryBuilder
->select('uid', 'uid_local')
->from(self::TABLE_NAME_FILE_REFERENCE)
->where(
$fileReferenceQueryBuilder->expr()->in(
'uid_foreign',
$fileReferenceQueryBuilder->createNamedParameter(
$mailUidsForDeletion,
Connection::PARAM_INT_ARRAY
)
),
$fileReferenceQueryBuilder->expr()->eq(
'tablenames',
$fileReferenceQueryBuilder->createNamedParameter(self::TABLE_NAME_MAIL, Connection::PARAM_STR)
),
$fileReferenceQueryBuilder->expr()->eq(
'fieldname',
$fileReferenceQueryBuilder->createNamedParameter('attachments', Connection::PARAM_STR)
),
)->execute()->fetchAll();
->from(self::TABLE_NAME_FILE_REFERENCE)->where($fileReferenceQueryBuilder->expr()->in(
'uid_foreign',
$fileReferenceQueryBuilder->createNamedParameter(
$mailUidsForDeletion,
ArrayParameterType::INTEGER
)
), $fileReferenceQueryBuilder->expr()->eq(
'tablenames',
$fileReferenceQueryBuilder->createNamedParameter(self::TABLE_NAME_MAIL, Connection::PARAM_STR)
), $fileReferenceQueryBuilder->expr()->eq(
'fieldname',
$fileReferenceQueryBuilder->createNamedParameter('attachments', Connection::PARAM_STR)
))->executeQuery()->fetchAllAssociative();
foreach ($sysFileReferencesToDelete as $sysFileReferenceToDelete) {
$sysFileReferenceUid = (int) $sysFileReferenceToDelete['uid'];
@@ -193,8 +187,7 @@ class DeleteOldMailsCommand extends Command {
// If we find more rows here, only the sys_file_reference record is deleted.
$countRefIndexEntries = $refIndexQueryBuilder
->count('*')
->from(self::TABLE_NAME_REFINDEX)
->where(
->from(self::TABLE_NAME_REFINDEX)->where(
$refIndexQueryBuilder->expr()->eq(
'ref_table',
$refIndexQueryBuilder->createNamedParameter(self::TABLE_NAME_FILE, Connection::PARAM_STR)
@@ -208,7 +201,7 @@ class DeleteOldMailsCommand extends Command {
'recuid',
$refIndexQueryBuilder->createNamedParameter($sysFileReferenceUid, Connection::PARAM_INT)
)
)->execute()->fetchOne();
)->executeQuery()->fetchOne();
if ($countRefIndexEntries <= 0) {
$referencedSysFile->delete();
@@ -222,16 +215,13 @@ class DeleteOldMailsCommand extends Command {
// delete the sys_file_reference
$this->amountOfDeletedRecords += $deleteFileReferenceQueryBuilder
->delete(self::TABLE_NAME_FILE_REFERENCE)
->where(
$deleteFileReferenceQueryBuilder->expr()->eq(
'uid',
$deleteFileReferenceQueryBuilder->createNamedParameter(
$sysFileReferenceUid,
Connection::PARAM_INT
)
->delete(self::TABLE_NAME_FILE_REFERENCE)->where($deleteFileReferenceQueryBuilder->expr()->eq(
'uid',
$deleteFileReferenceQueryBuilder->createNamedParameter(
$sysFileReferenceUid,
Connection::PARAM_INT
)
)->execute();
))->executeStatement();
}
}
}
Loading