* * @copyright Copyright (C) eZ Systems AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// */ require_once 'autoload.php'; $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => "Deletes cache records from the DFS storage table.\n" . "Can be used on a live site to cleanup cache leftovers in ezdfsfile.", 'use-session' => true, 'use-modules' => false, 'use-extensions' => true)); $script->startup(); $options = $script->getOptions("[iteration-sleep:][iteration-limit:]", "", array('iteration-sleep' => 'Sleep duration between batches, in milliseconds (default: 100)', 'iteration-limit' => 'Batch size (default: 1000)')); $optIterationSleep = (int) $options['iteration-sleep'] ?: 100; $optIterationLimit = (int) $options['iteration-limit'] ?: 1000; $script->initialize(); $mysqliDFSBackend = new eZDFSFileHandlerMySQLiBackend(); try { $mysqliDFSBackend->_connect(); } catch (eZClusterHandlerDBNoConnectionException $e) { $script->shutdown(2, "Unable to connect to the cluster database. Is this instance configured to use the feature ?"); } $clusterHandler = eZClusterFileHandler::instance(); try { while ($deletedCount = $mysqliDFSBackend->deleteCacheFiles($optIterationLimit)) { $cli->output("Deleted {$deletedCount} cache record(s)"); usleep($optIterationSleep * 1000); } } catch (InvalidArgumentException $e) { $script->shutdown(0, "The cache and storage tables are identical, nothing to do"); } catch (RuntimeException $e) { $script->shutdown(1, "A database error occured:\n" . $e->getMessage()); } $cli->output("Done");
<?php $dbHandler = new eZDFSFileHandlerMySQLiBackend(); $dbHandler->_connect(); /* @type $db mysqli */ $db = $dbHandler->db; $limit = 100; $offset = 0; $count = 0; do { $query = "SELECT name FROM ezdfsfile WHERE scope = 'template-block' AND mtime > 0 AND mtime < (UNIX_TIMESTAMP(NOW()) - 3600 * 24 * 2) LIMIT {$offset}, {$limit}"; $result = $db->query($query); $count = $result->num_rows; while ($row = $result->fetch_assoc()) { $name = $row['name']; $fileHandler = new eZDFSFileHandler($name); $fileHandler->purge(); } $offset += $limit; } while($count > 0);
public static function cssPackCacheCleanUp( $cacheIdentifier ) { $versionsToKeep = eZINI::instance( 'kless.ini' )->variable( 'KLessSettings', 'KeepPackedCssVersionNumber' ); if ( $versionsToKeep <= 0 ) { return; } $clusterFileHandler = eZClusterFileHandler::instance(); /* Sic.... */ switch( get_class($clusterFileHandler) ) { case 'eZFSFileHandler': case 'eZFS2FileHandler': $files = glob( self::cssPackedFilesDirectory() . '/k' . $cacheIdentifier . '*' ); sort( $files ); foreach( array_slice( $files, 0, count($files) - 1 - $versionsToKeep ) as $cssPackFile ) { $clusterFile = eZClusterFileHandler::instance( $cssPackFile ); $clusterFile->purge(); } break; case 'eZDFSFileHandler': $dfsDBHandler = new eZDFSFileHandlerMySQLiBackend(); $dfsDBHandler->_connect(); $db = $dfsDBHandler->db; $query = sprintf( "SELECT name FROM ezdfsfile WHERE scope = 'klesspack' AND name LIKE '%s' SORT BY mtime DESC", mysqli_escape_string( $db, self::cssPackedFilesDirectory() . '/k' . $cacheIdentifier . '%' ) ); $result = mysqli_query($db, $query); $inc = 0; while ( $row = mysqli_fetch_assoc($result) ) { if ( ++$inc < $versionsToKeep ) { continue; } $clusterFile = eZClusterFileHandler::instance( $row['name'] ); $clusterFile->purge(); } break; default: throw new Exception('Not implemented'); } }