Commit 623411ac authored by Andreas Wolf's avatar Andreas Wolf

Merge branch 'issue-279' into 'develop'

Improve logging in scheduler tasks

See merge request !267
parents 8ac9370c 5a266c9a
Pipeline #2746 passed with stages
in 4 minutes and 42 seconds
......@@ -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,10 @@ class CheckForExpiredExtensions extends Task
*/
public function execute()
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$this->logger->info('Task CheckForExpiredExtensions started');
$this->blacklistUsers = [
'abandoned_extensions',
'typo3v4',
......@@ -47,6 +59,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;
......@@ -58,6 +72,8 @@ class CheckForExpiredExtensions extends Task
// remove expired extensions
$this->removeExpiredExtensions();
$this->logger->info('Task CheckForExpiredExtensions finished');
return true;
}
......@@ -129,9 +145,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 +178,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 +216,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 +243,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',
[
......
......@@ -15,7 +15,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\Extbase\Object\ObjectManager;
......@@ -70,6 +72,11 @@ class CheckForOutdatedExtensions extends Task
*/
protected $solrIndexQueue;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* Initialize Task
*
......@@ -95,6 +102,9 @@ class CheckForOutdatedExtensions extends Task
*/
public function execute()
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$this->logger->info('Task CheckForOutdatedExtensions started');
$this->initializeTask();
......@@ -110,6 +120,8 @@ class CheckForOutdatedExtensions extends Task
$this->checkVersion($version);
}
$this->logger->info('Task CheckForOutdatedExtensions finished');
return true;
}
......
......@@ -15,7 +15,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\Core\Utility\ExtensionManagementUtility;
......@@ -36,6 +38,12 @@ class ImportExtensionsFromQueueTask extends Task
*/
protected $pidExtensions = 2;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* executes the importer
*
......@@ -43,11 +51,15 @@ class ImportExtensionsFromQueueTask extends Task
*/
public function execute()
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$this->logger->info('Task ImportExtensionsFromQueueTask started');
$extensionsFromQueue = $this->getExtensionsFromQueue();
// finish task if no extensions in queue
if (empty($extensionsFromQueue)) {
GeneralUtility::sysLog('No new extensions in queue table', 'ter_fe2', 1);
$this->logger->info('No new extensions in queue table');
return true;
}
......@@ -57,11 +69,10 @@ class ImportExtensionsFromQueueTask extends Task
if (!$this->versionExists($extensionData)) {
$extUid = $this->extensionExists($extensionData);
$this->saveExtension($extUid, $extensionData, $ext['crdate']);
GeneralUtility::sysLog(
'Extension "' . $extensionData['extensionkey'] . '", version ' . $extensionData['version'] . ' saved in ter_fe2',
'ter_fe2',
1
);
$this->logger->info(sprintf(
'Extension "%s" version %s saved in ter_fe2',
$extensionData['extensionkey'], $extensionData['version']
));
// update the EXT:solr Index Queue
if (ExtensionManagementUtility::isLoaded('solr')) {
......@@ -69,14 +80,15 @@ class ImportExtensionsFromQueueTask extends Task
$indexQueue->updateItem('tx_terfe2_domain_model_extension', $extUid);
}
}
GeneralUtility::sysLog(
'Extension "' . $extensionData['extensionkey'] . '" still exists with version ' . $extensionData['version'] . ' in ter_fe2',
'ter_fe2',
1
);
$this->logger->info(sprintf(
'Extension "%s" still exists in ter_fe2 with version %s',
$extensionData['extensionkey'], $extensionData['version']
));
$this->removeExtensionFromQueue($ext['extensionuid']);
}
$this->logger->info('Task ImportExtensionsFromQueueTask finished');
return true;
}
......
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