function _apdqc_lock_change_lock_id in Asynchronous Prefetch Database Query Cache 7
Change the lock id.
Parameters
string $name: Name of the lock.
string $old_lock_id: Value from _lock_id().
string $new_lock_id: New value for the 'value' column in the database.
Related topics
1 call to _apdqc_lock_change_lock_id()
- apdqc.lock.inc in ./
apdqc.lock.inc - A database-mediated implementation of a locking mechanism.
1 string reference to '_apdqc_lock_change_lock_id'
- apdqc.lock.inc in ./
apdqc.lock.inc - A database-mediated implementation of a locking mechanism.
File
- ./
apdqc.lock.db.inc, line 389 - A database-mediated implementation of a locking mechanism.
Code
function _apdqc_lock_change_lock_id($name, $old_lock_id, $new_lock_id) {
global $locks;
// Build query.
$query = \Database::getConnection()
->prefixTables("\n UPDATE {" . db_escape_table('semaphore') . "}\n SET value = '" . apdqc_escape_string($new_lock_id) . "'\n WHERE name = '" . apdqc_escape_string($name) . "'\n AND value = '" . apdqc_escape_string($old_lock_id) . "'\n ");
// Run Query.
$results = apdqc_query(array(
'semaphore',
), array(
$name,
), $query, array(
'get_affected_rows' => TRUE,
));
if (!is_string($results) || $results !== 'NO DB') {
$success = (bool) $results;
}
else {
// Try to extend the expiration of a lock we already acquired.
$success = (bool) db_update('semaphore')
->fields(array(
'value' => $new_lock_id,
))
->condition('name', $name)
->condition('value', $old_lock_id)
->execute();
if (!$success) {
// The lock was broken.
unset($locks[$name]);
}
}
return $success;
}