Class

eZDFSFileHandlerMySQLiBackend

class eZDFSFileHandlerMySQLiBackend implements eZClusterEventNotifier

Constants

TIME_UNTIL_RETRY

Wait for n microseconds until retry if copy fails, to avoid DFS overload.

Properties

mysqli $db DB connexion handle

Methods

__construct()

Constructor

void _connect()

Connects to the database.

_disconnect()

Disconnects the handler from the database

bool _copy(string $srcFilePath, string $dstFilePath, bool|string $fname = false)

Creates a copy of a file in DB+DFS

bool|eZMySQLBackendError _purge(string $filePath, bool $onlyExpired = false, bool|int $expiry = false, bool $fname = false)

Purges meta-data and file-data for a file entry

bool|int _purgeByLike(string $like, bool $onlyExpired = false, int $limit = 50, bool|int $expiry = false, string|bool $fname = false)

Purges meta-data and file-data for files matching a pattern using a SQL LIKE syntax.

bool _delete(string $filePath, bool $insideOfTransaction = false, bool|string $fname = false)

Deletes a file from DB

bool _deleteByLike(string $like, bool|string $fname = false)

Deletes multiple files using a SQL LIKE statement

bool _deleteByWildcard(string $wildcard, mixed $fname = false)

Deletes multiple DB files by wildcard

bool|mixed _deleteByDirList(array $dirList, string $commonPath, string $commonSuffix, string|bool $fname = false)

bool _exists(string $filePath, string|bool $fname = false, bool $ignoreExpiredFiles = true, bool $checkOnDFS = false)

Checks if a file exists

string|bool _fetch(string $filePath, bool|string $uniqueName = false)

Fetches the file $filePath from the database to its own name

string|bool _fetchContents(string $filePath, string|bool $fname = false)

array|false _fetchMetadata(string $filePath, bool $fname = false)

Fetches and returns metadata for $filePath

bool _linkCopy(string $srcPath, string $dstPath, string|bool $fname = false)

bool _passThrough(string $filePath, int $startOffset, bool|int $length = false, string|bool $fname = false)

Passes $filePath content through

bool _rename(string $srcFilePath, string $dstFilePath)

Renames $srcFilePath to $dstFilePath

void _store(string $filePath, string $datatype, string $scope, bool|string $fname = false)

Stores $filePath to cluster

bool _storeInner(string $filePath, string $datatype, string $scope, string $fname)

Callback function used to perform the actual file store operation

void _storeContents(string $filePath, string $contents, string $scope, string $datatype, bool|int $mtime = false, bool|string $fname = false)

Stores $contents as the contents of $filePath to the cluster

bool|eZMySQLBackendError _storeContentsInner(string $filePath, string $contents, string $scope, string $datatype, int|bool $curTime, string|bool $fname)

array|false _getFileList(array|bool $scopes = false, bool $excludeScopes = false, array|bool $limit = false, bool|string $path = false)

Returns the list of cluster files, filtered by the optional params

bool|int|string _insert(string $table, array $array, string $fname)

Performs an insert of the given items in $array.

void _report(string $query, string|bool $fname, int $timeTaken, int|bool $numRows = false)

Report SQL $query to debug system.

array _startCacheGeneration(string $filePath, string $generatingFilePath)

Attempts to begin cache generation by creating a new file named as the given filepath, suffixed with .generating.

bool _endCacheGeneration(string $filePath, string $generatingFilePath, bool $rename)

Ends the cache generation for the current file: moves the (meta)data for the .generating file to the actual file, and removed the .generating

bool _checkCacheGenerationTimeout(string $generatingFilePath, int $generatingFileMtime)

Checks if generation has timed out by looking for the .generating file and comparing its timestamp to the one assigned when the file was created

void _abortCacheGeneration(string $generatingFilePath)

Aborts the cache generation process by removing the .generating file

array(filepath) expiredFilesList(array $scopes, array|int $limit = array(0, 100), bool|int $expiry = false)

Returns the list of expired files

void registerListener(eZClusterEventListener $listener)

Registers $listener as the cluster event listener.

int deleteCacheFiles(int $limit)

Deletes a batch of cache files from the storage table.

string applyServerUri(string $filePath)

Transforms $filePath so that it contains a valid href to the file, wherever it is stored.

Details

at line 66
public __construct()

Constructor

at line 114
public void _connect()

Connects to the database.

at line 193
public _disconnect()

Disconnects the handler from the database

at line 211
public bool _copy(string $srcFilePath, string $dstFilePath, bool|string $fname = false)

Creates a copy of a file in DB+DFS

Parameters

string $srcFilePath Source file
string $dstFilePath Destination file
bool|string $fname

Return Value

bool

See also

_copyInner

at line 295
public bool|eZMySQLBackendError _purge(string $filePath, bool $onlyExpired = false, bool|int $expiry = false, bool $fname = false)

Purges meta-data and file-data for a file entry

Will only expire a single file. Use _purgeByLike to purge multiple files

Parameters

string $filePath Path of the file to purge
bool $onlyExpired Only purges expired files
bool|int $expiry
bool $fname

Return Value

bool|eZMySQLBackendError

See also

_purgeByLike

at line 339
public bool|int _purgeByLike(string $like, bool $onlyExpired = false, int $limit = 50, bool|int $expiry = false, string|bool $fname = false)

Purges meta-data and file-data for files matching a pattern using a SQL LIKE syntax.

Parameters

string $like SQL LIKE string applied to ezdfsfile.name to look for files to purge
bool $onlyExpired Only purge expired files (ezdfsfile.expired = 1)
int $limit Maximum number of items to purge in one call
bool|int $expiry Timestamp used to limit deleted files: only files older than this date will be deleted
string|bool $fname Optional caller name for debugging

Return Value

bool|int false if it fails, number of affected rows otherwise

See also

_purge

at line 417
public bool _delete(string $filePath, bool $insideOfTransaction = false, bool|string $fname = false)

Deletes a file from DB

The file won't be removed from disk, _purge has to be used for this. Only single files will be deleted, to delete multiple files, _deleteByLike has to be used.

Parameters

string $filePath Path of the file to delete
bool $insideOfTransaction Wether or not a transaction is already started
bool|string $fname Optional caller name for debugging

Return Value

bool

See also

_deleteInner
_deleteByLike

at line 473
public bool _deleteByLike(string $like, bool|string $fname = false)

Deletes multiple files using a SQL LIKE statement

Use _delete if you need to delete single files

Parameters

string $like SQL LIKE condition applied to ezdfsfile.name to look for files to delete. Will use nametrunk if the LIKE string matches a filetype that supports nametrunk.
bool|string $fname Optional caller name for debugging

Return Value

bool

See also

_deleteByLikeInner
_delete

at line 513
public bool _deleteByWildcard(string $wildcard, mixed $fname = false)

Deletes multiple DB files by wildcard

Parameters

string $wildcard
mixed $fname

Return Value

bool

at line 559
public bool|mixed _deleteByDirList(array $dirList, string $commonPath, string $commonSuffix, string|bool $fname = false)

Parameters

array $dirList
string $commonPath
string $commonSuffix
string|bool $fname

Return Value

bool|mixed

at line 619
public bool _exists(string $filePath, string|bool $fname = false, bool $ignoreExpiredFiles = true, bool $checkOnDFS = false)

Checks if a file exists

Parameters

string $filePath
string|bool $fname
bool $ignoreExpiredFiles
bool $checkOnDFS

Return Value

bool

at line 693
public string|bool _fetch(string $filePath, bool|string $uniqueName = false)

Fetches the file $filePath from the database to its own name

Saving $filePath locally with its original name, or $uniqueName if given

Parameters

string $filePath
bool|string $uniqueName Alternative name to save the file to

Return Value

string|bool the file physical path, or false if fetch failed

at line 768
public string|bool _fetchContents(string $filePath, string|bool $fname = false)

Parameters

string $filePath
string|bool $fname

Return Value

string|bool

at line 799
public array|false _fetchMetadata(string $filePath, bool $fname = false)

Fetches and returns metadata for $filePath

Parameters

string $filePath
bool $fname

Return Value

array|false file metadata, or false if the file does not exist in database.

at line 825
public bool _linkCopy(string $srcPath, string $dstPath, string|bool $fname = false)

Parameters

string $srcPath
string $dstPath
string|bool $fname

Return Value

bool

at line 844
public bool _passThrough(string $filePath, int $startOffset, bool|int $length = false, string|bool $fname = false)

Passes $filePath content through

Parameters

string $filePath
int $startOffset Byte offset to start download from
bool|int $length Byte length to be sent
string|bool $fname

Return Value

bool

at line 869
public bool _rename(string $srcFilePath, string $dstFilePath)

Renames $srcFilePath to $dstFilePath

Parameters

string $srcFilePath
string $dstFilePath

Return Value

bool

at line 945
public void _store(string $filePath, string $datatype, string $scope, bool|string $fname = false)

Stores $filePath to cluster

Parameters

string $filePath
string $datatype
string $scope
bool|string $fname

Return Value

void

at line 974
public bool _storeInner(string $filePath, string $datatype, string $scope, string $fname)

Callback function used to perform the actual file store operation

Parameters

string $filePath
string $datatype
string $scope
string $fname

Return Value

bool

See also

eZDFSFileHandlerMySQLiBackend::_store()

at line 1021
public void _storeContents(string $filePath, string $contents, string $scope, string $datatype, bool|int $mtime = false, bool|string $fname = false)

Stores $contents as the contents of $filePath to the cluster

Parameters

string $filePath
string $contents
string $scope
string $datatype
bool|int $mtime
bool|string $fname

Return Value

void

at line 1049
public bool|eZMySQLBackendError _storeContentsInner(string $filePath, string $contents, string $scope, string $datatype, int|bool $curTime, string|bool $fname)

Parameters

string $filePath
string $contents
string $scope
string $datatype
int|bool $curTime
string|bool $fname

Return Value

bool|eZMySQLBackendError

at line 1094
public array|false _getFileList(array|bool $scopes = false, bool $excludeScopes = false, array|bool $limit = false, bool|string $path = false)

Returns the list of cluster files, filtered by the optional params

Parameters

array|bool $scopes filter by array of scopes to include in the list
bool $excludeScopes if true, $scopes param acts as an exclude filter
array|bool $limit limits the search to offset limit[0], limit limit[1]
bool|string $path filter to include entries only including $path

Return Value

array|false the db list of entries of false if none found

at line 1174
public bool|int|string _insert(string $table, array $array, string $fname)

Performs an insert of the given items in $array.

Parameters

string $table Name of table to execute insert on.
array $array Associative array with data to insert, the keys are the field names and the values will be quoted according to type.
string $fname Name of caller function (for logging purpuse)

Return Value

bool|int|string

at line 1590
public void _report(string $query, string|bool $fname, int $timeTaken, int|bool $numRows = false)

Report SQL $query to debug system.

Parameters

string $query
string|bool $fname The function name that started the query, should contain relevant arguments in the text.
int $timeTaken Number of seconds the query + related operations took (as float).
int|bool $numRows Number of affected rows.

Return Value

void

at line 1621
public array _startCacheGeneration(string $filePath, string $generatingFilePath)

Attempts to begin cache generation by creating a new file named as the given filepath, suffixed with .generating.

If the file already exists, insertion is not performed and false is returned (means that the file is already being generated)

Parameters

string $filePath
string $generatingFilePath

Return Value

array array with 2 indexes: 'result', containing either ok or ko, and another index that depends on the result: - if result == 'ok', the 'mtime' index contains the generating file's mtime - if result == 'ko', the 'remaining' index contains the remaining generation time (time until timeout) in seconds

at line 1710
public bool _endCacheGeneration(string $filePath, string $generatingFilePath, bool $rename)

Ends the cache generation for the current file: moves the (meta)data for the .generating file to the actual file, and removed the .generating

Parameters

string $filePath
string $generatingFilePath
bool $rename

Return Value

bool

at line 1808
public bool _checkCacheGenerationTimeout(string $generatingFilePath, int $generatingFileMtime)

Checks if generation has timed out by looking for the .generating file and comparing its timestamp to the one assigned when the file was created

Parameters

string $generatingFilePath
int $generatingFileMtime

Return Value

bool true if the file didn't timeout, false otherwise

at line 1871
public void _abortCacheGeneration(string $generatingFilePath)

Aborts the cache generation process by removing the .generating file

Parameters

string $generatingFilePath .generating cache file path

Return Value

void

at line 1952
public array(filepath) expiredFilesList(array $scopes, array|int $limit = array(0, 100), bool|int $expiry = false)

Returns the list of expired files

Parameters

array $scopes Array of scopes to consider. At least one.
array|int $limit Max number of items. Set to false for unlimited.
bool|int $expiry Number of seconds, only items older than this will be returned.

Return Value

array(filepath)

Exceptions

ezcBaseValueException

at line 1991
public void registerListener(eZClusterEventListener $listener)

Registers $listener as the cluster event listener.

Parameters

eZClusterEventListener $listener

Return Value

void

at line 2020
public int deleteCacheFiles(int $limit)

Deletes a batch of cache files from the storage table.

Parameters

int $limit

Return Value

int The number of moved rows

Exceptions

RuntimeException if a MySQL query occurs
InvalidArgumentException if the split table feature is disabled

at line 2043
public string applyServerUri(string $filePath)

Transforms $filePath so that it contains a valid href to the file, wherever it is stored.

Parameters

string $filePath

Return Value

string