X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=Lock.php;h=b0e7ea9a2c05f14b13dd6e4ca26feb2eb1ed77be;hp=d9a99f582ea6a092914e0c75cd052355220e53b4;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=84ce7af846d302d19025870107565a438000e90b diff --git a/Lock.php b/Lock.php index d9a99f58..b0e7ea9a 100644 --- a/Lock.php +++ b/Lock.php @@ -48,7 +48,7 @@ class Pman_Core_Lock extends Pman return true; } - function get($action) + function get($action, $opts=array()) { // should we allow url links to lock things??? // only for debugging?? @@ -72,7 +72,7 @@ class Pman_Core_Lock extends Pman if (empty($_REQUEST['id'])) { $this->jerr("No lock id"); } - $curlock = DB_DataObject::factory('Core_locking'); + $curlock = DB_DataObject::factory('core_locking'); if (!$curlock->get($_REQUEST['id'])) { $this->jok("No lock exists"); // been deleted before.. probably ok.. } @@ -93,28 +93,46 @@ class Pman_Core_Lock extends Pman $this->jerr("Missing table or id"); } - $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection?? + $tab = str_replace('/', '', strtolower($_REQUEST['on_table'])); // basic protection?? $x = DB_DataObject::factory($tab); if (!$x->get($_REQUEST['on_id'])) { $this->jerr("Item does not exist"); } // is there a current lock on the item.. - $curlock = DB_DataObject::factory('Core_locking'); + $curlock = DB_DataObject::factory('core_locking'); $curlock->setFrom(array( 'on_id' => $_REQUEST['on_id'], - 'on_table' => $_REQUEST['on_table'] + 'on_table' => strtolower($_REQUEST['on_table']) )); + // remove old locks.. + $llc = clone($curlock); + $exp = date('Y-m-d', strtotime('NOW - 1 WEEK')); + $llc->whereAdd("created < '$exp'"); + if ($llc->count()) { + $llc->find(); + while($llc->fetch()) { + $llcd = clone($llc); + $llcd->delete(); + + } + } + + $curlock_ex = clone($curlock); - $curlock_ex->whereAdd('person_id != '. $this->authUser->id); + $curlock->person_id = $this->authUser->id; + $curlock_ex->whereAdd('person_id != '. $this->authUser->id); $nlocks = $curlock_ex->count() ; + + $ret = false; + if ($nlocks && empty($_REQUEST['force'])) { // DB_DataObjecT::debugLevel(1); - $ar = $curlock->fetchAll('person_id', 'created'); - $p = DB_DataObject::factory('Person'); + $ar = $curlock_ex->fetchAll('person_id', 'created'); + $p = DB_DataObject::factory('core_person'); $p->selectAdd(); $p->selectAdd('id,name,email'); @@ -125,30 +143,47 @@ class Pman_Core_Lock extends Pman $ret[$p->id] = $p->toArray(); $ret[$p->id]['lock_created'] = $ar[$p->id]; } - $this->jok(array_values($ret)); + $this->jok(array_values($ret)); } - $nlocks = $curlock->count(); - if ($nlocks) { + // trash the lock if it belongs to current user.. + $ulocks = $curlock->count(); + if ($ulocks) { // trash all the locks.. + $curlock = DB_DataObject::factory('core_locking'); + $curlock->setFrom(array( + 'on_id' => $_REQUEST['on_id'], + 'on_table' => strtolower($_REQUEST['on_table']), + 'person_id' => $this->authUser->id + )); + $curlock->find(); while($curlock->fetch()) { $cc =clone($curlock); $cc->delete(); } } + if ($nlocks && !empty($_REQUEST['force'])) { + // user has decied to delete eveyone elses locks.. + $curlock_ex->find(); + while($curlock_ex->fetch()) { + $cc =clone($curlock_ex); + $cc->delete(); + } + } + // make a lock.. - $curlock = DB_DataObject::factory('Core_locking'); + $curlock = DB_DataObject::factory('core_locking'); $curlock->setFrom(array( 'on_id' => $_REQUEST['on_id'], - 'on_table' => $_REQUEST['on_table'], + 'on_table' => strtolower($_REQUEST['on_table']), 'created' => date('Y-m-d H:i:s'), 'person_id' => $this->authUser->id, )); $id = $curlock->insert(); - $this->jok($id); + $this->jok( $id); }