Project

General

Profile

Actions

Bug #14945

closed

BE: TCEMAIN.clearCacheCmd doesn't work when deleting records

Added by Robert von over 18 years ago. Updated almost 18 years ago.

Status:
Closed
Priority:
Should have
Category:
-
Target version:
-
Start date:
2005-08-26
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
3.8.0
PHP Version:
4
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Page TSConfig TCEMAIN.clearCacheCmd = pid#1, pid#2, ... , pid#n works only inserting new records or updating existing records.

IMHO,

this issue is related with: t3lib_BEfunc::getRecord.
As a matter of fact, when deleting a record, method 'deleteRecord' from class t3lib_TCEmain is used.
At the end of 'deleteRecord' another method of t3lib_TCEmain is used: '$this->clear_cache($table,$uid)'.
'$this->clear_cache($table,$uid)' calls 't3lib_BEfunc::getTSCpid'.
't3lib_BEfunc::getTSCpid' consequently uses 't3lib_BEfunc::getTSconfig_pidValue', which calls
't3lib_BEfunc::getRecord'.

Finally: in t3lib_BEfunc::getRecord there's a 'where' clause with 't3lib_BEfunc::deleteClause($table)', complete line:

$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).t3lib_BEfunc::deleteClause($table).$where);

So, when a record is deleted '$this->clear_cache($table,$uid)' and subsequent are called after SQL statement which marks a record as deleted.
t3lib_BEfunc::getRecord returns -1 because it can't find a record just deleted!

At this moment i solved (just to make it work!) inserting '$this->clear_cache($table,$uid)' before SQL statement, but i don't like it at all!!
Any idea to solve it better ?

(issue imported from #M1407)


Files

bug_1407.diff (413 Bytes) bug_1407.diff Administrator Admin, 2005-09-10 19:59
2005-10-20_bugfix_1407.patch (920 Bytes) 2005-10-20_bugfix_1407.patch Administrator Admin, 2005-10-20 15:04
Actions #1

Updated by Thomas Peterson over 18 years ago

This SelectQuery has no result, because this deleteclause return with deleted=0 but the datarow is deleted and has deleted=1

$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).t3lib_BEfunc::deleteClause($table).$where);

When i correct this function in t3lib/class.t3lib_befunc.php from:
function deleteClause($table) {
global $TCA;
if ($TCA[$table]['ctrl']['delete']) {
return ' AND '.$table.'.'.$TCA[$table]['ctrl']['delete'].'=0';
} else {
return '';
}
}

in:
function deleteClause($table) {
global $TCA;
if ($TCA[$table]['ctrl']['delete']) {
return ' AND '.$table.'.'.$TCA[$table]['ctrl']['delete'].'=1';
} else {
return '';
}
}

works it.

Actions #2

Updated by Guillaume Crico over 18 years ago

The TSConfig doc says about clearCacheCmd :
"...cleared when saving to some page or branch of the page tree..."

I do agree that "deleting" is some kind of "saving" in this case...

We DO must call the clear cache BEFORE the delete query :
if the record has no "delete column", the record will be really deleted from the table, and, as the t3lib_befunc::getRecord() fetch the pid AFTER the deletion, we'll never fetch any pid...

But if we call the clear cache before the delete query :
If the delete query is aborted (aka no permission), the page's cache is flushed "for nothing"... I think this is not a big issue. (Am I wrong ? any DOS risk ?)

As I was already XCLASSing TCEmain in an extension, so I add this code to my "(ux_)*t3lib_TCEmain()" XCLASS :
function deleteRecord($table,$uid, $noRecordCheck) {
$this->clear_cache($table, $uid);
parent::deleteRecord($table, $uid, $noRecordCheck);
}

As XClassing tcemain can have some dependency conflict,
we could easily make an "clearCacheCmd_ON_DELETE" extension registering a hook class in :
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']
and providing a method :
function processCmdmap_preProcess($command, $table, $id, &$value, &$tcemain) {
if ($command == 'delete') {
$this->clear_cache($table, $id);
}
}
}

When I'll have the time...

Actions #3

Updated by Sebastian Kurfuerst over 18 years ago

the attached patch should fix the problem by clearing the cache before deleting the record. greets, sebastian

Actions #4

Updated by Sebastian Kurfuerst over 18 years ago

the current version doesn't take clearCacheCmd into account. will provide a fix for this.

Actions #5

Updated by Sebastian Kurfuerst over 18 years ago

I just checked again and can confirm that the little bugfix solves the clearCacheCMD problem as well, clearCacheCMD is taken into account as well. The interesting lines can be found in tcemain->clear_cache at the bottom of this function.
greets, sebastian

Actions #6

Updated by Robert von over 18 years ago

It could be interesting to discuss in depth about "flushing for nothing", as Guillaume Crico pointed in his note (see note 0002943 above ).

Actions #7

Updated by Sebastian Kurfuerst over 18 years ago

I don't see any issue in the "flushing for nothing" issue, as it for example cannot be triggered in the frontend. Greets, Sebastian

Actions #8

Updated by Sebastian Kurfuerst over 18 years ago

fixed in CVS.

Actions

Also available in: Atom PDF