Commit e7cce7f9 authored by Andreas Wolf's avatar Andreas Wolf

[TASK] #279: Add logging to CheckForExpiredExtensions

parent b0cc1775
......@@ -14,7 +14,9 @@ namespace T3o\TerFe2\Task;
* The TYPO3 project - inspiring people to share!
*/
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Extbase\Scheduler\Task;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
......@@ -32,6 +34,12 @@ class CheckForExpiredExtensions extends Task
*/
protected $blacklistUsers = [];
/**
* @var LoggerInterface
*/
protected $logger;
/**
* Execute Task
*
......@@ -39,6 +47,8 @@ class CheckForExpiredExtensions extends Task
*/
public function execute()
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$this->blacklistUsers = [
'abandoned_extensions',
'typo3v4',
......@@ -47,6 +57,8 @@ class CheckForExpiredExtensions extends Task
$expiredExtensionsByOwner = $this->getExpiredExtensionsByOwner();
$this->logger->info(sprintf('Found %d expired extensions', count($expiredExtensionsByOwner)));
foreach ($expiredExtensionsByOwner as $username => $extensions) {
if (in_array($username, $this->blacklistUsers, true)) {
continue;
......@@ -129,9 +141,16 @@ class CheckForExpiredExtensions extends Task
$mail->setSubject($subject);
$mail->setBody($body->render());
if ($mail->send()) {
$this->logger->info(sprintf(
'Sent email to user %s (%s)', $frontendUser['username'], $to
));
// set every extension of the owner to expire in 30 days
$this->updateExpirationTimeOfExtensions($extensions);
}
} else {
$this->logger->warning(sprintf(
'Could not find frontend user with username %s', $username
));
}
return $queryBuilder;
}
......@@ -155,6 +174,10 @@ class CheckForExpiredExtensions extends Task
'uid' => (int)$extension['uid']
]
);
$this->logger->info(
sprintf('Updated expiration time of extension %s (uid %d)', $extension['ext_key'], $extension['uid'])
);
}
}
......@@ -189,6 +212,11 @@ class CheckForExpiredExtensions extends Task
$queryBuilder->expr()->in('uid', $uidsToDelete)
);
$queryBuilder->execute()->execute();
$this->logger->info(sprintf(
'Deleted %d expired extensions (uids %s)',
count($uidsToDelete), implode(', ', $uidsToDelete)
));
}
}
......@@ -211,6 +239,7 @@ class CheckForExpiredExtensions extends Task
);
if (!$versionCount || $versionCount === 0) {
$this->logger->info(sprintf('Deleted extension key %s as it did not have versions.', $extensionKey));
return $extensionsConnection->delete(
'tx_ter_extensionkeys',
[
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment