Skip to content
Permalink
Browse files

improved editing log type for status-changing types; updates #1140

- discarded the feature that admins can do status changing edits of logs
  which are not the last log (could produce wrong cache status)

- disable status-changing log type edits for logs older than half a year

- adjust cache status when changing the log type from status-changing to
  non-status-changing
  • Loading branch information...
following5 committed Sep 30, 2017
1 parent d993c3e commit 38ab7700e7422784c8844dcfc021212b6c222697
Showing with 73 additions and 38 deletions.
  1. +7 −21 htdocs/editlog.php
  2. +65 −16 htdocs/lib2/logic/cache.class.php
  3. +1 −1 htdocs/log.php
@@ -268,23 +268,12 @@
$log_id
);
// update cache status if changed by logtype
if ($cache->isLatestLog($log_record['log_id'])) {
$newStatus = sql_value(
"SELECT `cache_status` FROM `log_types`
WHERE `id`='&1'",
false,
$log_type
);
if ($newStatus && $newStatus != $log_record['status']) {
sql("SET @STATUS_CHANGE_USER_ID='&1'", $login->userid);
sql(
"UPDATE `caches` SET `status`='&2'
WHERE `cache_id`='&1'",
$log_record['cache_id'],
$newStatus
);
}
// Update cache status if changed by logtype. To keep things simple, we implement
// this feature only for the latest log.
$statusChangeAllowed = $cache->statusChangeAllowedForLog($log_record['log_id']);
if ($statusChangeAllowed) {
$cache->updateCacheStatusFromLatestLog($log_id, $log_record['logtype'], $log_type);
$cache->save();
}
// update user-stat if type changed
@@ -334,10 +323,7 @@
// build logtype options
$disable_statuschange = (
$log_record['cache_user_id'] == $login->userid
&& !$cache->isLatestLog($log_record['log_id'])
);
$disable_statuschange = !$cache->statusChangeAllowedForLog($log_record['log_id']);
$disable_typechange = $disable_statuschange && $log_record['is_status_log'];
$tpl->assign('typeEditDisabled', $disable_typechange);
@@ -897,7 +897,6 @@ public function removeRecommendation($nUserId)
sql("DELETE FROM `cache_rating` WHERE `cache_id`='&1' AND `user_id`='&2'", $this->nCacheId, $nUserId);
}
// retrieves admin cache history data and stores it to template variables
// for display by adminhistory.tpl and adminreports.tpl
public function setTplHistoryData($exclude_report_id)
@@ -1026,29 +1025,79 @@ public function setTplHistoryData($exclude_report_id)
sql_free_result($rs);
}
public function logTypeAllowed($logType, $oldLogType = 0)
{
// check if given logType is valid for this cache type
return logtype_ok($this->getCacheId(), $logType, $oldLogType);
}
public function updateCacheStatus($logType)
/**
* @param int $logId
* @param int $oldLogType
* @param int $newLogType
*/
public function updateCacheStatusFromLatestLog($logId, $oldLogType, $newLogType)
{
// get cache status
$cacheStatus = sql_value(
"SELECT `cache_status` FROM `log_types` WHERE `id`='&1'",
0,
$logType
);
// set status, if not 0
if ($cacheStatus != 0) {
$this->setStatus($cacheStatus);
if ($newLogType != $oldLogType) {
// get new cache-status property of the new log type
$cacheStatus = sql_value(
"SELECT `cache_status` FROM `log_types` WHERE `id`='&1'",
0,
$newLogType
);
if ($cacheStatus != 0) {
// If the new log type is a status-changing type, it's easy -
// we can directly change the cache status:
$this->setStatus($cacheStatus);
} else {
// If the new log type is not status-changing, but the old type was, the
// cache status may need to be recalculated. To keep things simple, we will
// always recalculate the cache status in this case.
$cacheStatus = sql_value(
"SELECT `cache_status` FROM `log_types` WHERE `id`='&1'",
0,
$oldLogType
);
if ($cacheStatus != 0) {
// The only safe way to restore an old cache status is from table
// cache_status_modified. This is available since April 2013. As we
// do not allow status-changes by editing logs that are older than
// half a year, this is ok.
// The cache status is updated in a separate operation immediatly
// (usually within a millisecond or so) after saving a log, so we must
// apply some time lag to be on the safe side. It should be safe to
// assume that users will not edit the log type twice within <= 2 seconds:
$logCreated = sql_value(
"SELECT `date_created` FROM `cache_logs` WHERE `id`='&1'",
null,
$logId
);
$oldCacheStatus = sql_value(
"SELECT `old_state`
FROM `cache_status_modified`
WHERE `cache_id`='&1'
AND '&2' <= `date_modified`
AND TIMESTAMPDIFF(SECOND, '&2', `date_modified`) <= 2
ORDER BY `date_modified` DESC
LIMIT 1",
0,
$this->getCacheId(),
$logCreated
);
if ($oldCacheStatus > 0) {
$this->setStatus($oldCacheStatus);
}
}
}
}
}
// $userLogType:
// Logtype selected by the user, or null if not applicable
@@ -1098,11 +1147,11 @@ public function statusUserLogAllowed()
* @param $logId
* @return bool
*/
public function isLatestLog($logId)
public function statusChangeAllowedForLog($logId)
{
$latestLogId = sql_value(
"SELECT `id` FROM `cache_logs`
WHERE `cache_id`='&1'
WHERE `cache_id`='&1' AND DATEDIFF(NOW(), `date_created`) < 180
ORDER BY `order_date` DESC, `date_created` DESC, `id` DESC
LIMIT 1",
0,
@@ -281,7 +281,7 @@
$cacheLog->save();
// update cache status
$cache->updateCacheStatus($logType);
$cache->updateCacheStatusFromLatestLog($cacheLog->getLogId(), 0, $logType);
// update rating (if correct log type, user has ratings to give
// and is not owner (expect owner adopted cache))

0 comments on commit 38ab770

Please sign in to comment.
You can’t perform that action at this time.