From: Alan Knowles Date: Thu, 18 Nov 2010 09:23:16 +0000 (+0800) Subject: Lock.php X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=commitdiff_plain;h=9dcaca964f98153cba6d59593e40848a6f274a2d Lock.php --- diff --git a/Lock.php b/Lock.php index b06a262d..62e7ea33 100644 --- a/Lock.php +++ b/Lock.php @@ -17,6 +17,14 @@ * -- interacts with Roo and _lock = id.. * * + * call : + * try and lock it.. + * baseURL + /Core/Lock/lock?on_id=...&on_table=... + * - returns id or an array of who has the locks. + * + * baseURL + /Core/Lock/lock?on_id=...&on_table=...&force=1 + * - returns id.. + * */ require_once 'Pman.php'; @@ -88,19 +96,32 @@ class Pman_Core_Lock extends Pman )); - - if ($curlock->count() && empty($_REQUEST['force'])) { + $nlocks = $curlock->count() + if ($nlocks && empty($_REQUEST['force'])) { $curlock->selectAdd(); - $curlock->selectAdd('distinct(person_id)'); - $ar = $curlock->fetchAll('person_id'); - $p = DB_DataObject::factory('Person'); + $curlock->selectAdd('distinct(person_id), created'); - $err = $this->canUnlock(); - if ($err !== true) { - $this->jerr($err); + $ar = $curlock->fetchAll('person_id', 'created'); + $p = DB_DataObject::factory('Person'); + $p->whereAddIn('id', $ar, 'int'); + $p->find(); + while ($p->fetch()) { + $ret[$p->id] = $p->toRooArray(); + $ret[$p->id]->lock_created = $ar[$p->id]; + } + $this->jok($ret); + + } + if ($nlocks) { + // trash all the locks.. + $curlock->find(); + while($curlock->fetch()) { + $cc =clone($curlock); + $cc->delete(); } } + // make a lock.. $curlock = DB_DataObject::factory('Core_locking');