Project

General

Profile

Feature #18557 » 0008010_v3.patch

Administrator Admin, 2010-07-21 16:40

View differences:

t3lib/stddb/tables.sql (Arbeitskopie)
) ENGINE=InnoDB;
#
# Table structure for table 'sys_lock'
#
CREATE TABLE sys_lock (
id varchar(64) DEFAULT '' NOT NULL,
expires int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
#
# Table structure for table 'sys_language'
#
CREATE TABLE sys_language (
t3lib/class.t3lib_lock.php (Arbeitskopie)
* @see class.t3lib_tstemplate.php, class.tslib_fe.php
*/
class t3lib_lock {
const METHOD_SIMPLE = 'simple';
const METHOD_FLOCK = 'flock';
const METHOD_SEMAPHORE = 'semaphore';
const METHOD_DATABASE = 'database';
const METHOD_DISABLE = 'disable';
protected $method;
protected $id; // Identifier used for this lock
protected $resource; // Resource used for this lock (can be a file or a semaphore resource)
......
protected $loops = 150; // Number of times a locked resource is tried to be acquired. This is only used by manual locks like the "simple" method.
protected $step = 200; // Milliseconds after lock acquire is retried. $loops * $step results in the maximum delay of a lock. Only used by manual locks like the "simple" method.
protected $expiration = 300; // Number of seconds after a resource shall expire
......
}
// Detect locking method
if (in_array($method, array('disable', 'simple', 'flock', 'semaphore'))) {
if (in_array($method, array('disable', 'simple', 'flock', 'semaphore', 'database'))) {
$this->method = $method;
} else {
throw new Exception('No such method "' . $method . '"');
......
$success = TRUE;
}
break;
case 'database':
$this->id = sha1($id);
$this->resource = $GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, 'sys_lock');
$success = TRUE;
break;
case 'disable':
return FALSE;
break;
......
switch ($this->method) {
case 'simple':
if (is_file($this->resource)) {
$noWait = FALSE;
$this->sysLog('Waiting for a different process to release the lock');
$i = 0;
while ($i<$this->loops) {
......
clearstatcache();
if (!is_file($this->resource)) { // Lock became free, leave the loop
$this->sysLog('Different process released the lock');
$noWait = FALSE;
break;
}
}
......
$noWait = FALSE;
}
break;
case 'database':
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lock', 'expires<' . $GLOBALS['EXEC_TIME']);
$noWait = FALSE;
while ($i < $this->loops) {
if ($this->isDatabaseLockActive()) {
$i++;
usleep($this->step * 1000);
} else {
$noWait = TRUE;
break;
}
}
$fields = array(
'expires' => $GLOBALS['EXEC_TIME'] + $this->expiration,
'id' => $this->id,
);
if ($noWait || !$this->isDatabaseLockActive()) {
$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lock', $fields);
} else {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_lock', 'id=' . $this->resource, $fields);
}
break;
case 'disable':
$noWait = FALSE;
$isAcquired = FALSE;
......
$success = FALSE;
}
break;
case 'database':
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lock', 'id=' . $this->resource);
$success = ($GLOBALS['TYPO3_DB']->sql_affected_rows() > 0);
case 'disable':
$success = FALSE;
break;
......
public function sysLog($message, $severity=0) {
t3lib_div::sysLog('Locking [' . $this->method . '::' . $this->id.']: ' . trim($message), 'cms', $severity);
}
/**
* Determines whether a database lock is active.
*
* @return boolean
*/
protected function isDatabaseLockActive() {
return ($GLOBALS['TYPO3_DB']->exec_SELECTcountRows('id', 'sys_lock', 'id=' . $this->resource) != 0);
}
}
(4-4/4)