Ejemplo n.º 1
0
 /**
  * Disconnects the cluster handler from the database
  */
 public function disconnect()
 {
     if (self::$dbbackend !== null) {
         self::$dbbackend->_disconnect();
         self::$dbbackend = null;
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * If provided with $filePath, will use this file for further operations.
  * If not given, the file* methods must be used instead
  *
  * @param string $filePath Path of the file to handle
  *
  * @throws eZDBNoConnectionException DB connection failed
  */
 function __construct($filePath = false)
 {
     if (self::$nonExistantStaleCacheHandling === null) {
         $fileINI = eZINI::instance('file.ini');
         self::$nonExistantStaleCacheHandling = $fileINI->variable("ClusteringSettings", "NonExistantStaleCacheHandling");
         unset($fileINI);
     }
     // DB Backend init
     if (self::$dbbackend === null) {
         self::$dbbackend = eZExtension::getHandlerClass(new ezpExtensionOptions(array('iniFile' => 'file.ini', 'iniSection' => 'eZDFSClusteringSettings', 'iniVariable' => 'DBBackend')));
         self::$dbbackend->_connect(false);
     }
     if ($filePath !== false) {
         $filePath = eZDBFileHandler::cleanPath($filePath);
         eZDebugSetting::writeDebug('kernel-clustering', "dfs::ctor( '{$filePath}' )");
     } else {
         eZDebugSetting::writeDebug('kernel-clustering', "dfs::ctor()");
     }
     $this->filePath = $filePath;
 }
<?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);
    /**
     * @param string $logoField
     * @return string
     */
    public function getFile( $logoField )
    {
        if( $this->attribute( $logoField ) != null && $this->attribute( $logoField ) != '' )
        {
            $storageDir = eZSys::storageDirectory();
            $clusterIdentifier = ClusterTool::clusterIdentifier();
            $publisherFolderPath = $this->publisherFolder['path'];

            $outputDirectory = "{$storageDir}/static-data/{$clusterIdentifier}/publisher_folders/{$publisherFolderPath}";
            if (!is_readable($outputDirectory) || !is_dir($outputDirectory))
            {
                mkdir($outputDirectory, 0777, true);
            }
            $outputFile =  "{$outputDirectory}/{$logoField}.png";

            $fileUtils = eZClusterFileHandler::instance( $outputFile );

            if( !$fileUtils->fileExists( $outputFile ) )
            {
                if ( $fileUtils->requiresClusterizing() )
                {
                    eZDFSFileHandler::fileStoreContents( $outputFile, $this->attribute( $logoField ) );
                }
                else
                {
                    file_put_contents( $outputFile, $this->attribute( $logoField ) );
                }
            }

            return '/' . $outputFile;
        }
        else
        {
            return null;
        }
    }
 public function testIsFileExpired()
 {
     $fname = __METHOD__;
     // Negative mtime: expired
     $mtime = -1;
     $expiry = -1;
     $curtime = time();
     $ttl = null;
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertTrue($result, "negative mtime: expired expected");
     // FALSE mtime: expired
     $mtime = false;
     $expiry = -1;
     $curtime = time();
     $ttl = null;
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertTrue($result, "false mtime: expired expected");
     // NULL TTL + mtime < expiry: expired
     $mtime = time() - 3600;
     // mtime < expiry
     $expiry = time();
     $curtime = time();
     $ttl = null;
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertTrue($result, "no TTL + mtime < expiry: expired expected");
     // NULL TTL + mtime > expiry: not expired
     $mtime = time();
     $expiry = time() - 3600;
     // expires in the future
     $curtime = time();
     $ttl = null;
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertFalse($result, "no TTL + mtime > expiry: not expired expected");
     // TTL != null, mtime < curtime - ttl: expired
     $mtime = time();
     $expiry = -1;
     // disable expiry check
     $curtime = time();
     $ttl = 60;
     // 60 seconds TTL
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertFalse($result, "TTL + ( mtime < ( curtime - ttl ) ): !expired expected");
     // TTL != null, mtime > curtime - ttl: not expired
     $mtime = time() - 90;
     // old file
     $expiry = -1;
     // disable expiry check
     $curtime = time();
     $ttl = 60;
     // 60 seconds TTL
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertTrue($result, "TTL + ( mtime > ( curtime - ttl ) ): expired expected");
     // TTL != null, mtime < expiry: expired
     $mtime = time() - 90;
     // old file
     $expiry = time();
     // file is expired
     $curtime = time();
     $ttl = 60;
     // 60 seconds TTL
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertTrue($result, "TTL + ( mtime < expiry ): expired expected");
     // TTL != null, mtime > expiry: not expired
     $mtime = time();
     $expiry = time() - 90;
     $curtime = time();
     $ttl = 60;
     $result = eZDFSFileHandler::isFileExpired($fname, $mtime, $expiry, $curtime, $ttl);
     $this->assertFalse($result, "TTL + ( mtime > expiry ): !expired expected");
 }