eZ Publish  [4.2]
eZDBFileHandler Class Reference

List of all members.

Public Member Functions

 __get ($propertyName)
 Magic getter.
 abortCacheGeneration ()
 Aborts the current cache generation process.
 checkCacheGenerationTimeout ()
 Checks if the .generating file was changed, which would mean that generation timed out.
 deleteLocal ()
 Deletes a file that has been fetched before.
 endCacheGeneration ($rename=true)
 Ends the cache generation started by startCacheGeneration().
 exists ()
 Check if given file/dir exists.
 eZDBFileHandler ($filePath=false)
 Constructor.
 fetch ($noLocalCache=false)
 Fetches file from db and saves it in FS under the same name.
 fetchContents ()
 Returns file contents.
 fetchExpiredBinaryItems ($limit=array(0, 100))
 Fetches the first $limit expired binary items from the DB.
 fetchExpiredItems ($scopes, $limit=array(0, 100), $expiry=false)
 Fetches the first $limit expired files from the DB.
 fileStoreContents ($filePath, $contents, $scope=false, $datatype=false)
 Store file contents.
 getFileList ($scopes=false, $excludeScopes=false)
 Get list of files stored in database.
 isDBFileExpired ($expiry, $curtime, $ttl)
 Calculates if the DB file is expired or not.
 isExpired ($expiry, $curtime, $ttl)
 Calculates if the current file data is expired or not.
 isLocalFileExpired ($expiry, $curtime, $ttl)
 Calculates if the local file is expired or not.
 loadMetaData ($force=false)
 move ($dstPath)
 Move file.
 mtime ()
 Returns file modification time.
 name ()
 Returns file name.
 passthrough ()
 Outputs file contents prepending them with appropriate HTTP headers.
 processCache ($retrieveCallback, $generateCallback=null, $ttl=null, $expiry=null, $extraData=null)
 processFile ($callback, $expiry=false, $extraData=null)
 purge ($printCallback=false, $microsleep=false, $max=false, $expiry=false)
 requiresBinaryPurge ()
 eZDB does require binary purge.
 requiresClusterizing ()
 Since eZDB uses the database, running clusterize.php is required.
 requiresPurge ()
 eZDB does require binary purge.
 size ()
 Returns file size.
 startCacheGeneration ()
 Starts cache generation for the current file.
 stat ()
 Returns file metadata.
 storeContents ($contents, $scope=false, $datatype=false, $storeLocally=false)
 Store file contents.

Static Public Member Functions

static cleanPath ($path)
 Returns a clean version of input $path.
 delete ()
 Deletes specified file/directory.
 fetchUnique ()
 Fetches file from db and saves it in FS under unique name.
 fileCopy ($srcPath, $dstPath)
 Copy file.
 fileDelete ($path, $fnamePart=false)
 Deletes specified file/directory.
 fileDeleteByDirList ($dirList, $commonPath, $commonSuffix)
 fileDeleteByRegex ($dir, $fileRegex)
 fileDeleteByWildcard ($wildcard)
 fileDeleteLocal ($path)
 Deletes a file that has been fetched before.
 fileExists ($path)
 Check if given file/dir exists.
 fileFetch ($filePath)
 Fetches file from db and saves it in FS under the same name.
 fileFetchContents ($filePath)
 Returns file contents.
 fileLinkCopy ($srcPath, $dstPath, $symLink)
 Create symbolic or hard link to file.
 fileMove ($srcPath, $dstPath)
 Move file.
 fileStore ($filePath, $scope=false, $delete=false, $datatype=false)
static isFileExpired ($fname, $mtime, $expiry, $curtime, $ttl)
 Calculates if the file data is expired or not.

Public Attributes

 $backend
 $backendVerify
 $filePath
 $metaData = null
 holds the file's metaData loaded from database The variable's type indicates the exact status:
 $realFilePath = null
 holds the real file path.
const INFOCACHE_MAX = 200
const LOCAL_CACHE = 1

Private Member Functions

 _cacheType ()
 Determines the cache type based on the path.
 storeCache ($fileData)

Private Attributes

 $generationStartTimestamp = false
 $nonExistantStaleCacheHandling
 Holds the preferences used when stale cache is activated and no expired file is available.
 $remainingCacheGenerationTime = false
 $useStaleCache = false

Detailed Description

Definition at line 36 of file ezdbfilehandler.php.


Member Function Documentation

eZDBFileHandler::__get ( propertyName)

Magic getter.

Definition at line 1298 of file ezdbfilehandler.php.

eZDBFileHandler::_cacheType ( ) [private]

Determines the cache type based on the path.

Returns:
string viewcache, cacheblock or misc

Definition at line 1285 of file ezdbfilehandler.php.

Referenced by __get().

eZDBFileHandler::abortCacheGeneration ( )

Aborts the current cache generation process.

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

Definition at line 1263 of file ezdbfilehandler.php.

Referenced by storeCache().

eZDBFileHandler::checkCacheGenerationTimeout ( )

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

Definition at line 1276 of file ezdbfilehandler.php.

Referenced by storeCache().

static eZDBFileHandler::cleanPath ( path) [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 => my/windows/path
  • extra//slashes//fixed => extra/slashes/are/fixed
  • ending/slashes/ => ending/slashes

Definition at line 1195 of file ezdbfilehandler.php.

Referenced by eZDBFileHandler(), fileCopy(), fileDelete(), fileDeleteByDirList(), fileDeleteByRegex(), fileDeleteByWildcard(), fileDeleteLocal(), eZDFSFileHandler\fileDeleteLocal(), fileExists(), fileFetch(), fileFetchContents(), fileLinkCopy(), fileMove(), fileStore(), fileStoreContents(), and move().

eZDBFileHandler::delete ( ) [static]

Deletes specified file/directory.

If a directory specified it is deleted recursively.

Definition at line 970 of file ezdbfilehandler.php.

eZDBFileHandler::deleteLocal ( )

Deletes a file that has been fetched before.

Definition at line 1002 of file ezdbfilehandler.php.

eZDBFileHandler::endCacheGeneration ( rename = true)

Ends the cache generation started by startCacheGeneration().

Definition at line 1242 of file ezdbfilehandler.php.

Referenced by storeCache().

eZDBFileHandler::exists ( )

Check if given file/dir exists.

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

Definition at line 1066 of file ezdbfilehandler.php.

eZDBFileHandler::eZDBFileHandler ( filePath = false)

Constructor.

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

Definition at line 55 of file ezdbfilehandler.php.

eZDBFileHandler::fetch ( noLocalCache = false)

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

Definition at line 791 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::fetchContents ( )

Returns file contents.

Returns:
contents string, or false in case of an error.

Definition at line 830 of file ezdbfilehandler.php.

eZDBFileHandler::fetchExpiredBinaryItems ( limit = array( 0, 100 ))

Fetches the first $limit expired binary items from the DB.

Parameters:
array$limitA 2 items array( offset, limit )
Returns:
array(eZClusterFileHandlerInterace)
Since:
4.3.0
Deprecated:
Deprecated as of 4.5, use eZDBFileHandler::fetchExpiredItems() instead.
Todo:
handle output using $cli or something

Definition at line 1357 of file ezdbfilehandler.php.

eZDBFileHandler::fetchExpiredItems ( scopes,
limit = array( 0 , 100 ),
expiry = false 
)

Fetches the first $limit expired files from the DB.

Parameters:
array$scopesArray of scopes to fetch from
array$limitA 2 items array( offset, limit )
int$expiryNumber of seconds, only items older than this will be returned
Returns:
array(filepath)
Since:
4.5.0

Definition at line 1372 of file ezdbfilehandler.php.

eZDBFileHandler::fetchUnique ( ) [static]

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

Returns:
filename with path of a saved file. You can use this filename to get contents of file from filesystem.

Definition at line 776 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::fileCopy ( srcPath,
dstPath 
) [static]

Copy file.

Definition at line 1108 of file ezdbfilehandler.php.

eZDBFileHandler::fileDelete ( path,
fnamePart = false 
) [static]

Deletes specified file/directory.

If a directory specified it is deleted recursively.

Definition at line 947 of file ezdbfilehandler.php.

eZDBFileHandler::fileDeleteByDirList ( dirList,
commonPath,
commonSuffix 
) [static]

Definition at line 925 of file ezdbfilehandler.php.

eZDBFileHandler::fileDeleteByRegex ( dir,
fileRegex 
) [static]
See also:
fileDeleteByWildcard()

Definition at line 896 of file ezdbfilehandler.php.

eZDBFileHandler::fileDeleteByWildcard ( wildcard) [static]
See also:
fileDeleteByRegex()

Definition at line 912 of file ezdbfilehandler.php.

eZDBFileHandler::fileDeleteLocal ( path) [static]

Deletes a file that has been fetched before.

Definition at line 987 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::fileExists ( path) [static]

Check if given file/dir exists.

Definition at line 1049 of file ezdbfilehandler.php.

eZDBFileHandler::fileFetch ( filePath) [static]

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

Definition at line 212 of file ezdbfilehandler.php.

eZDBFileHandler::fileFetchContents ( filePath) [static]

Returns file contents.

Returns:
contents string, or false in case of an error.

Definition at line 815 of file ezdbfilehandler.php.

eZDBFileHandler::fileLinkCopy ( srcPath,
dstPath,
symLink 
) [static]

Create symbolic or hard link to file.

Definition at line 1123 of file ezdbfilehandler.php.

eZDBFileHandler::fileMove ( srcPath,
dstPath 
) [static]

Move file.

Definition at line 1138 of file ezdbfilehandler.php.

eZDBFileHandler::fileStore ( filePath,
scope = false,
delete = false,
datatype = false 
) [static]
Parameters:
$filePathPath to the file being stored.
$scopeMeans something like "file category". May be used to clean caches of a certain type.
$deletetrue if the file should be deleted after storing.

Definition at line 141 of file ezdbfilehandler.php.

eZDBFileHandler::fileStoreContents ( filePath,
contents,
scope = false,
datatype = false 
)

Store file contents.

Parameters:
string$filePath
mixed$contents
string$scope
string$datatype
Returns:
void

Definition at line 168 of file ezdbfilehandler.php.

eZDBFileHandler::getFileList ( scopes = false,
excludeScopes = false 
)

Get list of files stored in database.

Used in bin/php/clusterize.php.

Parameters:
array$scopesreturn only files that belong to any of these scopes
boolean$excludeScopesif true, then reverse the meaning of $scopes, which is return only files that do not belong to any of the scopes listed in $scopes

Definition at line 1175 of file ezdbfilehandler.php.

eZDBFileHandler::isDBFileExpired ( expiry,
curtime,
ttl 
)

Calculates if the DB file is expired or not.

Parameters:
int$expiryTime when file is to be expired, a value of -1 will disable this check.
int$curtimeThe current time to check against.
int$ttlNumber of seconds the data can live, set to null to disable TTL.
Returns:
bool

Definition at line 636 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::isExpired ( expiry,
curtime,
ttl 
)

Calculates if the current file data is expired or not.

Parameters:
int$expiryTime when file is to be expired, a value of -1 will disable this check.
int$curtimeThe current time to check against.
int$ttlNumber of seconds the data can live, set to null to disable TTL.
Returns:
bool

Definition at line 609 of file ezdbfilehandler.php.

static eZDBFileHandler::isFileExpired ( fname,
mtime,
expiry,
curtime,
ttl 
) [static]

Calculates if the file data is expired or not.

Parameters:
string$fnameName of file, available for easy debugging.
int$mtimeModification time of file, can be set to false if file does not exist.
int$expiryTime when file is to be expired, a value of -1 will disable this check.
int$curtimeThe current time to check against.
int$ttlNumber of seconds the data can live, set to null to disable TTL.
Returns:
bool

Definition at line 583 of file ezdbfilehandler.php.

Referenced by eZDBFileHandlerMysqlBackend\_verifyExclusiveLock(), isDBFileExpired(), isExpired(), and isLocalFileExpired().

eZDBFileHandler::isLocalFileExpired ( expiry,
curtime,
ttl 
)

Calculates if the local file is expired or not.

Parameters:
int$expiryTime when file is to be expired, a value of -1 will disable this check.
int$curtimeThe current time to check against.
int$ttlNumber of seconds the data can live, set to null to disable TTL.
Returns:
bool

Definition at line 624 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::loadMetaData ( force = false)

Load file meta information.

Parameters:
$forceFile stats will be refreshed if true

Definition at line 91 of file ezdbfilehandler.php.

Referenced by isExpired(), mtime(), passthrough(), processCache(), size(), and stat().

eZDBFileHandler::move ( dstPath)

Move file.

Definition at line 1154 of file ezdbfilehandler.php.

eZDBFileHandler::mtime ( )

Returns file modification time.

Definition at line 870 of file ezdbfilehandler.php.

eZDBFileHandler::name ( )

Returns file name.

Definition at line 884 of file ezdbfilehandler.php.

eZDBFileHandler::passthrough ( )

Outputs file contents prepending them with appropriate HTTP headers.

Deprecated:
This function should not be used since it cannot handle reading errors. For the PHP 5 port this should be removed.

Definition at line 1080 of file ezdbfilehandler.php.

eZDBFileHandler::processCache ( retrieveCallback,
generateCallback = null,
ttl = null,
expiry = null,
extraData = null 
)

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.

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.

The $generateCallback is 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. The function must return 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. Note: Set $generateCallback to false to disable generation callback. Note: Set $generateCallback 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().

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 convenience the $generateCallback function can return a string which will be considered as the binary data for the file and returned as the content.

For controlling how long a cache entry can be used the parameters $expiry and $ttl is used. $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.

$ttl (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.

Definition at line 265 of file ezdbfilehandler.php.

Referenced by processFile().

eZDBFileHandler::processFile ( callback,
expiry = false,
extraData = null 
)

Provides access to the file contents by downloading the file locally and calling $callback with the local filename. The callback can then process the contents and return the data in the same way as in processCache(). Downloading is only done once so the local copy is kept, while updates to the remote DB entry is synced with the local one.

The parameters $expiry and $extraData is the same as for processCache().

Note:
Unlike processCache() this returns null if the file cannot be accessed.

Definition at line 759 of file ezdbfilehandler.php.

eZDBFileHandler::purge ( printCallback = false,
microsleep = false,
max = false,
expiry = false 
)

Purge local and remote file data for current file.

Definition at line 1014 of file ezdbfilehandler.php.

eZDBFileHandler::requiresBinaryPurge ( )

eZDB does require binary purge.

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

Since:
4.3.0
Deprecated:
Deprecated as of 4.5, use eZDBFileHandler::requiresPurge() instead.
Returns:
bool

Definition at line 1329 of file ezdbfilehandler.php.

eZDBFileHandler::requiresClusterizing ( )

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

Returns:
bool

Definition at line 1316 of file ezdbfilehandler.php.

eZDBFileHandler::requiresPurge ( )

eZDB does require binary purge.

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

Since:
4.5.0
Returns:
bool

Definition at line 1341 of file ezdbfilehandler.php.

eZDBFileHandler::size ( )

Returns file size.

Definition at line 856 of file ezdbfilehandler.php.

eZDBFileHandler::startCacheGeneration ( )

Starts cache generation for the current file.

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

Returns:
bool false if the file is being generated, true if it is not

Definition at line 1212 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::stat ( )

Returns file metadata.

Definition at line 843 of file ezdbfilehandler.php.

eZDBFileHandler::storeCache ( fileData) [private]

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

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

Note:
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.

Definition at line 650 of file ezdbfilehandler.php.

Referenced by processCache().

eZDBFileHandler::storeContents ( contents,
scope = false,
datatype = false,
storeLocally = false 
)

Store file contents.

Parameters:
$storeLocallyIf true the file will also be stored on the local file system.

Definition at line 189 of file ezdbfilehandler.php.

Referenced by storeCache().


Member Data Documentation

eZDBFileHandler::$backend

Definition at line 1381 of file ezdbfilehandler.php.

eZDBFileHandler::$backendVerify

Definition at line 1388 of file ezdbfilehandler.php.

eZDBFileHandler::$generationStartTimestamp = false [private]

Definition at line 1444 of file ezdbfilehandler.php.

eZDBFileHandler::$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
    Todo:
    refactor to a magic property:

Definition at line 1416 of file ezdbfilehandler.php.

Referenced by fetch(), and loadMetaData().

eZDBFileHandler::$nonExistantStaleCacheHandling [private]

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

This is loaded from file.ini, ClusteringSettings.NonExistantStaleCacheHandling

Definition at line 1430 of file ezdbfilehandler.php.

eZDBFileHandler::$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

Definition at line 1401 of file ezdbfilehandler.php.

eZDBFileHandler::$remainingCacheGenerationTime = false [private]

Definition at line 1436 of file ezdbfilehandler.php.

eZDBFileHandler::$useStaleCache = false [private]

Definition at line 1423 of file ezdbfilehandler.php.

Controls the maximum number of metdata entries to keep in memory for this request. If the limit is reached the least used entries are removed.

Definition at line 48 of file ezdbfilehandler.php.

Controls whether file data from database is cached on the local filesystem.

Note:
This is primarily available for debugging purposes.

Definition at line 42 of file ezdbfilehandler.php.


The documentation for this class was generated from the following file: