eZPublish  4.5
eZDBFileHandlerMysqliBackend Class Reference

Public Member Functions

 __mkdir_p ($dir)
 
 _abortCacheGeneration ($generatingFilePath)
 Aborts the cache generation process by removing the .generating file. More...
 
 _begin ($fname=false)
 
 _checkCacheGenerationTimeout ($generatingFilePath, $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. More...
 
 _cleanupFiledata ($filePath, $contentLength, $fname)
 
 _commit ($fname=false)
 
 _connect ()
 
 _copy ($srcFilePath, $dstFilePath, $fname=false)
 
 _copyInner ($srcFilePath, $dstFilePath, $fname, $metaData)
 
 _delete ($filePath, $insideOfTransaction=false, $fname=false)
 
 _deleteByDirList ($dirList, $commonPath, $commonSuffix, $fname=false)
 
 _deleteByDirListInner ($dirList, $commonPath, $commonSuffix, $fname)
 
 _deleteByLike ($like, $fname=false)
 
 _deleteByLikeInner ($like, $fname)
 
 _deleteByRegex ($regex, $fname=false)
 
 _deleteByRegexInner ($regex, $fname)
 
 _deleteByWildcard ($wildcard, $fname=false)
 
 _deleteByWildcardInner ($wildcard, $fname)
 
 _deleteInner ($filePath, $fname)
 
 _die ($msg, $sql=null)
 
 _endCacheGeneration ($filePath, $generatingFilePath, $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. More...
 
 _error ($query, $fname, $error="Failed to execute SQL for function:")
 
 _exclusiveLock ($filePath, $fname=false)
 
 _exists ($filePath, $fname=false, $ignoreExpiredFiles=true)
 
 _fail ($value, $text=false)
 
 _fetch ($filePath, $uniqueName=false)
 Fetches the file $filePath from the database, saving it locally with its original name, or $uniqueName if given. More...
 
 _fetchContents ($filePath, $fname=false)
 
 _fetchMetadata ($filePath, $fname=false)
 
 _freeExclusiveLock ($fname=false)
 
 _freeSharedLock ($fname=false)
 
 _getFileList ($scopes=false, $excludeScopes=false)
 
 _handleErrorType ($res)
 
 _insert ($table, $array, $fname)
 
 _insertUpdate ($table, $array, $update, $fname, $reportError=true)
 
 _isFailure ($result)
 
 _linkCopy ($srcPath, $dstPath, $fname=false)
 
 _md5 ($value)
 
 _passThrough ($filePath, $fname=false)
 
 _protect ()
 
 _purge ($filePath, $onlyExpired=false, $expiry=false, $fname=false)
 
 _purgeByLike ($like, $onlyExpired=false, $limit=50, $expiry=false, $fname=false)
 
 _query ($query, $fname=false, $reportError=true)
 
 _quote ($value)
 
 _rename ($srcFilePath, $dstFilePath)
 
 _report ($query, $fname, $timeTaken, $numRows=false)
 Report SQL $query to debug system. More...
 
 _rollback ($fname=false)
 
 _selectOne ($query, $fname, $error=false, $debug=false, $fetchCall)
 Common select method for doing a SELECT query which is passed in $query and fetching one row from the result. More...
 
 _selectOneAssoc ($query, $fname, $error=false, $debug=false)
 
 _selectOneRow ($query, $fname, $error=false, $debug=false)
 Common select method for doing a SELECT query which is passed in $query and fetching one row from the result. More...
 
 _sharedLock ($filePath, $fname=false)
 
 _sqlList ($array)
 
 _startCacheGeneration ($filePath, $generatingFilePath)
 Attempts to begin cache generation by creating a new file named as the given filepath, suffixed with .generating. More...
 
 _store ($filePath, $datatype, $scope, $fname=false)
 
 _storeContents ($filePath, $contents, $scope, $datatype, $mtime=false, $fname=false)
 
 _storeContentsInner ($filePath, $contents, $scope, $datatype, $curTime, $fname)
 
 _storeInner ($filePath, $datatype, $scope, $fname)
 
 _verifyExclusiveLock ($filePath, $expiry, $curtime, $ttl, $fname=false)
 Uses a secondary database connection to check outside the transaction scope if a file has been generated during the current process execution. More...
 
 expiredFilesList ($scopes, $limit=array(0, 100), $expiry=false)
 Returns the list of expired files. More...
 

Static Public Member Functions

static nameTrunk ($filePath, $scope)
 Returns the name_trunk for a file path. More...
 

Public Attributes

 $db = null
 
 $dbparams
 
 $numQueries = 0
 
 $transactionCount = 0
 

Private Member Functions

 remainingCacheGenerationTime ($row)
 Returns the remaining time, in seconds, before the generating file times out. More...
 

Private Attributes

 $backendVerify = null
 

Member Function Documentation

eZDBFileHandlerMysqliBackend::__mkdir_p (   $dir)

Referenced by _fetch().

eZDBFileHandlerMysqliBackend::_abortCacheGeneration (   $generatingFilePath)

Aborts the cache generation process by removing the .generating file.

Parameters
string$filePathReal cache file path
string$generatingFilePath.generating cache file path
Returns
void
eZDBFileHandlerMysqliBackend::_begin (   $fname = false)

Starts a new transaction by executing a BEGIN call. If a transaction is already started nothing is executed.

Referenced by _endCacheGeneration(), _exclusiveLock(), _protect(), _rename(), and _sharedLock().

eZDBFileHandlerMysqliBackend::_checkCacheGenerationTimeout (   $generatingFilePath,
  $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
Returns
bool true if the file didn't timeout, false otherwise
eZDBFileHandlerMysqliBackend::_cleanupFiledata (   $filePath,
  $contentLength,
  $fname 
)

Helper method for removing leftover file data rows for the file path $filePath. Note: This should be run after insert/updating filedata entries.

Entries which are after $contentLength or which have different chunk offset than the defined chunk_size in $dbparams will be removed.

Parameters
$filePathThe file path which was inserted/updated
$contentLengthThe length of the file data $fname Name of the function caller

Referenced by _copyInner(), _storeContentsInner(), and _storeInner().

eZDBFileHandlerMysqliBackend::_commit (   $fname = false)

Stops a current transaction and commits the changes by executing a COMMIT call. If the current transaction is a sub-transaction nothing is executed.

Referenced by _endCacheGeneration(), _freeExclusiveLock(), _protect(), and _rename().

eZDBFileHandlerMysqliBackend::_connect ( )
Todo:
check when parent does use $newLink param
Todo:
what if port is null, '' ??? to be tested
eZDBFileHandlerMysqliBackend::_copy (   $srcFilePath,
  $dstFilePath,
  $fname = false 
)

Referenced by _linkCopy().

eZDBFileHandlerMysqliBackend::_copyInner (   $srcFilePath,
  $dstFilePath,
  $fname,
  $metaData 
)
eZDBFileHandlerMysqliBackend::_delete (   $filePath,
  $insideOfTransaction = false,
  $fname = false 
)

Referenced by _copyInner().

eZDBFileHandlerMysqliBackend::_deleteByDirList (   $dirList,
  $commonPath,
  $commonSuffix,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_deleteByDirListInner (   $dirList,
  $commonPath,
  $commonSuffix,
  $fname 
)
eZDBFileHandlerMysqliBackend::_deleteByLike (   $like,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_deleteByLikeInner (   $like,
  $fname 
)
eZDBFileHandlerMysqliBackend::_deleteByRegex (   $regex,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_deleteByRegexInner (   $regex,
  $fname 
)
eZDBFileHandlerMysqliBackend::_deleteByWildcard (   $wildcard,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_deleteByWildcardInner (   $wildcard,
  $fname 
)
eZDBFileHandlerMysqliBackend::_deleteInner (   $filePath,
  $fname 
)

Referenced by _delete().

eZDBFileHandlerMysqliBackend::_die (   $msg,
  $sql = null 
)
Todo:
to be fixed: will this generate a warning?

Referenced by _connect().

eZDBFileHandlerMysqliBackend::_endCacheGeneration (   $filePath,
  $generatingFilePath,
  $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
Returns
bool
eZDBFileHandlerMysqliBackend::_error (   $query,
  $fname,
  $error = "Failed to execute SQL for function:" 
)

Prints error message $error to debug system.

Parameters
$queryThe query that was attempted, will be printed if $error is false
$fnameThe function name that started the query, should contain relevant arguments in the text.
$errorThe 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 false a generic message is shown.

Referenced by _checkCacheGenerationTimeout(), _query(), and _selectOne().

eZDBFileHandlerMysqliBackend::_exclusiveLock (   $filePath,
  $fname = false 
)

Locks the file entry for exclusive write access.

The locking is performed by trying to insert the entry with mtime set to -1, which means that file is not to be used. If it exists the mtime will be negated to mark it as deleted. This insert/update procedure will perform an exclusive lock of the row (InnoDB feature).

Note: All reads of the row must be done with LOCK IN SHARE MODE.

eZDBFileHandlerMysqliBackend::_exists (   $filePath,
  $fname = false,
  $ignoreExpiredFiles = true 
)

Referenced by _rename().

eZDBFileHandlerMysqliBackend::_fail (   $value,
  $text = false 
)

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

Parameters
$valueThe value which is sent to the debug system.
$textThe text/header for the value.

Referenced by _cleanupFiledata(), _copyInner(), _deleteByLikeInner(), _deleteByRegexInner(), _deleteByWildcardInner(), _deleteInner(), _exclusiveLock(), _purge(), _purgeByLike(), _sharedLock(), _storeContentsInner(), and _storeInner().

eZDBFileHandlerMysqliBackend::_fetch (   $filePath,
  $uniqueName = false 
)

Fetches the file $filePath from the database, saving it locally with its original name, or $uniqueName if given.

Parameters
string$filePath
string$uniqueName
Returns
the file physical path, or false if fetch failed
eZDBFileHandlerMysqliBackend::_fetchContents (   $filePath,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_fetchMetadata (   $filePath,
  $fname = false 
)
Returns
file metadata, or false if the file does not exist in database.

Referenced by _copy(), _fetch(), _fetchContents(), _passThrough(), and _rename().

eZDBFileHandlerMysqliBackend::_freeExclusiveLock (   $fname = false)

Frees a previously open exclusive-lock by commiting the current transaction.

Note: There is not checking to see if a lock is started, and if locking was done in an existing transaction nothing will happen.

eZDBFileHandlerMysqliBackend::_freeSharedLock (   $fname = false)

Frees a previously open shared-lock by performing a rollback on the current transaction.

Note: There is not checking to see if a lock is started, and if locking was done in an existing transaction nothing will happen.

eZDBFileHandlerMysqliBackend::_getFileList (   $scopes = false,
  $excludeScopes = false 
)
eZDBFileHandlerMysqliBackend::_handleErrorType (   $res)

Referenced by _delete().

eZDBFileHandlerMysqliBackend::_insert (   $table,
  $array,
  $fname 
)

Performs an insert of the given items in $array.

Parameters
$tableName of table to execute insert on.
$arrayAssociative array with data to insert, the keys are the field names and the values will be quoted according to type.
$fnameName of caller.
eZDBFileHandlerMysqliBackend::_insertUpdate (   $table,
  $array,
  $update,
  $fname,
  $reportError = true 
)

Performs an insert of the given items in $array, if entry specified already exists the $update SQL is executed to update the entry.

Parameters
$tableName of table to execute insert on.
$arrayAssociative array with data to insert, the keys are the field names and the values will be quoted according to type.
$updatePartial update SQL which is executed when entry exists.
$fnameName of caller.

Referenced by _copyInner(), _exclusiveLock(), _storeContentsInner(), and _storeInner().

eZDBFileHandlerMysqliBackend::_isFailure (   $result)

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.

Referenced by _copyInner(), _storeContentsInner(), and _storeInner().

eZDBFileHandlerMysqliBackend::_linkCopy (   $srcPath,
  $dstPath,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_md5 (   $value)

Make sure that $value is escaped and qouted and turned into and MD5. The returned value can directly be put into SQLs.

Referenced by _abortCacheGeneration(), _checkCacheGenerationTimeout(), _cleanupFiledata(), _copyInner(), _deleteInner(), _exists(), _fetch(), _fetchContents(), _fetchMetadata(), _purge(), _sharedLock(), and _startCacheGeneration().

eZDBFileHandlerMysqliBackend::_passThrough (   $filePath,
  $fname = false 
)
Deprecated:
This function should not be used since it cannot handle reading errors. For the PHP 5 port this should be removed.
eZDBFileHandlerMysqliBackend::_protect ( )

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.

Referenced by _copy(), _delete(), _deleteByDirList(), _deleteByLike(), _deleteByRegex(), _deleteByWildcard(), _store(), and _storeContents().

eZDBFileHandlerMysqliBackend::_purge (   $filePath,
  $onlyExpired = false,
  $expiry = false,
  $fname = false 
)

Purges meta-data and file-data for the file entry named $filePath from the database.

Referenced by _rename().

eZDBFileHandlerMysqliBackend::_purgeByLike (   $like,
  $onlyExpired = false,
  $limit = 50,
  $expiry = false,
  $fname = false 
)

Purges meta-data and file-data for the matching files. Matching is done by passing the string $like to the LIKE statement in the SQL.

eZDBFileHandlerMysqliBackend::_query (   $query,
  $fname = false,
  $reportError = true 
)

Performs mysql query and returns mysql result. Times the sql execution, adds accumulator timings and reports SQL to debug.

Parameters
$fnameThe function name that started the query, should contain relevant arguments in the text.

Referenced by _abortCacheGeneration(), _begin(), _cleanupFiledata(), _commit(), _copyInner(), _deleteByDirListInner(), _deleteByLikeInner(), _deleteByRegexInner(), _deleteByWildcardInner(), _deleteInner(), _endCacheGeneration(), _fetch(), _fetchContents(), _getFileList(), _insert(), _insertUpdate(), _passThrough(), _purge(), _purgeByLike(), _rename(), _rollback(), _sharedLock(), _startCacheGeneration(), and expiredFilesList().

eZDBFileHandlerMysqliBackend::_quote (   $value)

Make sure that $value is escaped and qouted according to type and returned as a string. The returned value can directly be put into SQLs.

Referenced by _deleteByLikeInner(), _deleteByRegexInner(), _purgeByLike(), and _sqlList().

eZDBFileHandlerMysqliBackend::_rename (   $srcFilePath,
  $dstFilePath 
)
eZDBFileHandlerMysqliBackend::_report (   $query,
  $fname,
  $timeTaken,
  $numRows = false 
)

Report SQL $query to debug system.

Parameters
string$fnameThe function name that started the query, should contain relevant arguments in the text.
int$timeTakenNumber of seconds the query + related operations took (as float).
int$numRowsNumber of affected rows.

Referenced by _checkCacheGenerationTimeout(), _query(), and _selectOne().

eZDBFileHandlerMysqliBackend::_rollback (   $fname = false)

Stops a current transaction and discards all changes by executing a ROLLBACK call. If the current transaction is a sub-transaction nothing is executed.

Referenced by _endCacheGeneration(), _freeSharedLock(), _protect(), and _rename().

eZDBFileHandlerMysqliBackend::_selectOne (   $query,
  $fname,
  $error = false,
  $debug = false,
  $fetchCall 
)

Common select method for doing a SELECT query which is passed in $query and fetching one row from the result.

If there are more than one row it will fail and exit, if 0 it returns false.

Parameters
string$fnameThe function name that started the query, should contain relevant arguments in the text.
mixed$errorSent to _error() in case of errors
bool$debugIf true it will display the fetched row in addition to the SQL.
string$fetchCallThe callback to fetch the row.

Referenced by _selectOneAssoc(), and _selectOneRow().

eZDBFileHandlerMysqliBackend::_selectOneAssoc (   $query,
  $fname,
  $error = false,
  $debug = false 
)

Common select method for doing a SELECT query which is passed in $query and fetching one row from the result. If there are more than one row it will fail and exit, if 0 it returns false. The returned row is an associative array.

Parameters
$fnameThe function name that started the query, should contain relevant arguments in the text.
$errorSent to _error() in case of errors
$debugIf true it will display the fetched row in addition to the SQL.

Referenced by _fetchMetadata().

eZDBFileHandlerMysqliBackend::_selectOneRow (   $query,
  $fname,
  $error = false,
  $debug = false 
)

Common select method for doing a SELECT query which is passed in $query and fetching one row from the result.

If there are more than one row it will fail and exit, if 0 it returns false.

Parameters
string$fnameThe function name that started the query, should contain relevant arguments in the text.
mixed$errorSent to _error() in case of errors
bool$debugIf true it will display the fetched row in addition to the SQL.
Returns
array|false A numerical array, or false if 0 or more than 1 rows

Referenced by _exists(), and _startCacheGeneration().

eZDBFileHandlerMysqliBackend::_sharedLock (   $filePath,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_sqlList (   $array)

Formats a list of entries as an SQL list which is separated by commas. Each entry in the list is quoted using _quote().

Referenced by _endCacheGeneration(), _insert(), _insertUpdate(), and expiredFilesList().

eZDBFileHandlerMysqliBackend::_startCacheGeneration (   $filePath,
  $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
Returns
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
eZDBFileHandlerMysqliBackend::_store (   $filePath,
  $datatype,
  $scope,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_storeContents (   $filePath,
  $contents,
  $scope,
  $datatype,
  $mtime = false,
  $fname = false 
)
eZDBFileHandlerMysqliBackend::_storeContentsInner (   $filePath,
  $contents,
  $scope,
  $datatype,
  $curTime,
  $fname 
)
eZDBFileHandlerMysqliBackend::_storeInner (   $filePath,
  $datatype,
  $scope,
  $fname 
)
eZDBFileHandlerMysqliBackend::_verifyExclusiveLock (   $filePath,
  $expiry,
  $curtime,
  $ttl,
  $fname = false 
)

Uses a secondary database connection to check outside the transaction scope if a file has been generated during the current process execution.

Parameters
string$filePath
int$expiry
int$curtime
int$ttl
string$fname
Returns
bool false if the file exists and is not expired, true otherwise
eZDBFileHandlerMysqliBackend::expiredFilesList (   $scopes,
  $limit = array( 0, 100 ),
  $expiry = false 
)

Returns the list of expired files.

Parameters
array$scopesArray of scopes to consider. At least one.
int$limitMax number of items. Set to false for unlimited.
int$expiryNumber of seconds, only items older than this will be returned.
Returns
array(filepath)
Since
4.3
static eZDBFileHandlerMysqliBackend::nameTrunk (   $filePath,
  $scope 
)
static

Returns the name_trunk for a file path.

Parameters
string$filePath
string$scope
Returns
string

Referenced by _endCacheGeneration().

eZDBFileHandlerMysqliBackend::remainingCacheGenerationTime (   $row)
private

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

Parameters
resource$fileRow
Returns
int Remaining generation seconds. A negative value indicates a timeout.

Referenced by _startCacheGeneration().

Member Data Documentation

eZDBFileHandlerMysqliBackend::$backendVerify = null
private
eZDBFileHandlerMysqliBackend::$db = null
eZDBFileHandlerMysqliBackend::$dbparams
eZDBFileHandlerMysqliBackend::$numQueries = 0

Referenced by _report().

eZDBFileHandlerMysqliBackend::$transactionCount = 0

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