kernel/private/classes/clusterfilehandlers/dfsbackends/mysqli.php
File containing the eZDFSFileHandlerMySQLiBackend 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
\eZDFSFileHandlerMySQLiBackend
File containing the eZDFSFileHandlerMySQLiBackend class.
- 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


\eZDFSFileHandlerDFSBackend
$dfsbackend= 'null'
Distributed filesystem backend
null
Details


int
$numQueries= '0'
Amount of executed queries, for debugging purpose
0
Details- Type
- int
Methods


_abortCacheGeneration(
string $generatingFilePath
)
:
void
Aborts the cache generation process by removing the .generating file
Name | Type | Description |
---|---|---|
$generatingFilePath | string | .generating cache file path |


_begin(
$fname
=
false
)
:
void
Starts a new transaction by executing a BEGIN call.
If a transaction is already started nothing is executed.
Name | Type | Description |
---|---|---|
$fname |


_checkCacheGenerationTimeout(
string $generatingFilePath, int $generatingFileMtime
)
:
bool
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
Name | Type | Description |
---|---|---|
$generatingFilePath | string | |
$generatingFileMtime | int |
Type | Description |
---|---|
bool | true if the file didn't timeout, false otherwise |


_commit(
$fname
=
false
)
:
void
Stops a current transaction and commits the changes by executing a COMMIT call.
If the current transaction is a sub-transaction nothing is executed.
Name | Type | Description |
---|---|---|
$fname |


_connect(
)
:
void
Connects to the database.
Exception | Description |
---|---|
\eZClusterHandlerDBNoConnectionException | |
\eZClusterHandlerDBNoDatabaseException |


_copy(
string $srcFilePath, string $dstFilePath, string $fname
=
false
)
:
bool
Creates a copy of a file in DB+DFS
Name | Type | Description |
---|---|---|
$srcFilePath | string | Source file |
$dstFilePath | string | Destination file |
$fname | string |
Type | Description |
---|---|
bool |
- See
- \_copyInner


_copyInner(
string $srcFilePath, string $dstFilePath, bool $fname, array $metaData
)
:
bool
Inner function used by _copy to perform the operation in a transaction
Name | Type | Description |
---|---|---|
$srcFilePath | string | |
$dstFilePath | string | |
$fname | bool | |
$metaData | array | Source file's metadata |
Type | Description |
---|---|
bool |
- See
- \_copy


_delete(
string $filePath, bool $insideOfTransaction
=
false, bool | string $fname
=
false
)
:
bool
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.
Name | Type | Description |
---|---|---|
$filePath | string | Path of the file to delete |
$insideOfTransaction | bool | Wether or not a transaction is already started |
$fname | bool | string | Optional caller name for debugging |
Type | Description |
---|---|
bool |
- See
- \_deleteInner
- See
- \_deleteByLike


_deleteByDirList(
$dirList, $commonPath, $commonSuffix, $fname
=
false
)
:
void
Name | Type | Description |
---|---|---|
$dirList | ||
$commonPath | ||
$commonSuffix | ||
$fname |


_deleteByDirListInner(
$dirList, $commonPath, $commonSuffix, $fname
)
:
void
Name | Type | Description |
---|---|---|
$dirList | ||
$commonPath | ||
$commonSuffix | ||
$fname |


_deleteByLike(
string $like, string $fname
=
false
)
:
bool
Deletes multiple files using a SQL LIKE statement
Use _delete if you need to delete single files
Name | Type | Description |
---|---|---|
$like | string | SQL LIKE condition applied to ezdfsfile.name to look for files to delete. Will use name_trunk if the LIKE string matches a filetype that supports name_trunk. |
$fname | string | Optional caller name for debugging |
Type | Description |
---|---|
bool |
- See
- \_deleteByLikeInner
- See
- \_delete


_deleteByLikeInner(
string $like, mixed $fname
)
:
Callback used by _deleteByLike to perform the deletion
Name | Type | Description |
---|---|---|
$like | string | |
$fname | mixed |


_deleteByRegex(
string $regex, mixed $fname
=
false
)
:
bool
Deletes DB files by using a SQL regular expression applied to file names
Name | Type | Description |
---|---|---|
$regex | string | |
$fname | mixed |
Type | Description |
---|---|
bool |
- Deprecated
- Has severe performance issues


_deleteByRegexInner(
mixed $regex, mixed $fname
)
:
Callback used by _deleteByRegex to perform the deletion
Name | Type | Description |
---|---|---|
$regex | mixed | |
$fname | mixed |
- Deprecated
- Has severe performances issues


_deleteByWildcard(
string $wildcard, mixed $fname
=
false
)
:
bool
Deletes multiple DB files by wildcard
Name | Type | Description |
---|---|---|
$wildcard | string | |
$fname | mixed |
Type | Description |
---|---|
bool |
- Deprecated
- Has severe performance issues


_deleteByWildcardInner(
mixed $wildcard, mixed $fname
)
:
bool
Callback used by _deleteByWildcard to perform the deletion
Name | Type | Description |
---|---|---|
$wildcard | mixed | |
$fname | mixed |
Type | Description |
---|---|
bool |
- Deprecated
- Has severe performance issues


_deleteInner(
string $filePath, string $fname
)
:
bool
Callback method used by by _delete to delete a single file
Name | Type | Description |
---|---|---|
$filePath | string | Path of the file to delete |
$fname | string | Optional caller name for debugging |
Type | Description |
---|---|
bool |


_die(
string $msg, string $sql
=
null
)
:
void
Handles a DB error, displaying it as an eZDebug error
Name | Type | Description |
---|---|---|
$msg | string | Message to display |
$sql | string | SQL query to display error for |


_endCacheGeneration(
string $filePath, $generatingFilePath, $rename
)
:
bool
Ends the cache generation for the current file: moves the (meta)data for the .generating file to the actual file, and removed the .generating
Name | Type | Description |
---|---|---|
$filePath | string | |
$generatingFilePath | ||
$rename |
Type | Description |
---|---|
bool |


_error(
string $query, string $fname, string $error
=
"Failed to execute SQL for function:"
)
:
void
Prints error message $error to debug system.
Name | Type | Description |
---|---|---|
$query | string | The query that was attempted, will be printed if $error is \c false |
$fname | string | The function name that started the query, should contain relevant arguments in the text. |
$error | string | The error message, if this is an array the first element is the value to dump and the second the error header (for eZDebug::writeNotice). If this is \c false a generic message is shown. |


_exists(
$filePath, $fname
=
false, $ignoreExpiredFiles
=
true, $checkOnDFS
=
false
)
:
void
Name | Type | Description |
---|---|---|
$filePath | ||
$fname | ||
$ignoreExpiredFiles | ||
$checkOnDFS |


_fail(
mixed $value, string $text
=
false
)
:
void
Creates an error object which can be read by some backend functions.
Name | Type | Description |
---|---|---|
$value | mixed | The value which is sent to the debug system. |
$text | string | The text/header for the value. |


_fetch(
string $filePath, string $uniqueName
=
false
)
:
string | bool
Fetches the file $filePath from the database to its own name
Saving $filePath locally with its original name, or $uniqueName if given
Name | Type | Description |
---|---|---|
$filePath | string | |
$uniqueName | string | Alternative name to save the file to |
Type | Description |
---|---|
string | bool | the file physical path, or false if fetch failed |


_fetchContents(
$filePath, $fname
=
false
)
:
void
Name | Type | Description |
---|---|---|
$filePath | ||
$fname |


_fetchMetadata(
$filePath, $fname
=
false
)
:
array | false
Fetches and returns metadata for $filePath
Name | Type | Description |
---|---|---|
$filePath | ||
$fname |
Type | Description |
---|---|
array | false | file metadata, or false if the file does not exist in database. |


_getFileList(
$scopes
=
false, $excludeScopes
=
false
)
:
void
Name | Type | Description |
---|---|---|
$scopes | ||
$excludeScopes |


_insert(
string $table, array $array, string $fname
)
:
void
Performs an insert of the given items in $array.
Name | Type | Description |
---|---|---|
$table | string | 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. |
$fname | string | Name of caller function (for logging purpuse) |


_insertUpdate(
string $table, array $array, string $update, string $fname, $reportError
=
true
)
:
void
Performs an insert of the given items in $array.
If entry specified already exists the $update SQL is executed to update the entry instead.
Name | Type | Description |
---|---|---|
$table | string | Name of table to execute insert on. |
$array | array | array $array Associative array with data to insert, the keys are the field names and the values will be quoted according to type. |
$update | string | Partial update SQL which is executed when entry exists. |
$fname | string | Name of caller function (for logging purpuse) |
$reportError |


_isFailure(
$result
)
:
void
Checks if $result is a failure type and returns true if so, false otherwise.
A failure is either the value false or an error object of type eZMySQLBackendError.
Name | Type | Description |
---|---|---|
$result |


_linkCopy(
$srcPath, $dstPath, $fname
=
false
)
:
void
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath | ||
$fname |


_md5(
$value
)
:
void
Provides the SQL calls to convert $value to MD5 The returned value can directly be put into SQLs.
Name | Type | Description |
---|---|---|
$value |


_passThrough(
string $filePath, $startOffset
=
0, int $length
=
false, $fname
=
false
)
:
bool
Passes $filePath content through
Name | Type | Description |
---|---|---|
$filePath | string | |
$startOffset | ||
$length | int | Byte length to be sent |
$fname |
Type | Description |
---|---|
bool |


_protect(
)
:
void
Protects a custom function with SQL queries in a database transaction.
If the function reports an error the transaction is ROLLBACKed.
The first argument to the _protect() is the callback and the second is the name of the function (for query reporting). The remainder of arguments are sent to the callback.
A return value of false from the callback is considered a failure, any other value is returned from _protect(). For extended error handling call _fail() and return the value.


_purge(
string $filePath, bool $onlyExpired
=
false, bool | int $expiry
=
false, bool $fname
=
false
)
:
void
Purges meta-data and file-data for a file entry
Will only expire a single file. Use _purgeByLike to purge multiple files
Name | Type | Description |
---|---|---|
$filePath | string | Path of the file to purge |
$onlyExpired | bool | Only purges expired files |
$expiry | bool | int | |
$fname | bool |
- See
- \_purgeByLike


_purgeByLike(
string $like, bool $onlyExpired
=
false, integer $limit
=
50, integer $expiry
=
false, mixed $fname
=
false
)
:
bool | int
Purges meta-data and file-data for files matching a pattern using a SQL LIKE syntax.
Name | Type | Description |
---|---|---|
$like | string | SQL LIKE string applied to ezdfsfile.name to look for files to purge |
$onlyExpired | bool | Only purge expired files (ezdfsfile.expired = 1) |
$limit | integer | Maximum number of items to purge in one call |
$expiry | integer | Timestamp used to limit deleted files: only files older than this date will be deleted |
$fname | mixed | Optional caller name for debugging |
Type | Description |
---|---|
bool | int | false if it fails, number of affected rows otherwise |
- See
- \_purge
- Todo
- This method should also remove the files from disk


_query(
$query, string $fname
=
false, $reportError
=
true
)
:
void
Performs mysql query and returns mysql result.
Times the sql execution, adds accumulator timings and reports SQL to debug.
Name | Type | Description |
---|---|---|
$query | ||
$fname | string | The function name that started the query, should contain relevant arguments in the text. |
$reportError |


_quote(
string $value
)
:
string
Make sure that $value is escaped and qouted according to type and returned as a string.
Name | Type | Description |
---|---|---|
$value | string | a SQL parameter to escape |
Type | Description |
---|---|
string | a string that can safely be used in SQL queries |


_rename(
string $srcFilePath, string $dstFilePath
)
:
bool
Renames $srcFilePath to $dstFilePath
Name | Type | Description |
---|---|---|
$srcFilePath | string | |
$dstFilePath | string |
Type | Description |
---|---|
bool |


_report(
$query, string $fname, int $timeTaken, int $numRows
=
false
)
:
void
Report SQL $query to debug system.
Name | Type | Description |
---|---|---|
$query | ||
$fname | string | The function name that started the query, should contain relevant arguments in the text. |
$timeTaken | int | Number of seconds the query + related operations took (as float). |
$numRows | int | Number of affected rows. |


_rollback(
$fname
=
false
)
:
void
Stops a current transaction and discards all changes by executing a ROLLBACK call.
If the current transaction is a sub-transaction nothing is executed.
Name | Type | Description |
---|---|---|
$fname |


_selectOne(
$query, string $fname, string $error
=
false, bool $debug
=
false, callback $fetchCall
)
:
mixed
Runs a select query, applying the $fetchCall callback to one result If there are more than one row it will fail and exit, if 0 it returns false.
Name | Type | Description |
---|---|---|
$query | ||
$fname | string | The function name that started the query, should contain relevant arguments in the text. |
$error | string | Sent to _error() in case of errors |
$debug | bool | If true it will display the fetched row in addition to the SQL. |
$fetchCall | callback | The callback to fetch the row. |
Type | Description |
---|---|
mixed |


_selectOneAssoc(
string $query, string $fname, string $error
=
false, bool $debug
=
false
)
:
array | false
Runs a select query and returns one associative row from the result.
If there are more than one row it will fail and exit, if 0 it returns false.
Name | Type | Description |
---|---|---|
$query | string | |
$fname | string | The function name that started the query, should contain relevant arguments in the text. |
$error | string | Sent to _error() in case of errors |
$debug | bool | If true it will display the fetched row in addition to the SQL. |
Type | Description |
---|---|
array | false |


_selectOneRow(
string $query, string $fname, string $error
=
false, bool $debug
=
false
)
:
array | false
Runs a select query and returns one numeric indexed row from the result If there are more than one row it will fail and exit, if 0 it returns false.
Name | Type | Description |
---|---|---|
$query | string | |
$fname | string | The function name that started the query, should contain relevant arguments in the text. |
$error | string | Sent to _error() in case of errors |
$debug | bool | If true it will display the fetched row in addition to the SQL. |
Type | Description |
---|---|
array | false |


_sqlList(
array $array
)
:
array
Formats a list of entries as an SQL list which is separated by commas.
Each entry in the list is quoted using _quote().
Name | Type | Description |
---|---|---|
$array | array |
Type | Description |
---|---|
array |


_startCacheGeneration(
string $filePath, $generatingFilePath
)
:
array
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)
Name | Type | Description |
---|---|---|
$filePath | string | |
$generatingFilePath |
Type | Description |
---|---|
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 |


_store(
string $filePath, string $datatype, string $scope, string $fname
=
false
)
:
void
Stores $filePath to cluster
Name | Type | Description |
---|---|---|
$filePath | string | |
$datatype | string | |
$scope | string | |
$fname | string |


_storeContents(
string $filePath, string $contents, string $scope, string $datatype, int $mtime
=
false, string $fname
=
false
)
:
void
Stores $contents as the contents of $filePath to the cluster
Name | Type | Description |
---|---|---|
$filePath | string | |
$contents | string | |
$scope | string | |
$datatype | string | |
$mtime | int | |
$fname | string |


_storeContentsInner(
$filePath, $contents, $scope, $datatype, $curTime, $fname
)
:
void
Name | Type | Description |
---|---|---|
$filePath | ||
$contents | ||
$scope | ||
$datatype | ||
$curTime | ||
$fname |


_storeInner(
string $filePath, string $datatype, string $scope, string $fname
)
:
bool
Callback function used to perform the actual file store operation
Name | Type | Description |
---|---|---|
$filePath | string | |
$datatype | string | |
$scope | string | |
$fname | string |
Type | Description |
---|---|
bool |


expiredFilesList(
array $scopes, int $limit
=
array( 0, 100 ), int $expiry
=
false
)
:
\array(filepath)
Returns the list of expired files
Name | Type | Description |
---|---|---|
$scopes | array | Array of scopes to consider. At least one. |
$limit | int | Max number of items. Set to false for unlimited. |
$expiry | int | Number of seconds, only items older than this will be returned. |
Type | Description |
---|---|
\array(filepath) |
- Since
- 4.3


nameTrunk(
string $filePath, string $scope
)
:
string
Returns the name_trunk for a file path
Name | Type | Description |
---|---|---|
$filePath | string | |
$scope | string |
Type | Description |
---|---|
string |