From 618c708d2d43a1440690b10d63c93280ae8eb1b9 Mon Sep 17 00:00:00 2001 From: Luca Realdi Date: Tue, 20 Feb 2018 18:26:05 +0100 Subject: [PATCH] Add CacheThreshold limit in cleanup script --- classes/sqliimportutils.php | 105 ++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 45 deletions(-) diff --git a/classes/sqliimportutils.php b/classes/sqliimportutils.php index 662119b..3ee0362 100755 --- a/classes/sqliimportutils.php +++ b/classes/sqliimportutils.php @@ -233,61 +233,76 @@ public static function viewCacheClear() 'length' => 50 ); $count = (int)eZPersistentObject::count( eZPendingActions::definition(), $conds ); - - if( $isCli && $count > 0 ) + + if( eZContentCache::inCleanupThresholdRange( $count ) ) { - // Progress bar implementation - $output = new ezcConsoleOutput(); - $output->outputLine( 'Starting to clear view cache for imported objects...' ); - $progressBarOptions = array( - 'emptyChar' => ' ', - 'barChar' => '=' - ); - $progressBar = new ezcConsoleProgressbar( $output, $count, $progressBarOptions ); - $progressBar->start(); - } - /* - * To avoid fatal errors due to memory exhaustion, pending actions are fetched by packets - */ - do - { - $aObjectsToClear = eZPendingActions::fetchObjectList( eZPendingActions::definition(), null, $conds, null, $limit ); - $jMax = count( $aObjectsToClear ); - if( $jMax > 0 ) + if( $isCli && $count > 0 ) { - for( $j=0; $j<$jMax; ++$j ) + // Progress bar implementation + $output = new ezcConsoleOutput(); + $output->outputLine( 'Starting to clear view cache for imported objects...' ); + $progressBarOptions = array( + 'emptyChar' => ' ', + 'barChar' => '=' + ); + $progressBar = new ezcConsoleProgressbar( $output, $count, $progressBarOptions ); + $progressBar->start(); + } + + /* + * To avoid fatal errors due to memory exhaustion, pending actions are fetched by packets + */ + do + { + $aObjectsToClear = eZPendingActions::fetchObjectList( eZPendingActions::definition(), null, $conds, null, $limit ); + $jMax = count( $aObjectsToClear ); + if( $jMax > 0 ) { - if( $isCli ) - $progressBar->advance(); - - $db->begin(); - eZContentCacheManager::clearContentCacheIfNeeded( (int)$aObjectsToClear[$j]->attribute( 'param' ) ); - $aObjectsToClear[$j]->remove(); - $db->commit(); - $i++; + for( $j=0; $j<$jMax; ++$j ) + { + if( $isCli ) + $progressBar->advance(); + + $db->begin(); + eZContentCacheManager::clearContentCacheIfNeeded( (int)$aObjectsToClear[$j]->attribute( 'param' ) ); + $aObjectsToClear[$j]->remove(); + $db->commit(); + $i++; + } } - } - unset( $aObjectsToClear ); - eZContentObject::clearCache(); + unset( $aObjectsToClear ); + eZContentObject::clearCache(); - if ( eZINI::instance( 'site.ini' )->variable( 'ContentSettings', 'StaticCache' ) == 'enabled' ) - { - $optionArray = array( 'iniFile' => 'site.ini', - 'iniSection' => 'ContentSettings', - 'iniVariable' => 'StaticCacheHandler' ); + if ( eZINI::instance( 'site.ini' )->variable( 'ContentSettings', 'StaticCache' ) == 'enabled' ) + { + $optionArray = array( 'iniFile' => 'site.ini', + 'iniSection' => 'ContentSettings', + 'iniVariable' => 'StaticCacheHandler' ); - $options = new ezpExtensionOptions( $optionArray ); - $staticCacheHandler = eZExtension::getHandlerClass( $options ); - $staticCacheHandler::executeActions(); + $options = new ezpExtensionOptions( $optionArray ); + $staticCacheHandler = eZExtension::getHandlerClass( $options ); + $staticCacheHandler::executeActions(); + } + } + while( $i < $count ); + + if( $isCli && $count > 0 ) + { + $progressBar->finish(); + $output->outputLine(); } } - while( $i < $count ); - - if( $isCli && $count > 0 ) + else { - $progressBar->finish(); - $output->outputLine(); + if( $isCli ) + { + $output = new ezcConsoleOutput(); + $output->outputLine( "Expiring all view cache since list of nodes({$count}) exceeds site.ini\[ContentSettings]\CacheThreshold" ); + } + ezpEvent::getInstance()->notify( 'content/cache/all' ); + eZContentObject::expireAllViewCache(); + eZPendingActions::removeByAction(SQLIContent::ACTION_CLEAR_CACHE); } }