function content_lock_timeout_cron in Content locking (anti-concurrent editing) 7
Same name and namespace in other branches
- 8.2 modules/content_lock_timeout/content_lock_timeout.module \content_lock_timeout_cron()
- 8 modules/content_lock_timeout/content_lock_timeout.module \content_lock_timeout_cron()
- 6.2 modules/content_lock_timeout/content_lock_timeout.module \content_lock_timeout_cron()
- 6 modules/content_lock_timeout/content_lock_timeout.module \content_lock_timeout_cron()
- 7.3 modules/content_lock_timeout/content_lock_timeout.module \content_lock_timeout_cron()
- 7.2 modules/content_lock_timeout/content_lock_timeout.module \content_lock_timeout_cron()
Implementation of hook_cron().
Breaks batches of stale locks whenever the cron hooks are run. Inspired by original content_lock_cron() (leftover from the checkout module).
File
- modules/
content_lock_timeout/ content_lock_timeout.module, line 57 - Allowed time-based automatic unlocking of nodes locked for editing with content_lock.
Code
function content_lock_timeout_cron() {
$timeout_minutes = variable_get('content_lock_timeout_minutes', 30);
$last_valid_time = time() - 60 * $timeout_minutes;
// We call content_lock_release() for each lock so that the
// hook_content_lock_released may be invoked.
$query = db_select('content_lock', 'c')
->fields('c', array(
'nid',
))
->condition('c.timestamp', $last_valid_time, '<');
$count = 0;
foreach ($query
->execute() as $obj) {
content_lock_release($obj->nid);
$count++;
}
if ($count) {
$period = format_interval($timeout_minutes * 60);
watchdog('content_lock_timeout', 'Released @count stale node locks which lasted at least @period.', array(
'@count' => $count,
'@period' => $period,
));
}
}