Index: kernel/classes/clusterfilehandlers/dbbackends/mysql.php
===================================================================
--- kernel/classes/clusterfilehandlers/dbbackends/mysql.php	(revision 25362)
+++ kernel/classes/clusterfilehandlers/dbbackends/mysql.php	(working copy)
@@ -1665,22 +1665,27 @@
     }
 
     /**
-     * Returns the list of expired binary files (images + binaries)
+     * Returns the list of expired files
      *
      * @param array $scopes Array of scopes to consider. At least one.
      * @param int $limit Max number of items. Set to false for unlimited.
+     * @param int $expiry Number of seconds, only items older than this will be returned
      *
      * @return array(filepath)
      *
      * @since 4.3
      */
-    public function expiredFilesList( $scopes, $limit = array( 0, 100 ) )
+    public function expiredFilesList( $scopes, $limit = array( 0, 100 ), $expiry = false )
     {
         if ( count( $scopes ) == 0 )
             throw new ezcBaseValueException( 'scopes', $scopes, "array of scopes", "parameter" );
 
         $scopeString = $this->_sqlList( $scopes );
         $query = "SELECT name FROM " . TABLE_METADATA . " WHERE expired = 1 AND scope IN( $scopeString )";
+        if ( $expiry !== false )
+        {
+            $query .= ' AND expired < ' . (time() - $expiry);
+        }
         if ( $limit !== false )
         {
             $query .= " LIMIT {$limit[0]}, {$limit[1]}";
Index: kernel/classes/clusterfilehandlers/ezdbfilehandler.php
===================================================================
--- kernel/classes/clusterfilehandlers/ezdbfilehandler.php	(revision 25362)
+++ kernel/classes/clusterfilehandlers/ezdbfilehandler.php	(working copy)
@@ -1333,6 +1333,21 @@
     }
 
     /**
+     * Fetches the first $limit expired files from the DB
+     *
+     * @param array $scopes Array of scopes to fetch from
+     * @param array $limit A 2 items array( offset, limit )
+     * @param int $expiry Number of seconds, only items older than this will be returned
+     *
+     * @return array(filepath)
+     * @since 4.4.0
+     */
+    public function fetchExpiredItems( $scopes, $limit = array( 0 , 100 ), $expiry = false )
+    {
+        return $this->backend->expiredFilesList( $scopes, $limit, $expiry );
+    }
+
+    /**
     * Database backend class
     * @var eZDBFileHandlerMysqlBackend
     **/
Index: kernel/private/classes/ezscriptclusterpurge.php
===================================================================
--- kernel/private/classes/ezscriptclusterpurge.php	(revision 25362)
+++ kernel/private/classes/ezscriptclusterpurge.php	(working copy)
@@ -15,6 +15,8 @@
  * @property int optIterationLimit
  * @property int optIterationSleep
  * @property bool optMemoryMonitoring
+ * @property array(string) optScopes
+ * @property int optExpiry
  */
 class eZScriptClusterPurge
 {
@@ -25,6 +27,8 @@
             'iteration-sleep' => 1,
             'iteration-limit' => 100,
             'memory-monitoring' => false,
+            'scopes' => false,
+            'expiry' => 2592000 // 60*60*24*30 = 30 days
         );
     }
 
@@ -65,13 +69,15 @@
 
         $limit = array( 0, $this->optIterationLimit );
 
-        $cli->output( "Purging expired binary items:" );
+        $cli->output( "Purging expired items:" );
 
         self::monitor( "start" );
 
         // Fetch a limited list of purge items from the handler itself
         $clusterHandler = eZClusterFileHandler::instance();
-        while ( $filesList = $clusterHandler->fetchExpiredBinaryItems( $limit ) )
+        while ( $filesList = ( $this->optScopes === false ?
+                               $clusterHandler->fetchExpiredBinaryItems( $limit ) :
+                               $clusterHandler->fetchExpiredItems( $this->optScopes, $limit, $this->optExpiry ) ) )
         {
             self::monitor( "iteration start" );
             foreach( $filesList as $file )
@@ -127,6 +133,16 @@
             {
                 return $this->options['memory-monitoring'];
             } break;
+
+            case 'optScopes':
+            {
+                return $this->options['scopes'];
+            } break;
+
+            case 'optExpiry':
+            {
+                return $this->options['expiry'];
+            } break;
         }
     }
 
@@ -156,6 +172,16 @@
             {
                 $this->options['memory-monitoring'] = $propertyValue;
             } break;
+
+            case 'optScopes':
+            {
+                $this->options['scopes'] = $propertyValue;
+            } break;
+
+            case 'optExpiry':
+            {
+                $this->options['expiry'] = $propertyValue;
+            } break;
         }
     }
 
@@ -169,6 +195,6 @@
 
     private $options = array();
 
-    const LOG_FILE = 'clusterbinarypurge.log';
+    const LOG_FILE = 'clusterpurge.log';
 }
 ?>
Index: kernel/private/classes/clusterfilehandlers/ezdfsfilehandler.php
===================================================================
--- kernel/private/classes/clusterfilehandlers/ezdfsfilehandler.php	(revision 25362)
+++ kernel/private/classes/clusterfilehandlers/ezdfsfilehandler.php	(working copy)
@@ -1424,6 +1424,21 @@
     }
 
     /**
+     * Fetches the first $limit expired files from the DB
+     *
+     * @param array $scopes Array of scopes to fetch from
+     * @param array $limit A 2 items array( offset, limit )
+     * @param int $expiry Number of seconds, only items older than this will be returned
+     *
+     * @return array(filepath)
+     * @since 4.4.0
+     */
+    public function fetchExpiredItems( $scopes, $limit = array( 0 , 100 ), $expiry = false )
+    {
+        return self::$dbbackend->expiredFilesList( $scopes, $limit, $expiry );
+    }
+
+    /**
      * Database backend class
      * Provides metadata operations
      * @var eZDFSFileHandlerMySQLBackend
Index: kernel/private/classes/clusterfilehandlers/dfsbackends/mysql.php
===================================================================
--- kernel/private/classes/clusterfilehandlers/dfsbackends/mysql.php	(revision 25362)
+++ kernel/private/classes/clusterfilehandlers/dfsbackends/mysql.php	(working copy)
@@ -1648,21 +1648,26 @@
 
     /**
      * Returns the list of expired files
-     * 
+     *
      * @param array $scopes Array of scopes to consider. At least one.
      * @param int $limit Max number of items. Set to false for unlimited.
+     * @param int $expiry Number of seconds, only items older than this will be returned
      *
      * @return array(filepath)
      *
      * @since 4.3
      */
-    public function expiredFilesList( $scopes, $limit = array( 0, 100 ) )
+    public function expiredFilesList( $scopes, $limit = array( 0, 100 ), $expiry = false )
     {
         if ( count( $scopes ) == 0 )
             throw new ezcBaseValueException( 'scopes', $scopes, "array of scopes", "parameter" );
 
         $scopeString = $this->_sqlList( $scopes );
         $query = "SELECT name FROM " . self::TABLE_METADATA . " WHERE expired = 1 AND scope IN( $scopeString )";
+        if ( $expiry !== false )
+        {
+            $query .= ' AND expired < ' . (time() - $expiry);
+        }
         if ( $limit !== false )
         {
             $query .= " LIMIT {$limit[0]}, {$limit[1]}";
Index: bin/php/clustercachepurge.php
===================================================================
--- bin/php/clustercachepurge.php	(revision 0)
+++ bin/php/clustercachepurge.php	(revision 0)
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Cluster cache files purge script
+ *
+ * @copyright Copyright (C) 1999-2010 eZ Systems AS. All rights reserved.
+ * @license http://ez.no/licenses/gnu_gpl GNU GPLv2
+ */
+
+require 'autoload.php';
+
+$cli = eZCLI::instance();
+$script = eZScript::instance( array( 'description' => ( "eZ Publish cache files purge\n" .
+                                                        "Physically purges expired cache files\n" .
+                                                        "\n" .
+                                                        "./bin/php/clustercachepurge.php --scopes=scope1,scope2" ),
+                                     'use-session' => false,
+                                     'use-modules' => false,
+                                     'use-extensions' => true ) );
+
+$script->startup();
+
+$options = $script->getOptions( "[dry-run][iteration-sleep:][iteration-limit:][memory-monitoring][scopes:][expiry:]",
+"",
+array( 'dry-run' => 'Test mode, output the list of affected files without removing them',
+       'iteration-sleep' => 'Amount of seconds to sleep between each iteration when performing a purge operation, can be a float. Default is one second.',
+       'iteration-limit' => 'Amount of items to remove in each iteration when performing a purge operation. Default is 100.',
+       'memory-monitoring' => 'If set, memory usage will be logged in var/log/clustercachepurge.log.',
+       'scopes' => 'Comma separated list of cache types to purge. Possible values are: classattridentifiers, classidentifiers, content, expirycache, statelimitations, template-block, user-info-cache, viewcache, wildcard-cache-index',
+       'expiry' => 'Number of days since the file was expired. Only files older than this will be purged. Default is 30, minimum is 1.' ) );
+$sys = eZSys::instance();
+
+$script->initialize();
+
+if ( !eZScriptClusterPurge::isRequired() )
+{
+    $cli->error( "Your current cluster handler does not require cache purge" );
+    $script->shutdown( 1 );
+}
+
+$purgeHandler = new eZScriptClusterPurge();
+if ( $options['dry-run'] )
+{
+    $purgeHandler->optDryRun = true;
+}
+
+if ( $options['iteration-sleep'] )
+{
+    $purgeHandler->optIterationSleep = (int)( $options['iteration-sleep'] * 1000000 );
+}
+
+if ( $options['iteration-limit'] )
+{
+    $purgeHandler->optIterationLimit = (int)$options['iteration-limit'];
+}
+
+if ( $options['memory-monitoring'] )
+{
+    $purgeHandler->optMemoryMonitoring = true;
+}
+
+if ( $options['scopes'] )
+{
+    $purgeHandler->optScopes = explode( ',', $options['scopes'] );
+}
+
+if ( $options['expiry'] )
+{
+    $purgeHandler->optExpiry = (int)$options['expiry'] * 86400; // 60*60*24
+}
+
+$purgeHandler->run();
+
+$script->shutdown();
+
+?>

Property changes on: bin/php/clustercachepurge.php
___________________________________________________________________
Added: svn:eol-style
   + native

Index: cronjobs/clustercachepurge.php
===================================================================
--- cronjobs/clustercachepurge.php	(revision 0)
+++ cronjobs/clustercachepurge.php	(revision 0)
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Cluster cache files purge cronjob
+ *
+ * @copyright Copyright (C) 1999-2010 eZ Systems AS. All rights reserved.
+ * @license http://ez.no/licenses/gnu_gpl GNU GPLv2
+ */
+
+if ( !eZScriptClusterPurge::isRequired() )
+{
+    $cli->error( "Your current cluster handler does not require cache purge" );
+    $script->shutdown( 1 );
+}
+
+$purgeHandler = new eZScriptClusterPurge();
+$purgeHandler->optScopes = array( 'classattridentifiers',
+                                  'classidentifiers',
+                                  'content',
+                                  'expirycache',
+                                  'statelimitations',
+                                  'template-block',
+                                  'user-info-cache',
+                                  'viewcache',
+                                  'wildcard-cache-index' );
+$purgeHandler->optExpiry = 30;
+$purgeHandler->run();
+
+?>

Property changes on: cronjobs/clustercachepurge.php
___________________________________________________________________
Added: svn:eol-style
   + native

