Project

General

Profile

Feature #18239 » 0007572-TSFE-sys_lockedrecords-v2.patch

Administrator Admin, 2008-10-29 13:41

View differences:

typo3/sysext/cms/tslib/class.tslib_fe.php (Arbeitskopie)
/********************************************
*
* 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 (optional)
* @return boolean Success = True
*/
public function setRecordEditLock($table='', $uid=0, $pid=0) {
$success = False;
if ($this->loginUser) {
$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' => intval($uid),
'username' => $this->fe_user->user['username'],
'record_pid' => intval($pid),
'feuserid' => $feuser_id
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lockedrecords', $fields_values);
$success = !$GLOBALS['TYPO3_DB']->sql_error();
}
}
}
return ($success);
}
/**
* 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 boolean Success = True
*/
public function removeRecordEditLocks($table='', $uid=0) {
$success = False;
if ($this->loginUser) {
$feuser_id = intval($this->fe_user->user['uid']);
if ($feuser_id) {
if ($table && $uid) {
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'feuserid='.$feuser_id.' AND record_uid='.intval($uid).
' AND record_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_lockedrecords'));
} else {
$GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'feuserid='.$feuser_id);
}
$success = !$GLOBALS['TYPO3_DB']->sql_error();
}
}
return ($success);
}
/**
* 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 in BE is not strictly carried out since locking is abandoned when other scripts are activated - which means that a BE-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
* @param mixed if array: information[locks]: array of records found in table 'sys_lockedrecords'
* information[locks]: 0=unlocked, -1=locked by same FeUser, 1=locked by other FeUser
* information[message] contains textual message, if returnvalue[locked]!=0
* if other: information contains textual message
* @return integer locktype: 0=unlocked, -1=locked by same FeUser, 1=locked by other FeUser or BeUser
*/
public function getRecordEditLockState($table, $uid, &$information=NULL) {
$recordLockState = 0;
$recordLockMessage = '';
$locks = array();
if ($this->loginUser && 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).' AND record_uid='.intval($uid).
' AND record_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_lockedrecords'),
'', 'sys_lockedrecords.tstamp DESC'
);
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'));
$row['lockmessage'] = 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'))
);
$row['lockstate'] = ($row['feuserid']==intval($this->fe_user->user['uid'])) ? -1 : 1;
// if more than one locks exist AND the active feuser AND other fe/beusers have locked this record: newest lock of other user takes precedence
if ($recordLockState<1) {
$recordLockState = $row['lockstate'];
$recordLockMessage = $row['lockmessage'];
}
$locks[] = $row;
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
}
}
if (is_array($information)) {
$information['locks'] = $locks;
$information['lockstate'] = $recordLockState;
$information['lockmessage'] = $recordLockMessage;
} else {
$information = $recordLockMessage;
}
return ($recordLockState);
}
......
/*********************************************
*
* Localization and character set conversion
(3-3/4)