Class: Lock

A simple locking mechanism for ensuring users don't edit the same object at the same time.

Usage:

$lock = new Lock ('type', 'id');
if ($lock->exists ()) {
    echo $tpl->render ('admin/locked', $lock->info ());
    return;
} else {
    $lock->add ();
}

// on save:
$lock->remove ();

// when logging an admin out:
Lock::clear ();

Fields:

id user resource resource_id expires created modified

Properties

public $timeout = 2400

The lock timeout. Defaults to 40 minutes.

public $error = false

The error message if an error occurs, or false if no errors.

public $resource = false

The type of resource being locked.

public $key = false

The unique ID of the resource being locked.

Methods

public __construct ($resource = false, $key = false)

Constructor.

public add ($resource = false, $key = false)

Create a lock on the specified object.

public exists ($resource = false, $key = false)

Check whether a lock is held on an object by someone other than the current user.

public info ($resource = false, $key = false)

Get the info about a lock.

public update ($resource = false, $key = false)

Update the expiry and modification time of an existing lock.

public remove ($resource = false, $key = false)

Remove a specific lock.

public static clear ()

Clear all locks held by the current user.

public static clear_all ()

Clear all locks.