kernel/classes/clusterfilehandlers/ezdbfilehandler.php
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
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
Properties


$_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
null
Details- 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


int
$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
false
Details- Type
- int


$nonExistantStaleCacheHandling= ''
Holds the preferences used when stale cache is activated and no expired file is available.
This is loaded from file.ini, ClusteringSettings.NonExistantStaleCacheHandling
- Type
- n/a


$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
null
Details- Type
- n/a


int
$remainingCacheGenerationTime= 'false'
Holds the number of seconds remaining before the generating cache times out
false
Details- Type
- int
Methods


__construct(
$filePath
=
false
)
:
void
Constructor.
$filePath File path. If specified, file metadata is fetched in the constructor.
Name | Type | Description |
---|---|---|
$filePath |


_cacheType(
)
:
string
Determines the cache type based on the path
Type | Description |
---|---|
string | viewcache, cacheblock or misc |


abortCacheGeneration(
)
:
void
Aborts the current cache generation process.
Does so by rolling back the current transaction, which should be the .generating file lock


checkCacheGenerationTimeout(
)
:
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


cleanPath(
$path
)
:
void
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
Name | Type | Description |
---|---|---|
$path |


delete(
)
:
void
Deletes specified file/directory.
If a directory specified it is deleted recursively.
\public \static


endCacheGeneration(
$rename
=
true
)
:
void
Ends the cache generation started by startCacheGeneration().
Name | Type | Description |
---|---|---|
$rename |


exists(
)
:
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


fetch(
$noLocalCache
=
false
)
:
void
Fetches file from db and saves it in FS under the same name.
\public
Name | Type | Description |
---|---|---|
$noLocalCache |


fetchContents(
)
:
void
Returns file contents.
\public \return contents string, or false in case of an error.


fetchExpiredBinaryItems(
array $limit
=
array( 0, 100 )
)
:
\array(eZClusterFileHandlerInterace)
Fetches the first $limit expired binary items from the DB
Name | Type | Description |
---|---|---|
$limit | array | A 2 items array( offset, limit ) |
Type | Description |
---|---|
\array(eZClusterFileHandlerInterace) |
- Deprecated
- Deprecated as of 4.5, use {@link eZDBFileHandler::fetchExpiredItems()} instead.
- Since
- 4.3.0
- Todo
- handle output using $cli or something


fetchExpiredItems(
array $scopes, array $limit
=
array( 0 , 100 ), int $expiry
=
false
)
:
\array(filepath)
Fetches the first $limit expired files from the DB
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 |
Type | Description |
---|---|
\array(filepath) |
- Since
- 4.5.0


fetchUnique(
)
:
string
Fetches file from db and saves it in FS under unique name.
Type | Description |
---|---|
string | filename with path of a saved file. You can use this filename to get contents of file from filesystem. |


fileCopy(
$srcPath, $dstPath
)
:
void
Copy file.
\public \static
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath |


fileDelete(
$path, $fnamePart
=
false
)
:
void
Deletes specified file/directory.
If a directory specified it is deleted recursively.
\public \static
Name | Type | Description |
---|---|---|
$path | ||
$fnamePart |


fileDeleteByDirList(
$dirList, $commonPath, $commonSuffix
)
:
void
\public \static
Name | Type | Description |
---|---|---|
$dirList | ||
$commonPath | ||
$commonSuffix |


fileDeleteByRegex(
$dir, $fileRegex
)
:
void
\public \static \sa fileDeleteByWildcard()
Name | Type | Description |
---|---|---|
$dir | ||
$fileRegex |


fileDeleteByWildcard(
$wildcard
)
:
void
\public \static \sa fileDeleteByRegex()
Name | Type | Description |
---|---|---|
$wildcard |


fileDeleteLocal(
$path
)
:
void
Deletes a file that has been fetched before.
\public \static
Name | Type | Description |
---|---|---|
$path |


fileExists(
$path
)
:
void
Check if given file/dir exists.
\public \static
Name | Type | Description |
---|---|---|
$path |


fileFetch(
$filePath
)
:
void
Fetches file from db and saves it in FS under the same name.
\public \static
Name | Type | Description |
---|---|---|
$filePath |


fileFetchContents(
$filePath
)
:
void
Returns file contents.
\public \static \return contents string, or false in case of an error.
Name | Type | Description |
---|---|---|
$filePath |


fileLinkCopy(
$srcPath, $dstPath, $symLink
)
:
void
Create symbolic or hard link to file.
\public \static
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath | ||
$symLink |


fileMove(
$srcPath, $dstPath
)
:
void
Move file.
\public \static
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath |


fileStore(
string $filePath, string $scope
=
false, string $delete
=
false, string $datatype
=
false
)
:
void
Stores a local file to the cluster
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 |


fileStoreContents(
string $filePath, mixed $contents, string $scope
=
false, string $datatype
=
false
)
:
void
Store file contents.
Name | Type | Description |
---|---|---|
$filePath | string | |
$contents | mixed | |
$scope | string | |
$datatype | string |


getFileList(
array $scopes
=
false, boolean $excludeScopes
=
false
)
:
void
Get list of files stored in database.
Used in bin/php/clusterize.php.
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 |


isDBFileExpired(
int $expiry, int $curtime, int $ttl
)
:
bool
Calculates if the DB file is expired or not.
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. |
Type | Description |
---|---|
bool |


isExpired(
int $expiry, int $curtime, int $ttl
)
:
bool
Calculates if the current file data is expired or not.
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. |
Type | Description |
---|---|
bool |


isFileExpired(
string $fname, int $mtime, int $expiry, int $curtime, int $ttl
)
:
bool
Calculates if the file data is expired or not.
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. |
Type | Description |
---|---|
bool |


isLocalFileExpired(
int $expiry, int $curtime, int $ttl
)
:
bool
Calculates if the local file is expired or not.
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. |
Type | Description |
---|---|
bool |


loadMetaData(
bool $force
=
false
)
:
void
Load file meta information from the database
Name | Type | Description |
---|---|---|
$force | bool | File stats will be refreshed if true |


passthrough(
int $offset
=
0, int $length
=
false
)
:
void
Outputs file contents prepending them with appropriate HTTP headers.
Name | Type | Description |
---|---|---|
$offset | int | Transfer start offset |
$length | int | Transfer length |


processCache(
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.
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} |
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. |


processFile(
$callback, $expiry
=
false, $extraData
=
null
)
:
void
Name | Type | Description |
---|---|---|
$callback | ||
$expiry | ||
$extraData |


purge(
$printCallback
=
false, $microsleep
=
false, $max
=
false, $expiry
=
false
)
:
void
Name | Type | Description |
---|---|---|
$printCallback | ||
$microsleep | ||
$max | ||
$expiry |


requiresBinaryPurge(
)
:
bool
eZDB does require binary purge.
It does store files in DB and therefore doesn't remove files in real time
Type | Description |
---|---|
bool |
- Deprecated
- Deprecated as of 4.5, use {@link eZDBFileHandler::requiresPurge()} instead.
- Since
- 4.3.0


requiresClusterizing(
)
:
bool
Since eZDB uses the database, running clusterize.php is required
Type | Description |
---|---|
bool |


requiresPurge(
)
:
bool
eZDB does require binary purge.
It does store files in DB and therefore doesn't remove files in real time
Type | Description |
---|---|
bool |
- Since
- 4.5.0


startCacheGeneration(
)
:
bool
Starts cache generation for the current file.
This is done by creating a file named by the original file name, prefixed with '.generating'.
Type | Description |
---|---|
bool | false if the file is being generated, true if it is not |


storeCache(
$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().
Name | Type | Description |
---|---|---|
$fileData |