0008010_v2.patch

Administrator Admin, 2008-04-21 14:43

Download (2.9 KB)

View differences:

t3lib/stddb/tables.sql (Arbeitskopie)
381 381
  KEY parent (pid)
382 382
);
383 383

  
384
#
385
# Table structure for table 'sys_lock'
386
#
387
CREATE TABLE sys_lock (
388
  id varchar(32) DEFAULT '' NOT NULL,
389
  tstamp int(11) unsigned DEFAULT '0' NOT NULL,
390
  PRIMARY KEY (id)
391
) ENGINE=InnoDB;
t3lib/class.t3lib_lock.php (Arbeitskopie)
63 63
	protected $method;
64 64
	protected $id;		// Identifier used for this lock
65 65
	protected $resource;	// Resource used for this lock (can be a file or a semaphore resource)
66
	protected $resourceQuoted;	// The quoted $resource for disposal on databases
66 67
	protected $filepointer;
67 68
	protected $isAcquired = false;
68 69

  
......
95 96
		}
96 97

  
97 98
			// Detect locking method
98
		if (in_array($method, array('disable', 'simple', 'flock', 'semaphore'))) {
99
		if (in_array($method, array('disable', 'simple', 'flock', 'semaphore', 'database'))) {
99 100
			$this->method = $method;
100 101
		} else {
101 102
			throw new Exception('No such method "'.$method.'"');
......
119 120
					$success = true;
120 121
				}
121 122
			break;
123
			case 'database':
124
				$this->resource = $this->id = md5($id);
125
				$this->resourceQuoted = $GLOBALS['TYPO3_DB']->fullQuoteStr($this->resource, 'sys_lock');
126
				$success = true;
127
			break;
122 128
			case 'disable':
123 129
				return false;
124 130
			break;
......
190 196
					$noWait = false;
191 197
				}
192 198
			break;
199
			case 'database':
200
				$i = 0;
201
				while ($i<$this->loops) {
202
					$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_lock', 'id='.$this->resourceQuoted);
203
					if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
204
						$GLOBALS['TYPO3_DB']->sql_free_result($res);
205
						$i++;
206
						usleep($this->step*1000);
207
					} else {
208
						break;
209
					}
210
				}
211
					// If loop was iterated, we had to wait:
212
				if ($i>0) {
213
					$noWait = false;
214
				}
215
					// Setup fields to write to database:
216
				$lockFields = array(
217
					'id' => $this->resource,
218
					'tstamp' => time(),
219
				);
220
					// Insert new record to database:
221
				if ($noWait) {
222
					$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lock', $lockFields);
223
					// Update record in database:
224
				} else {
225
					$GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_lock', 'id='.$this->resourceQuoted, $lockFields);
226
				}
227
				$isAcquired = true;
228
			break;
193 229
			case 'disable':
194 230
				$noWait = false;
195 231
				$isAcquired = false;
......
231 267
					$success = false;
232 268
				}
233 269
			break;
270
			case 'database':
271
				$success = $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lock', 'id='.$this->resourceQuoted);
272
				if (!$success) {
273
					$this->sysLog('The lock to be released did not exist (anymore)');
274
				}
275
			break;
234 276
			case 'disable':
235 277
				$success = false;
236 278
			break;