kernel/private/classes/clusterfilehandlers/dfsbackends/mysqli.php

Show: inherited
Table of Contents

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

Package: kernel

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

Constantstring  TABLE_METADATA = 'ezdfsfile'

DB file table name

string

Properties

Propertypublic\handle  $db= 'null'

DB connexion handle

Default valuenullDetails
Type
\handle
Propertyprotectedarray  $dbparams= 'null'
static

DB connexion parameters

Default valuenullDetails
Type
array
Propertyprotected\eZDFSFileHandlerDFSBackend  $dfsbackend= 'null'

Distributed filesystem backend

Default valuenullDetails
Type
\eZDFSFileHandlerDFSBackend
Propertyprotectedint  $numQueries= '0'

Amount of executed queries, for debugging purpose

Default value0Details
Type
int
Propertyprotectedint  $transactionCount= '0'

Current transaction level.

Will be used to decide wether we can BEGIN (if it's the first BEGIN call) or COMMIT (if we're commiting the last running transaction

Default value0Details
Type
int

Methods

methodprotected__mkdir_p(  $dir ) : void

Parameters
Name Type Description
$dir
methodpublic_abortCacheGeneration( string $generatingFilePath ) : void

Aborts the cache generation process by removing the .generating file

Parameters
Name Type Description
$generatingFilePath string

.generating cache file path

methodprotected_begin(  $fname = false ) : void

Starts a new transaction by executing a BEGIN call.

If a transaction is already started nothing is executed.

Parameters
Name Type Description
$fname
methodpublic_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

Parameters
Name Type Description
$generatingFilePath string
$generatingFileMtime int
Returns
Type Description
bool true if the file didn't timeout, false otherwise
methodprotected_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.

Parameters
Name Type Description
$fname
methodpublic_connect( ) : void

Connects to the database.

methodpublic_copy( string $srcFilePath, string $dstFilePath, string $fname = false ) : bool

Creates a copy of a file in DB+DFS

Parameters
Name Type Description
$srcFilePath string

Source file

$dstFilePath string

Destination file

$fname string
Returns
Type Description
bool
Details
See
\_copyInner  
methodprivate_copyInner( string $srcFilePath, string $dstFilePath, bool $fname, array $metaData ) : bool

Inner function used by _copy to perform the operation in a transaction

Parameters
Name Type Description
$srcFilePath string
$dstFilePath string
$fname bool
$metaData array

Source file's metadata

Returns
Type Description
bool
Details
See
\_copy  
methodpublic_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.

Parameters
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

Returns
Type Description
bool
Details
See
\_deleteInner  
See
\_deleteByLike  
methodpublic_deleteByDirList(  $dirList,  $commonPath,  $commonSuffix,  $fname = false ) : void

Parameters
Name Type Description
$dirList
$commonPath
$commonSuffix
$fname
methodprotected_deleteByDirListInner(  $dirList,  $commonPath,  $commonSuffix,  $fname ) : void

Parameters
Name Type Description
$dirList
$commonPath
$commonSuffix
$fname
methodpublic_deleteByLike( string $like, string $fname = false ) : bool

Deletes multiple files using a SQL LIKE statement

Use _delete if you need to delete single files

Parameters
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

Returns
Type Description
bool
Details
See
\_deleteByLikeInner  
See
\_delete  
methodprivate_deleteByLikeInner( string $like, mixed $fname ) :

Callback used by _deleteByLike to perform the deletion

Parameters
Name Type Description
$like string
$fname mixed
methodpublic_deleteByRegex( string $regex, mixed $fname = false ) : bool

Deletes DB files by using a SQL regular expression applied to file names

Parameters
Name Type Description
$regex string
$fname mixed
Returns
Type Description
bool
Details
Deprecated
Has severe performance issues  
methodpublic_deleteByRegexInner( mixed $regex, mixed $fname ) :

Callback used by _deleteByRegex to perform the deletion

Parameters
Name Type Description
$regex mixed
$fname mixed
Details
Deprecated
Has severe performances issues  
methodpublic_deleteByWildcard( string $wildcard, mixed $fname = false ) : bool

Deletes multiple DB files by wildcard

Parameters
Name Type Description
$wildcard string
$fname mixed
Returns
Type Description
bool
Details
Deprecated
Has severe performance issues  
methodprotected_deleteByWildcardInner( mixed $wildcard, mixed $fname ) : bool

Callback used by _deleteByWildcard to perform the deletion

Parameters
Name Type Description
$wildcard mixed
$fname mixed
Returns
Type Description
bool
Details
Deprecated
Has severe performance issues  
methodprotected_deleteInner( string $filePath, string $fname ) : bool

Callback method used by by _delete to delete a single file

Parameters
Name Type Description
$filePath string

Path of the file to delete

$fname string

Optional caller name for debugging

Returns
Type Description
bool
methodprotected_die( string $msg, string $sql = null ) : void

Handles a DB error, displaying it as an eZDebug error

Parameters
Name Type Description
$msg string

Message to display

$sql string

SQL query to display error for

Details
See
\eZDebug::writeError  
methodpublic_disconnect( ) : void

Disconnects the handler from the database

methodpublic_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

Parameters
Name Type Description
$filePath string
$generatingFilePath
$rename
Returns
Type Description
bool
methodprotected_error( string $query, string $fname, string $error = "Failed to execute SQL for function:" ) : void

Prints error message $error to debug system.

Parameters
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.

methodpublic_exists(  $filePath,  $fname = false,  $ignoreExpiredFiles = true,  $checkOnDFS = false ) : void

Parameters
Name Type Description
$filePath
$fname
$ignoreExpiredFiles
$checkOnDFS
methodprotected_fail( mixed $value, string $text = false ) : void

Creates an error object which can be read by some backend functions.

Parameters
Name Type Description
$value mixed

The value which is sent to the debug system.

$text string

The text/header for the value.

methodpublic_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

Parameters
Name Type Description
$filePath string
$uniqueName string

Alternative name to save the file to

Returns
Type Description
string | bool the file physical path, or false if fetch failed
methodpublic_fetchContents(  $filePath,  $fname = false ) : void

Parameters
Name Type Description
$filePath
$fname
methodpublic_fetchMetadata(  $filePath,  $fname = false ) : array | false

Fetches and returns metadata for $filePath

Parameters
Name Type Description
$filePath
$fname
Returns
Type Description
array | false file metadata, or false if the file does not exist in database.
methodpublic_getFileList(  $scopes = false,  $excludeScopes = false ) : void

Parameters
Name Type Description
$scopes
$excludeScopes
methodprotected_handleErrorType(  $res ) : void

Parameters
Name Type Description
$res
methodpublic_insert( string $table, array $array, string $fname ) : void

Performs an insert of the given items in $array.

Parameters
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)

methodprotected_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.

Parameters
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
methodprotected_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.

Parameters
Name Type Description
$result
methodpublic_linkCopy(  $srcPath,  $dstPath,  $fname = false ) : void

Parameters
Name Type Description
$srcPath
$dstPath
$fname
methodprotected_md5(  $value ) : void

Provides the SQL calls to convert $value to MD5 The returned value can directly be put into SQLs.

Parameters
Name Type Description
$value
methodpublic_passThrough( string $filePath,  $startOffset = 0, int $length = false,  $fname = false ) : bool

Passes $filePath content through

Parameters
Name Type Description
$filePath string
$startOffset
$length int

Byte length to be sent

$fname
Returns
Type Description
bool
methodprotected_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.

methodpublic_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

Parameters
Name Type Description
$filePath string

Path of the file to purge

$onlyExpired bool

Only purges expired files

$expiry bool | int
$fname bool
Details
See
\_purgeByLike  
methodpublic_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.

Parameters
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

Returns
Type Description
bool | int false if it fails, number of affected rows otherwise
Details
See
\_purge  
Todo
This method should also remove the files from disk  
methodprotected_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.

Parameters
Name Type Description
$query
$fname string

The function name that started the query, should contain relevant arguments in the text.

$reportError
methodprotected_quote( string $value ) : string

Make sure that $value is escaped and qouted according to type and returned as a string.

Parameters
Name Type Description
$value string

a SQL parameter to escape

Returns
Type Description
string a string that can safely be used in SQL queries
methodpublic_rename( string $srcFilePath, string $dstFilePath ) : bool

Renames $srcFilePath to $dstFilePath

Parameters
Name Type Description
$srcFilePath string
$dstFilePath string
Returns
Type Description
bool
methodpublic_report(  $query, string $fname, int $timeTaken, int $numRows = false ) : void

Report SQL $query to debug system.

Parameters
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.

methodprotected_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.

Parameters
Name Type Description
$fname
methodprotected_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.

Parameters
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.

Returns
Type Description
mixed
methodprotected_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.

Parameters
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.

Returns
Type Description
array | false
methodprotected_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.

Parameters
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.

Returns
Type Description
array | false
methodprotected_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().

Parameters
Name Type Description
$array array
Returns
Type Description
array
methodpublic_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)

Parameters
Name Type Description
$filePath string
$generatingFilePath
Returns
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
methodpublic_store( string $filePath, string $datatype, string $scope, string $fname = false ) : void

Stores $filePath to cluster

Parameters
Name Type Description
$filePath string
$datatype string
$scope string
$fname string
methodpublic_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

Parameters
Name Type Description
$filePath string
$contents string
$scope string
$datatype string
$mtime int
$fname string
methodpublic_storeContentsInner(  $filePath,  $contents,  $scope,  $datatype,  $curTime,  $fname ) : void

Parameters
Name Type Description
$filePath
$contents
$scope
$datatype
$curTime
$fname
methodpublic_storeInner( string $filePath, string $datatype, string $scope, string $fname ) : bool

Callback function used to perform the actual file store operation

Parameters
Name Type Description
$filePath string
$datatype string
$scope string
$fname string
Returns
Type Description
bool
Details
See
\eZDFSFileHandlerMySQLBackend::_store()  
methodpublicexpiredFilesList( array $scopes, int $limit = array( 0, 100 ), int $expiry = false ) : \array(filepath)

Returns the list of expired files

Parameters
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.

Returns
Type Description
\array(filepath)
Details
Since
4.3  
methodprotectednameTrunk( string $filePath, string $scope ) : string
static

Returns the name_trunk for a file path

Parameters
Name Type Description
$filePath string
$scope string
Returns
Type Description
string
methodprotectedremainingCacheGenerationTime(  $row ) : int

Returns the remaining time, in seconds, before the generating file times out

Parameters
Name Type Description
$row
Returns
Type Description
int Remaining generation seconds. A negative value indicates a timeout.
Documentation was generated by DocBlox 0.18.1.