kernel/classes/clusterfilehandlers/ezdbfilehandler.php

Show: inherited
Table of Contents

File containing the eZDBFileHandler class.

Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Package
kernel  
Version
4.6.0  

\eZDBFileHandler

Package: kernel

File containing the eZDBFileHandler class.

Parent(s)
\ezpDatabaseBasedClusterFileHandler
Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Version
4.6.0  

Constants

Constant  LOCAL_CACHE = 1
Constant  INFOCACHE_MAX = 200

Properties

Propertypublic  $_metaData= 'null'

holds the file's metaData loaded from database The variable's type indicates the exact status: - null: means that metaData have not been loaded yet - false: means that metaData were loaded but the file was not found in DB - array: metaData have been loaded and file exists

Default valuenullDetails
Type
n/a
Todo
refactor to a magic property: - when the property is requested, we check if it's null. - if it is, we load the metadata from the database and cache them - if it is not, we return the metaData - then we add a reinitMetaData() method that resets the property to null by erasing the cache  
Propertypublic\eZDBFileHandlerMysqlBackend  $dbbackend= ''
static

Database backend class

Propertypublicstring  $filePath= ''

Path to the current file

Details
Type
string
Propertyprotectedint  $generationStartTimestamp= 'false'

When the instance generates the cached version for a file, this property holds the timestamp at which generation was started. This is used to control a possible generation timeout

Default valuefalseDetails
Type
int
Propertyprotected  $nonExistantStaleCacheHandling= ''

Holds the preferences used when stale cache is activated and no expired file is available.

This is loaded from file.ini, ClusteringSettings.NonExistantStaleCacheHandling

Details
Type
n/a
Propertypublic  $realFilePath= 'null'

holds the real file path. This is only used when we are generating a cache file, in which case $filePath holds the generating cache file name, and $realFilePath holds the real name

Default valuenullDetails
Type
n/a
Propertyprotectedint  $remainingCacheGenerationTime= 'false'

Holds the number of seconds remaining before the generating cache times out

Default valuefalseDetails
Type
int
Propertyprotectedbool  $useStaleCache= 'false'

Indicates that the current cache item is being generated and an old version should be used

Default valuefalseDetails
Type
bool

Methods

methodpublic__construct(  $filePath = false ) : void

Constructor.

$filePath File path. If specified, file metadata is fetched in the constructor.

Parameters
Name Type Description
$filePath
methodpublic__get(  $propertyName ) : void

Magic getter

Parameters
Name Type Description
$propertyName
methodprotected_cacheType( ) : string

Determines the cache type based on the path

Returns
Type Description
string viewcache, cacheblock or misc
methodpublicabortCacheGeneration( ) : void

Aborts the current cache generation process.

Does so by rolling back the current transaction, which should be the .generating file lock

methodpubliccheckCacheGenerationTimeout( ) : void

Checks if the .generating file was changed, which would mean that generation timed out. If not timed out, refreshes the timestamp so that storage won't be stolen

methodpubliccleanPath(  $path ) : void
static

Returns a clean version of input $path.

  • Backslashes are turned into slashes.
  • Multiple consecutive slashes are turned into one slash.
  • Ending slashes are removed.

Examples: - my\windows\path => my/windows/path - extra//slashes/\are/fixed => extra/slashes/are/fixed - ending/slashes/ => ending/slashes

Parameters
Name Type Description
$path
methodpublicdelete( ) : void

Deletes specified file/directory.

If a directory specified it is deleted recursively.

\public \static

methodpublicdeleteLocal( ) : void

Deletes a file that has been fetched before.

\public

methodpublicdisconnect( ) : void

Disconnects the cluster handler from the database

methodpublicendCacheGeneration(  $rename = true ) : void

Ends the cache generation started by startCacheGeneration().

Parameters
Name Type Description
$rename
methodpublicexists( ) : void

Check if given file/dir exists.

NOTE: this function does not interact with database. Instead, it just returns existance status determined in the constructor.

\public

methodpublicfetch(  $noLocalCache = false ) : void

Fetches file from db and saves it in FS under the same name.

\public

Parameters
Name Type Description
$noLocalCache
methodpublicfetchContents( ) : void

Returns file contents.

\public \return contents string, or false in case of an error.

methodpublicfetchExpiredBinaryItems( array $limit = array( 0, 100 ) ) : \array(eZClusterFileHandlerInterace)

Fetches the first $limit expired binary items from the DB

Parameters
Name Type Description
$limit array

A 2 items array( offset, limit )

Returns
Type Description
\array(eZClusterFileHandlerInterace)
Details
Deprecated
Deprecated as of 4.5, use {@link eZDBFileHandler::fetchExpiredItems()} instead.  
Since
4.3.0  
Todo
handle output using $cli or something  
methodpublicfetchExpiredItems( array $scopes, array $limit = array( 0 , 100 ), int $expiry = false ) : \array(filepath)

Fetches the first $limit expired files from the DB

Parameters
Name Type Description
$scopes array

Array of scopes to fetch from

$limit array

A 2 items array( offset, limit )

$expiry int

Number of seconds, only items older than this will be returned

Returns
Type Description
\array(filepath)
Details
Since
4.5.0  
methodpublicfetchUnique( ) : string

Fetches file from db and saves it in FS under unique name.

Returns
Type Description
string filename with path of a saved file. You can use this filename to get contents of file from filesystem.
methodpublicfileCopy(  $srcPath,  $dstPath ) : void

Copy file.

\public \static

Parameters
Name Type Description
$srcPath
$dstPath
methodpublicfileDelete(  $path,  $fnamePart = false ) : void

Deletes specified file/directory.

If a directory specified it is deleted recursively.

\public \static

Parameters
Name Type Description
$path
$fnamePart
methodpublicfileDeleteByDirList(  $dirList,  $commonPath,  $commonSuffix ) : void

\public \static

Parameters
Name Type Description
$dirList
$commonPath
$commonSuffix
methodpublicfileDeleteByRegex(  $dir,  $fileRegex ) : void

\public \static \sa fileDeleteByWildcard()

Parameters
Name Type Description
$dir
$fileRegex
methodpublicfileDeleteByWildcard(  $wildcard ) : void

\public \static \sa fileDeleteByRegex()

Parameters
Name Type Description
$wildcard
methodpublicfileDeleteLocal(  $path ) : void

Deletes a file that has been fetched before.

\public \static

Parameters
Name Type Description
$path
methodpublicfileExists(  $path ) : void

Check if given file/dir exists.

\public \static

Parameters
Name Type Description
$path
methodpublicfileFetch(  $filePath ) : void

Fetches file from db and saves it in FS under the same name.

\public \static

Parameters
Name Type Description
$filePath
methodpublicfileFetchContents(  $filePath ) : void

Returns file contents.

\public \static \return contents string, or false in case of an error.

Parameters
Name Type Description
$filePath
methodpublicfileLinkCopy(  $srcPath,  $dstPath,  $symLink ) : void

Create symbolic or hard link to file.

\public \static

Parameters
Name Type Description
$srcPath
$dstPath
$symLink
methodpublicfileMove(  $srcPath,  $dstPath ) : void

Move file.

\public \static

Parameters
Name Type Description
$srcPath
$dstPath
methodpublicfileStore( string $filePath, string $scope = false, string $delete = false, string $datatype = false ) : void

Stores a local file to the cluster

Parameters
Name Type Description
$filePath string

Path to the file being stored.

$scope string

File scope. Used to group similar files together. Examples: image, template-block...

$delete string

true if the file should be deleted after storing.

$datatype string

File mime type

methodpublicfileStoreContents( string $filePath, mixed $contents, string $scope = false, string $datatype = false ) : void

Store file contents.

Parameters
Name Type Description
$filePath string
$contents mixed
$scope string
$datatype string
methodpublicgetFileList( array $scopes = false, boolean $excludeScopes = false ) : void

Get list of files stored in database.

Used in bin/php/clusterize.php.

Parameters
Name Type Description
$scopes array

return only files that belong to any of these scopes

$excludeScopes boolean

if true, then reverse the meaning of $scopes, which is return only files that do not belong to any of the scopes listed in $scopes

methodpublicisDBFileExpired( int $expiry, int $curtime, int $ttl ) : bool

Calculates if the DB file is expired or not.

Parameters
Name Type Description
$expiry int

Time when file is to be expired, a value of -1 will disable this check.

$curtime int

The current time to check against.

$ttl int

Number of seconds the data can live, set to null to disable TTL.

Returns
Type Description
bool
methodpublicisExpired( int $expiry, int $curtime, int $ttl ) : bool

Calculates if the current file data is expired or not.

Parameters
Name Type Description
$expiry int

Time when file is to be expired, a value of -1 will disable this check.

$curtime int

The current time to check against.

$ttl int

Number of seconds the data can live, set to null to disable TTL.

Returns
Type Description
bool
methodpublicisFileExpired( string $fname, int $mtime, int $expiry, int $curtime, int $ttl ) : bool
static

Calculates if the file data is expired or not.

Parameters
Name Type Description
$fname string

Name of file, available for easy debugging.

$mtime int

Modification time of file, can be set to false if file does not exist.

$expiry int

Time when file is to be expired, a value of -1 will disable this check.

$curtime int

The current time to check against.

$ttl int

Number of seconds the data can live, set to null to disable TTL.

Returns
Type Description
bool
methodpublicisLocalFileExpired( int $expiry, int $curtime, int $ttl ) : bool

Calculates if the local file is expired or not.

Parameters
Name Type Description
$expiry int

Time when file is to be expired, a value of -1 will disable this check.

$curtime int

The current time to check against.

$ttl int

Number of seconds the data can live, set to null to disable TTL.

Returns
Type Description
bool
methodpublicloadMetaData( bool $force = false ) : void

Load file meta information from the database

Parameters
Name Type Description
$force bool

File stats will be refreshed if true

methodpublicmove(  $dstPath ) : void

Move file.

\public

Parameters
Name Type Description
$dstPath
methodpublicmtime( ) : void

Returns file modification time.

\public

methodpublicname( ) : void

Returns file name.

\public

methodpublicpassthrough( int $offset = 0, int $length = false ) : void

Outputs file contents prepending them with appropriate HTTP headers.

Parameters
Name Type Description
$offset int

Transfer start offset

$length int

Transfer length

methodpublicprocessCache( mixed $retrieveCallback, mixed $generateCallback = null, mixed $ttl = null, mixed $expiry = null, mixed $extraData = null ) : array

Creates a single transaction out of the typical file operations for accessing caches.

Caches are normally ready from the database or local file, if the entry does not exist or is expired then it generates the new cache data and stores it. This method takes care of these operations and handles the custom code by performing callbacks when needed.

Either content or binarydata must be supplied, if not an error is issued and it returns null. If content is set it will be used as the return value of this function, if not it will return the binary data. If binarydata is set it will be used as the binary data for the file, if not it will perform a var_export on content and use that as the binary data.

For controlling how long a cache entry can be used the parameters $expiry and $ttl is used.

Parameters
Name Type Description
$retrieveCallback mixed

The $retrieveCallback is used when the file contents can be used (ie. not re-generation) and is called when the file is ready locally. The function will be called with the file path as the first parameter, the mtime as the second and optionally $extraData as the third. The function must return the file contents or an instance of eZClusterFileFailure which can be used to tell the system that the retrieve data cannot be used after all. $retrieveCallback can be set to null which makes the system go directly to the generation. Set to null to tell the function to perform a write lock but not do any generation, the generation must done be done by the caller by calling storeCache().

$generateCallback mixed

used when the file content is expired or does not exist, in this case the content must be re-generated and stored. The function will be called with the file path as the first parameter and optionally $extraData as the second. Set to false to disable generation callback. For convenience the $generateCallback function can return a string which will be considered as the binary data for the file and returned as the content.

$ttl mixed

(time to live) tells how many seconds the cache can live from the time it was stored. If the value is set to negative or null there is no limit for the lifetime of the cache. A value of 0 means that the cache will always expire and practically disables caching. For the cache to be used both the $expiry and $ttl check must hold.

$expiry mixed

$expiry can be set to a timestamp which controls the absolute max time for the cache, after this time/date the cache will never be used. If the value is set to a negative value or null there the expiration check is disabled.

$extraData mixed

Extra parameters to be sent to {@link $generateCallback} and {@link $retrieveCallback}

Returns
Type Description
array an array with information on the contents, the array consists of: - scope: The current scope of the file, is optional. - datatype: The current datatype of the file, is optional. - content: The file content, this can be any type except null. - binarydata: The binary data which is written to the file. - store: Whether *content* or *binarydata* should be stored to the file, if false it will simply return the data. Optional, by default it is true.
methodpublicprocessFile(  $callback,  $expiry = false,  $extraData = null ) : void

Parameters
Name Type Description
$callback
$expiry
$extraData
methodpublicpurge(  $printCallback = false,  $microsleep = false,  $max = false,  $expiry = false ) : void

Parameters
Name Type Description
$printCallback
$microsleep
$max
$expiry
methodpublicrequiresBinaryPurge( ) : bool

eZDB does require binary purge.

It does store files in DB and therefore doesn't remove files in real time

Returns
Type Description
bool
Details
Deprecated
Deprecated as of 4.5, use {@link eZDBFileHandler::requiresPurge()} instead.  
Since
4.3.0  
methodpublicrequiresClusterizing( ) : bool

Since eZDB uses the database, running clusterize.php is required

Returns
Type Description
bool
methodpublicrequiresPurge( ) : bool

eZDB does require binary purge.

It does store files in DB and therefore doesn't remove files in real time

Returns
Type Description
bool
Details
Since
4.5.0  
methodpublicsize( ) : void

Returns file size.

\public

methodpublicstartCacheGeneration( ) : bool

Starts cache generation for the current file.

This is done by creating a file named by the original file name, prefixed with '.generating'.

Returns
Type Description
bool false if the file is being generated, true if it is not
methodpublicstat( ) : void

Returns file metadata.

\public

methodpublicstoreCache(  $fileData ) : void

Stores the data in $fileData to the remote and local file and commits the transaction.

This method is just a continuation of the code in processCache() and is not meant to be called alone since it relies on specific state in the database.

The parameter $fileData must contain the same as information as the $generateCallback returns as explained in processCache().

Parameters
Name Type Description
$fileData
methodpublicstoreContents(  $contents,  $scope = false,  $datatype = false,  $storeLocally = false ) : void

Store file contents.

\public

\param $storeLocally If true the file will also be stored on the local file system.

Parameters
Name Type Description
$contents
$scope
$datatype
$storeLocally
Documentation was generated by DocBlox 0.18.1.