webCOMAND

cObject::unlock_object()

Unlocks this object in the repository.

This method has no effect (and will return TRUE) if the user does not already possess the lock in this session.

Prototype

bool unlock_object(array $options = [])

Parameters

  • options - Associative array of key/value pairs with the following recognized keys.
    • User - The User (object) to lock on behalf of.  If not provided, the current "user of record" for the object's repository connection will be used.
    • Comment - An optional comment to apply to the lock as it is unlocked.

Return

TRUE if the lock was successfully released, otherwise FALSE.

Example

$repo = comand::repo();
$user = $repo->get_first('FROM User WHERE Username='admin' LIMIT 1');
$contact = $repo->get_first('FROM Contact LIMIT 1');
$locked = $contact->lock_object([
    'Timeout' => 3,   // wait up to 3 seconds to get lock
    'User' => $user, // lock on behalf of admin user
]);
if(!$locked) {
    echo("Could not get lock.\n");
    exit();
}
$contact->LastName = 'New Name';
$contact->approve();
$contact->unlock_object([
    'User' => $user, // unlock on behalf of admin user
]);

Related

lock_object()