Project

General

Profile

Feature #18557 » 0008010_v2.patch

Administrator Admin, 2008-04-21 14:43

View differences:

t3lib/stddb/tables.sql (Arbeitskopie)
KEY parent (pid)
);
#
# Table structure for table 'sys_lock'
#
CREATE TABLE sys_lock (
id varchar(32) DEFAULT '' NOT NULL,
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
t3lib/class.t3lib_lock.php (Arbeitskopie)
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 $resourceQuoted; // The quoted $resource for disposal on databases
protected $filepointer;
protected $isAcquired = false;
......
}
// 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->resource = $this->id = md5($id);
$this->resourceQuoted = $GLOBALS['TYPO3_DB']->fullQuoteStr($this->resource, 'sys_lock');
$success = true;
break;
case 'disable':
return false;
break;
......
$noWait = false;
}
break;
case 'database':
$i = 0;
while ($i<$this->loops) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_lock', 'id='.$this->resourceQuoted);
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$GLOBALS['TYPO3_DB']->sql_free_result($res);
$i++;
usleep($this->step*1000);
} else {
break;
}
}
// If loop was iterated, we had to wait:
if ($i>0) {
$noWait = false;
}
// Setup fields to write to database:
$lockFields = array(
'id' => $this->resource,
'tstamp' => time(),
);
// Insert new record to database:
if ($noWait) {
$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lock', $lockFields);
// Update record in database:
} else {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_lock', 'id='.$this->resourceQuoted, $lockFields);
}
$isAcquired = true;
break;
case 'disable':
$noWait = false;
$isAcquired = false;
......
$success = false;
}
break;
case 'database':
$success = $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lock', 'id='.$this->resourceQuoted);
if (!$success) {
$this->sysLog('The lock to be released did not exist (anymore)');
}
break;
case 'disable':
$success = false;
break;
(3-3/4)