Ejemplo n.º 1
0
 /**
  * Clears view cache for imported content objects.
  * ObjectIDs are stored in 'ezpending_actions' table, with {@link SQLIContent::ACTION_CLEAR_CACHE} action
  */
 public static function viewCacheClear()
 {
     $db = eZDB::instance();
     $isCli = isset($_SERVER['argv']);
     $output = null;
     $progressBar = null;
     $i = 0;
     $conds = array('action' => SQLIContent::ACTION_CLEAR_CACHE);
     $limit = array('offset' => 0, 'length' => 50);
     $count = (int) eZPersistentObject::count(eZPendingActions::definition(), $conds);
     if ($isCli && $count > 0) {
         // 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) {
             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();
         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();
         }
     } while ($i < $count);
     if ($isCli && $count > 0) {
         $progressBar->finish();
         $output->outputLine();
     }
 }