0011903_v2.patch

Administrator Admin, 2009-09-10 15:24

Download (12.2 KB)

View differences:

t3lib/config_default.php (Arbeitskopie)
123 123
				'cache_hash' => array(
124 124
					'backend' => 't3lib_cache_backend_DbBackend',
125 125
					'options' => array(
126
						'cacheTable' => 'cache_hash'
126
						'cacheTable' => 'cache_hash',
127
						'tagsTable' => 'cache_hash_tags',
127 128
					)
128 129
				),
129 130
				'cache_pages' => array(
130 131
					'backend' => 't3lib_cache_backend_DbBackend',
131 132
					'options' => array(
132
						'cacheTable' => 'cache_pages'
133
						'cacheTable' => 'cache_pages',
134
						'tagsTable' => 'cache_pages_tags',
133 135
					)
134 136
				),
135 137
				'cache_pagesection' => array(
136 138
					'backend' => 't3lib_cache_backend_DbBackend',
137 139
					'options' => array(
138
						'cacheTable' => 'cache_pagesection'
140
						'cacheTable' => 'cache_pagesection',
141
						'tagsTable' => 'cache_pagesection_tags',
139 142
					)
140 143
				)
141 144
				/*
t3lib/stddb/tables.sql (Arbeitskopie)
124 124
#
125 125
CREATE TABLE cache_hash (
126 126
  id int(11) unsigned NOT NULL auto_increment,
127
  identifier varchar(250) DEFAULT '' NOT NULL,
127
  identifier varchar(128) DEFAULT '' NOT NULL,
128 128
  crdate int(11) unsigned DEFAULT '0' NOT NULL,
129 129
  content mediumtext,
130
  tags mediumtext,
131 130
  lifetime int(11) unsigned DEFAULT '0' NOT NULL,
132 131
  PRIMARY KEY (id),
133 132
  KEY cache_id (identifier)
134 133
) ENGINE=InnoDB;
135 134

  
136 135
#
136
# Table structure for table 'cache_hash_tags'
137
#
138
CREATE TABLE cache_hash_tags (
139
  id int(11) unsigned NOT NULL auto_increment,
140
  identifier varchar(128) DEFAULT '' NOT NULL,
141
  tag varchar(128) DEFAULT '' NOT NULL,
142
  PRIMARY KEY (id),
143
  KEY cache_id (identifier),
144
  KEY cache_tag (tag)
145
) ENGINE=InnoDB;
146

  
147
#
137 148
# Table structure for table 'cache_imagesizes'
138 149
#
139 150
CREATE TABLE cache_imagesizes (
t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php (Arbeitskopie)
33 33
class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend {
34 34

  
35 35
	protected $cacheTable;
36
	protected $tagsTable;
36 37

  
38
	protected $identifierField;
39
	protected $creationField;
40
	protected $lifetimeField;
41
	protected $notExpiredStatement;
42
	protected $tableList;
43
	protected $tableJoin;
44

  
37 45
	/**
46
	 * Constructs this backend
47
	 *
48
	 * @param mixed Configuration options - depends on the actual backend
49
	 */
50
	public function __construct(array $options = array()) {
51
		parent::__construct($options);
52
		$this->initializeCommonReferences();
53
	}
54

  
55
	/**
56
	 * Initializes common references used in this backend.
57
	 *
58
	 * @return	void
59
	 */
60
	protected function initializeCommonReferences() {
61
		$this->identifierField = $this->cacheTable . '.identifier';
62
		$this->creationField = $this->cacheTable . '.crdate';
63
		$this->lifetimeField = $this->cacheTable . '.lifetime';
64
		$this->tableList = $this->cacheTable . ', ' . $this->tagsTable;
65
		$this->tableJoin = $this->identifierField . ' = ' . $this->tagsTable . '.identifier';
66
		$this->notExpiredStatement = '(' . $this->creationField . ' + ' . $this->lifetimeField .
67
			' >= ' . $GLOBALS['EXEC_TIME'] . ' OR ' . $this->lifetimeField . ' = 0)';
68
	}
69

  
70
	/**
38 71
	 * Saves data in a cache file.
39 72
	 *
40 73
	 * @param string An identifier for this specific cache entry
......
73 106
				'identifier' => $entryIdentifier,
74 107
				'crdate'     => $GLOBALS['EXEC_TIME'],
75 108
				'content'    => $data,
76
				'tags'       => implode(',', $tags),
77 109
				'lifetime'   => $lifetime
78 110
			)
79 111
		);
112

  
113
		foreach ($tags as $tag) {
114
			$GLOBALS['TYPO3_DB']->exec_INSERTquery(
115
				$this->tagsTable,
116
				array(
117
					'identifier' => $entryIdentifier,
118
					'tag'        => $tag,
119
				)
120
			);
121
		}
80 122
	}
81 123

  
82 124
	/**
......
117 159
			'content',
118 160
			$this->cacheTable,
119 161
			'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable) . ' '
120
				. 'AND crdate + lifetime >= ' . $GLOBALS['EXEC_TIME']
162
				. 'AND crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0'
121 163
		);
122 164

  
123 165
		if (count($cacheEntries) == 1) {
......
139 181
		$entryRemoved = false;
140 182

  
141 183
		$res = $GLOBALS['TYPO3_DB']->exec_DELETEquery(
142
			$this->cacheTable,
143
			'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable)
184
			$this->tableList,
185
			$this->tableJoin .
186
				' AND ' . $this->identifierField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable),
187
			$this->tableList
144 188
		);
145 189

  
146 190
		if($GLOBALS['TYPO3_DB']->sql_affected_rows($res) == 1) {
......
161 205
		$cacheEntryIdentifiers = array();
162 206

  
163 207
		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
164
			'identifier',
165
			$this->cacheTable,
166
			$this->getListQueryForTag($tag) . ' AND (crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)'
208
			$this->identifierField,
209
			$this->tableList,
210
			$this->getQueryForTag() .
211
				' AND ' . $this->tableJoin .
212
				' AND ' . $this->notExpiredStatement,
213
			$this->identifierField
167 214
		);
168 215

  
169 216
		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
......
186 233
		$whereClause  = array();
187 234

  
188 235
		foreach ($tags as $tag) {
189
			$whereClause[] = $this->getListQueryForTag($tag);
236
			$whereClause[] = $this->getQueryForTag($tag);
190 237
		}
191
		$whereClause[] = '(crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)';
192 238

  
239
		$whereClause[] = $this->tableJoin;
240
		$whereClause[] = $this->notExpiredStatement;
241

  
193 242
		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
194
			'identifier',
195
			$this->cacheTable,
196
			implode(' AND ', $whereClause)
243
			$this->identifierField,
244
			$this->tableList,
245
			implode(' AND ', $whereClause),
246
			$this->identifierField
197 247
		);
198 248

  
199 249
		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
......
211 261
	 */
212 262
	public function flush() {
213 263
		$GLOBALS['TYPO3_DB']->sql_query('TRUNCATE ' . $this->cacheTable);
264
		$GLOBALS['TYPO3_DB']->sql_query('TRUNCATE ' . $this->tagsTable);
214 265
	}
215 266

  
216 267
	/**
......
221 272
	 */
222 273
	public function flushByTag($tag) {
223 274
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
224
			$this->cacheTable,
225
			$this->getListQueryForTag($tag)
275
			$this->tableList,
276
			$this->tableJoin .
277
				' AND ' . $this->getQueryForTag($tag),
278
			$this->tableList
226 279
		);
227 280
	}
228 281

  
......
233 286
	 * @return void
234 287
	 */
235 288
	public function flushByTags(array $tags) {
236
		$listQueryConditions = array();
237
		foreach ($tags as $tag) {
238
			$listQueryConditions[$tag] = $this->getListQueryForTag($tag);
289
		if (count($tags)) {
290
			$listQueryConditions = array();
291
			foreach ($tags as $tag) {
292
				$listQueryConditions[$tag] = $this->getQueryForTag($tag);
293
			}
294
	
295
			$GLOBALS['TYPO3_DB']->exec_DELETEquery(
296
				$this->tableList,
297
				$this->tableJoin .
298
					' AND (' . implode(' OR ', $listQueryConditions) . ')',
299
				$this->tableList
300
			);
239 301
		}
240

  
241
		$listQuery = implode(' OR ', $listQueryConditions);
242
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
243
			$this->cacheTable,
244
			$listQuery
245
		);
246 302
	}
247 303

  
248 304
	/**
......
253 309
	 */
254 310
	public function collectGarbage() {
255 311
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
256
			$this->cacheTable,
257
			'crdate + lifetime < ' . $GLOBALS['EXEC_TIME'] . ' AND lifetime > 0'
312
			$this->tableList,
313
			$this->tableJoin .
314
				' AND ' . $this->cacheTable . '.crdate + ' . $this->cacheTable . '.lifetime < ' . $GLOBALS['EXEC_TIME'] .
315
				' AND ' . $this->cacheTable . '.lifetime > 0',
316
			$this->tableList
258 317
		);
259 318
	}
260 319

  
......
300 359
		}
301 360
*/
302 361
		$this->cacheTable = $cacheTable;
362
		$this->initializeCommonReferences();
303 363
	}
304 364

  
305 365
	/**
......
313 373
	}
314 374

  
315 375
	/**
376
	 * Sets the table where cache tags are stored.
377
	 *
378
	 * @param	string		$tagsTabls: Name of the table
379
	 * @return	void
380
	 */
381
	public function setTagsTable($tagsTable) {
382
		$this->tagsTable = $tagsTable;
383
		$this->initializeCommonReferences();
384
	}
385

  
386
	/**
387
	 * Gets the table where cache tags are store.
388
	 *
389
	 * @return	string		Name of the table storing tags
390
	 */
391
	public function getTagsTable() {
392
		return $this->tagsTable;
393
	}
394

  
395
	/**
316 396
	 * Gets the query to be used for selecting entries by a tag. The asterisk ("*")
317 397
	 * is allowed as a wildcard at the beginning and the end of a tag.
318 398
	 *
......
320 400
	 * @return string the query to be used for selecting entries
321 401
	 * @author Oliver Hader <oliver@typo3.org>
322 402
	 */
323
	protected function getListQueryForTag($tag) {
324
		return str_replace('*', '%', $GLOBALS['TYPO3_DB']->listQuery('tags', $tag, $this->cacheTable));
403
	protected function getQueryForTag($tag) {
404
		if (strpos($tag, '*') === false) {
405
			$query = $this->tagsTable . '.tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable);
406
		} else {
407
			$patternForLike = $GLOBALS['TYPO3_DB']->escapeStrForLike(
408
				$GLOBALS['TYPO3_DB']->quoteStr($tag, $this->tagsTable),
409
				$this->tagsTable
410
			);
411
			$query = $this->tagsTable . '.tag LIKE \'' . $patternForLike . '\'';
412
		}
413

  
414
		return $query;
325 415
	}
326 416
}
327 417

  
t3lib/class.t3lib_db.php (Arbeitskopie)
207 207
	 *
208 208
	 * @param	string		Database tablename
209 209
	 * @param	string		WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
210
	 * @param	string		Comma list of tables to execute deletion on in multi-table context (default: '')
210 211
	 * @return	pointer		MySQL result pointer / DBAL object
211 212
	 */
212
	function exec_DELETEquery($table,$where)	{
213
		$res = mysql_query($this->DELETEquery($table,$where), $this->link);
213
	function exec_DELETEquery($table, $where, $deleteTable = '') {
214
		$res = mysql_query($this->DELETEquery($table,$where, $deleteTable), $this->link);
214 215
		if ($this->debugOutput)	$this->debug('exec_DELETEquery');
215 216
		return $res;
216 217
	}
......
447 448
	 *
448 449
	 * @param	string		See exec_DELETEquery()
449 450
	 * @param	string		See exec_DELETEquery()
451
	 * @param	string		See exec_DELETEquery()
450 452
	 * @return	string		Full SQL query for DELETE
451 453
	 */
452
	function DELETEquery($table,$where)	{
454
	function DELETEquery($table,$where, $deleteTable = '') {
453 455
		if (is_string($where))	{
454 456

  
455 457
				// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
456
			$query = 'DELETE FROM '.$table.
458
			$query = 'DELETE ' . $deleteTable . ' FROM '.$table.
457 459
				(strlen($where)>0 ? '
458 460
				WHERE
459 461
					'.$where : '');
typo3/sysext/cms/ext_tables.sql (Arbeitskopie)
8 8
#
9 9
CREATE TABLE cache_pages (
10 10
  id int(11) unsigned NOT NULL auto_increment,
11
  identifier varchar(250) DEFAULT '' NOT NULL,
11
  identifier varchar(128) DEFAULT '' NOT NULL,
12 12
  crdate int(11) unsigned DEFAULT '0' NOT NULL,
13 13
  content mediumtext,
14
  tags mediumtext,
15 14
  lifetime int(11) unsigned DEFAULT '0' NOT NULL,
16 15
  PRIMARY KEY (id),
17 16
  KEY cache_id (identifier)
......
19 18

  
20 19

  
21 20
#
21
# Table structure for table 'cache_pages_tags'
22
#
23
CREATE TABLE cache_pages_tags (
24
  id int(11) unsigned NOT NULL auto_increment,
25
  identifier varchar(128) DEFAULT '' NOT NULL,
26
  tag varchar(128) DEFAULT '' NOT NULL,
27
  PRIMARY KEY (id),
28
  KEY cache_id (identifier),
29
  KEY cache_tag (tag)
30
) ENGINE=InnoDB;
31

  
32

  
33
#
22 34
# Table structure for table 'cache_pagesection'
23 35
#
24 36
CREATE TABLE cache_pagesection (
25 37
  id int(11) unsigned NOT NULL auto_increment,
26
  identifier varchar(250) DEFAULT '' NOT NULL,
38
  identifier varchar(128) DEFAULT '' NOT NULL,
27 39
  crdate int(11) unsigned DEFAULT '0' NOT NULL,
28 40
  content mediumtext,
29
  tags mediumtext,
30 41
  lifetime int(11) unsigned DEFAULT '0' NOT NULL,
31 42
  PRIMARY KEY (id),
32 43
  KEY cache_id (identifier)
......
34 45

  
35 46

  
36 47
#
48
# Table structure for table 'cache_pagesection_tags'
49
#
50
CREATE TABLE cache_pagesection_tags (
51
  id int(11) unsigned NOT NULL auto_increment,
52
  identifier varchar(128) DEFAULT '' NOT NULL,
53
  tag varchar(128) DEFAULT '' NOT NULL,
54
  PRIMARY KEY (id),
55
  KEY cache_id (identifier),
56
  KEY cache_tag (tag)
57
) ENGINE=InnoDB;
58

  
59

  
60
#
37 61
# Table structure for table 'cache_typo3temp_log'
38 62
#
39 63
CREATE TABLE cache_typo3temp_log (