Project

General

Profile

Feature #18239 » 07572-TSFE-sys_lockedrecords.patch

Administrator Admin, 2008-02-18 11:29

View differences:

typo3/sysext/cms/tslib/class.tslib_fe.php (working copy)
}
/********************************************
*
* FE-User editing functions - for use in plugins etc.
*
*******************************************/
/**
* Lock a record from $table with $uid
*
* @param string Table name
* @param integer Record uid
* @param integer Record pid
* @return void
*/
function lockRecords($table='',$uid=0,$pid=0) {
$feuser_id = intval($this->fe_user->user['uid']);
if ($feuser_id) {
if ($table && $uid) {
$fields_values = array(
'userid' => 0,
'tstamp' => $GLOBALS['EXEC_TIME'],
'record_table' => $table,
'record_uid' => $uid,
'username' => $this->fe_user->user['username'],
'record_pid' => $pid,
'feuserid' => $feuser_id
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lockedrecords', $fields_values);
}
}
}
/**
* Unlock a record from $table with $uid
* If $table and $uid is not set, then all locking for the current BE_USER is removed!
*
* @param string Table name
* @param integer Record uid
* @return void
*/
function unLockRecords($table='',$uid=0) {
$feuser_id = intval($this->fe_user->user['uid']);
if ($feuser_id) {
if ($table && $uid) {
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'feuserid='.intval($feuser_id).' AND record_uid='.$uid.' AND record_table=\''.$table.'\'');
} else {
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'feuserid='.intval($feuser_id));
}
}
}
/**
* Returns information about whether the record from table, $table, with uid, $uid is currently locked (edited by another user - which should issue a warning).
* Notice: Locking is not strictly carried out since locking is abandoned when other backend scripts are activated - which means that a user CAN have a record "open" without having it locked. So this just serves as a warning that counts well in 90% of the cases, which should be sufficient.
*
* @param string Table name
* @param integer Record uid
* @return array returnvalue[locked] 0=unlocked, -1=locked by same FeUser, 1=locked by other FeUser
* returnvalue[msg] contains textual message, if returnvalue[locked]!=0
*/
function isRecordLocked($table,$uid) {
global $LOCKED_FE_RECORDS;
if (intval($this->fe_user->user['uid'])) {
// first: remove all old records !
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'feuserid > 0 AND sys_lockedrecords.tstamp < '.($GLOBALS['EXEC_TIME']-8*3600));
if (!is_array($LOCKED_FE_RECORDS)) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
'sys_lockedrecords',
'sys_lockedrecords.tstamp > '.($GLOBALS['EXEC_TIME']-2*3600)
);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$tmpUserType = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.'.($row['userid'] ? 'beUser' : ($row['feuserid'] ? 'feUser' : 'user') ) );
$tmpUserName = ($row['username'] ? $row['username'] : $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.unknownUser'));
$LOCKED_FE_RECORDS[$row['record_table'].':'.$row['record_uid']]=$row;
$LOCKED_FE_RECORDS[$row['record_table'].':'.$row['record_uid']]['msg']=sprintf(
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecordUser'),
$tmpUserType,$tmpUserName,
t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
);
if ($row['record_pid'] && !isset($LOCKED_FE_RECORDS[$row['record_table'].':'.$row['record_pid']])) {
$LOCKED_FE_RECORDS['pages:'.$row['record_pid']]['msg']=sprintf(
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecordUser_content'),
$tmpUserType,$tmpUserName,
t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
);
}
}
}
$tmp = $LOCKED_FE_RECORDS[$table.':'.$uid];
if (is_array($tmp)) {
if ($tmp['feuserid']==intval($this->fe_user->user['uid'])) {
$tmp['locked'] = -1;
} else {
$tmp['locked'] = 1;
}
} else {
$tmp = array('locked'=>0);
}
return $tmp;
} else {
return array('locked'=>0);
}
}
......
/********************************************
*
* Various external API functions - for use in plugins etc.
(1-1/4)