Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CacheThreshold limit in cleanup script #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
105 changes: 60 additions & 45 deletions classes/sqliimportutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down