Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

adds command for clearing the processed files in typo3temp (DB and hd… #123

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions Classes/Command/CacheApiCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
* @author Stefano Kowalke <[email protected]>
* @package Etobi\CoreAPI\Service\SiteApiService
*/
class CacheApiCommandController extends CommandController {
class CacheApiCommandController extends CommandController
{
/**
* @var \TYPO3\CMS\Core\Log\LogManager $logManager
*/
Expand All @@ -49,14 +50,16 @@ class CacheApiCommandController extends CommandController {
*
* @return void
*/
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) {
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager)
{
$this->logManager = $logManager;
}

/**
* Initialize the object
*/
public function initializeObject() {
public function initializeObject()
{
$this->logger = $this->objectManager->get('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
}

Expand All @@ -70,7 +73,8 @@ public function initializeObject() {
*
* @param \Etobi\CoreAPI\Service\CacheApiService $cacheApiService
*/
public function injectCacheApiService(\Etobi\CoreAPI\Service\CacheApiService $cacheApiService) {
public function injectCacheApiService(\Etobi\CoreAPI\Service\CacheApiService $cacheApiService)
{
$this->cacheApiService = $cacheApiService;
}

Expand All @@ -81,7 +85,8 @@ public function injectCacheApiService(\Etobi\CoreAPI\Service\CacheApiService $ca
* @param boolean $hard
* @return void
*/
public function clearAllCachesCommand($hard = false) {
public function clearAllCachesCommand($hard = false)
{
$this->cacheApiService->clearAllCaches($hard);
$message = 'All caches have been cleared%s.';
$this->logger->info($message);
Expand All @@ -93,7 +98,8 @@ public function clearAllCachesCommand($hard = false) {
*
* @return void
*/
public function clearSystemCacheCommand() {
public function clearSystemCacheCommand()
{
$this->cacheApiService->clearSystemCache();
$message = 'System cache has been cleared';
$this->logger->info($message);
Expand All @@ -108,7 +114,8 @@ public function clearSystemCacheCommand() {
*
* @return void
*/
public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL) {
public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL)
{
$this->cacheApiService->clearAllActiveOpcodeCache($fileAbsPath);

if ($fileAbsPath !== NULL) {
Expand All @@ -127,7 +134,8 @@ public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL) {
*
* @return void
*/
public function clearConfigurationCacheCommand() {
public function clearConfigurationCacheCommand()
{
$this->cacheApiService->clearConfigurationCache();
$message = 'Configuration cache has been cleared.';
$this->logger->info($message);
Expand All @@ -139,7 +147,8 @@ public function clearConfigurationCacheCommand() {
*
* @return void
*/
public function clearPageCacheCommand() {
public function clearPageCacheCommand()
{
$this->cacheApiService->clearPageCache();
$message = 'Page cache has been cleared.';
$this->logger->info($message);
Expand Down Expand Up @@ -184,10 +193,31 @@ public function clearRealUrlCacheCommand()
*
* @return void
*/
public function clearAllExceptPageCacheCommand() {
public function clearAllExceptPageCacheCommand()
{
$clearedCaches = $this->cacheApiService->clearAllExceptPageCache();
$message = 'Cleared caches: ' . implode(', ', $clearedCaches);
$this->logger->info($message);
$this->outputLine($message);
}

/**
* Clear all processsed files (in DB and on disk)
* This is especially useful on big sites when you can't just drop the page cache.
*
* @return void
*/
public function clearProcessedFilesCommand()
{
if ($this->cacheApiService->clearProcessedFiles()) {
$message = 'Cleared processed files in typo3temp and fileadmin.';
$this->logger->info($message);
$this->outputLine($message);
} else {
$message = 'Clearing processed files failed.';
$this->logger->info($message);
$this->outputLine($message);
$this->quit(1);
};
}
}
52 changes: 39 additions & 13 deletions Classes/Service/CacheApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* @author Stefano Kowalke <[email protected]>
* @package Etobi\CoreAPI\Service\SiteApiService
*/
class CacheApiService {
class CacheApiService
{

/**
* @var \TYPO3\CMS\Core\DataHandling\DataHandler
Expand All @@ -57,7 +58,8 @@ class CacheApiService {
*
* @return void
*/
public function injectDataHandler(\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler) {
public function injectDataHandler(\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
{
$this->dataHandler = $dataHandler;
}

Expand All @@ -66,7 +68,8 @@ public function injectDataHandler(\TYPO3\CMS\Core\DataHandling\DataHandler $data
*
* @return void
*/
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) {
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}

Expand All @@ -75,7 +78,8 @@ public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $obj
*
* @return void
*/
public function injectInstallToolClearCacheService(\TYPO3\CMS\Install\Service\ClearCacheService $installToolClearCacheService) {
public function injectInstallToolClearCacheService(\TYPO3\CMS\Install\Service\ClearCacheService $installToolClearCacheService)
{
$this->installToolClearCacheService = $installToolClearCacheService;
}

Expand All @@ -84,7 +88,8 @@ public function injectInstallToolClearCacheService(\TYPO3\CMS\Install\Service\Cl
*
* @return void
*/
public function initializeObject() {
public function initializeObject()
{
// Create a fake admin user
$adminUser = $this->objectManager->get('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
$adminUser->user['uid'] = $GLOBALS['BE_USER']->user['uid'];
Expand All @@ -101,7 +106,8 @@ public function initializeObject() {
* @param bool $hard
* @return void
*/
public function clearAllCaches($hard = FALSE) {
public function clearAllCaches($hard = FALSE)
{
!$hard ? $this->dataHandler->clear_cacheCmd('all') : $this->installToolClearCacheService->clearAll();
}

Expand All @@ -110,13 +116,14 @@ public function clearAllCaches($hard = FALSE) {
*
* @return void
*/
public function clearPageCache() {
public function clearPageCache()
{
$this->dataHandler->clear_cacheCmd('pages');
}

/**
* Clear the page cache by tag.
* @param string $tag
*
* @return void
*/
public function clearPageCacheByTag($tag)
Expand All @@ -129,16 +136,19 @@ public function clearPageCacheByTag($tag)
*
* @return void
*/
public function clearConfigurationCache() {
public function clearConfigurationCache()
{
$this->dataHandler->clear_cacheCmd('temp_cached');
}


/**
* Clear the system cache
*
* @return void
*/
public function clearSystemCache() {
public function clearSystemCache()
{
$this->dataHandler->clear_cacheCmd('system');
}

Expand All @@ -150,7 +160,8 @@ public function clearSystemCache() {
*
* @return void
*/
public function clearAllActiveOpcodeCache($fileAbsPath = NULL) {
public function clearAllActiveOpcodeCache($fileAbsPath = NULL)
{
$this->clearAllActiveOpcodeCacheWrapper($fileAbsPath);
}

Expand All @@ -161,7 +172,8 @@ public function clearAllActiveOpcodeCache($fileAbsPath = NULL) {
*
* @return array with list of cleared caches
*/
public function clearAllExceptPageCache() {
public function clearAllExceptPageCache()
{
$out = array();
$cacheKeys = array_keys($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
$ignoredCaches = array('cache_pages', 'cache_pagesection');
Expand All @@ -181,6 +193,19 @@ public function clearAllExceptPageCache() {
return $toBeFlushed;
}

/**
* Clear processed files
* The sys_file_processedfile table is truncated and the physical files of local storages are deleted.
* @return \TYPO3\CMS\Install\Status\StatusInterface
*/
public function clearProcessedFiles()
{
$repository = $this->objectManager->get('\\TYPO3\\CMS\\Core\\Resource\\ProcessedFileRepository');
$failedDeletions = $repository->removeAll();
return $failedDeletions;

}

/**
* Clears the opcode cache. This just wraps the static call for testing purposes.
*
Expand All @@ -189,7 +214,8 @@ public function clearAllExceptPageCache() {
*
* @return void
*/
protected function clearAllActiveOpcodeCacheWrapper($fileAbsPath) {
protected function clearAllActiveOpcodeCacheWrapper($fileAbsPath)
{
\TYPO3\CMS\Core\Utility\OpcodeCacheUtility::clearAllActive($fileAbsPath);
}
}