Object locks
Today I published anticipated object locking to MidCOM 2.9 trunk. This feature is familiar for those that have been hanging around in the times of MidCOM 2.4 and before, but unfortunately not in MidCOM 2.6 and so far in MidCOM 2.8.
Concept itself is simple: when someone is editing an object, it is marked as locked. If someone else tries to edit the same object at the same time, it will be prevented. Lock will expire by itself in configurable amount of minutes and the object will be unlocked, when the object is either saved or editing has been cancelled. These are implemented by default already in midcom.helper.datamanager2, which should cover most of the editing.
If you by any chance want to use the features to anything, here is a quick HOWTO:
Check if the object is locked
When you have a MidCOM dbobject at hand, you can check it e.g. like this:
get_metadata();
if ($metadata->is_locked())
{
// Object is locked
}
else
{
// Object is not locked
}
?>
Locking and unlocking an object
To lock and unlock and object do the following:
get_metadata();
// Lock the object
$metadata->lock();
// Unlock the object
$metadata->unlock();
?>
If using PHP5
One more reasons why to update. PHP5 has neat features for using methods of the returned object on the fly:
get_metadata()->is_locked())
{
// Object is locked
}
// Lock
$object->get_metadata()->lock();
// Unlock
$object->get_metadata()->unlock();
?>