Bug #14945
closedBE: TCEMAIN.clearCacheCmd doesn't work when deleting records
0%
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
Updated by Thomas Peterson about 19 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.
Updated by Guillaume Crico about 19 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...
Updated by Sebastian Kurfuerst about 19 years ago
the attached patch should fix the problem by clearing the cache before deleting the record. greets, sebastian
Updated by Sebastian Kurfuerst about 19 years ago
the current version doesn't take clearCacheCmd into account. will provide a fix for this.
Updated by Sebastian Kurfuerst about 19 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
Updated by Robert von about 19 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 ).
Updated by Sebastian Kurfuerst about 19 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