Skip to content
Snippets Groups Projects
Commit be3b6894 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #323 from protich/feature/locks-revisited

Feature/locks revisited
parents aebdda7c 3c8b1111
No related branches found
No related tags found
No related merge requests found
......@@ -181,12 +181,10 @@ class TicketsAjaxAPI extends AjaxController {
function acquireLock($tid) {
global $cfg,$thisstaff;
if(!$tid or !is_numeric($tid) or !$thisstaff or !$cfg)
if(!$tid or !is_numeric($tid) or !$thisstaff or !$cfg or !$cfg->getLockTime())
return 0;
$ticket = Ticket::lookup($tid);
if(!$ticket || !$ticket->checkStaffAccess($thisstaff))
if(!($ticket = Ticket::lookup($tid)) || !$ticket->checkStaffAccess($thisstaff))
return $this->json_encode(array('id'=>0, 'retry'=>false, 'msg'=>'Lock denied!'));
//is the ticket already locked?
......@@ -198,17 +196,13 @@ class TicketsAjaxAPI extends AjaxController {
//Ticket already locked by staff...try renewing it.
$lock->renew(); //New clock baby!
return $this->json_encode(array('id'=>$lock->getId(), 'time'=>$lock->getTime()));
} elseif(!($lock=$ticket->acquireLock($thisstaff->getId(),$cfg->getLockTime()))) {
//unable to obtain the lock..for some really weired reason!
//Client should watch for possible loop on retries. Max attempts?
return $this->json_encode(array('id'=>0, 'retry'=>true));
}
//Ticket is not locked or the lock is expired...try locking it...
if($lock=$ticket->acquireLock($thisstaff->getId(),$cfg->getLockTime())) //Set the lock.
return $this->json_encode(array('id'=>$lock->getId(), 'time'=>$lock->getTime()));
//unable to obtain the lock..for some really weired reason!
//Client should watch for possible loop on retries. Max attempts?
return $this->json_encode(array('id'=>0, 'retry'=>true));
return $this->json_encode(array('id'=>$lock->getId(), 'time'=>$lock->getTime()));
}
function renewLock($tid, $id) {
......
......@@ -88,7 +88,7 @@ class TicketLock {
function renew($lockTime=0) {
if(!$lockTime || !is_numeric($lockTime)) //XXX: test to make it works.
$lockTime = '(TIME_TO_SEC(TIMEDIFF(created,expire))/60)';
$lockTime = '(TIME_TO_SEC(TIMEDIFF(expire,created))/60)';
$sql='UPDATE '.TICKET_LOCK_TABLE
......
......@@ -366,6 +366,7 @@ if(!$cfg->showNotesInline()) { ?>
<?php csrf_token(); ?>
<input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>">
<input type="hidden" name="msgId" value="<?php echo $msgId; ?>">
<input type="hidden" name="locktime" value="<?php echo $cfg->getLockTime(); ?>">
<input type="hidden" name="a" value="reply">
<span class="error"></span>
<table border="0" cellspacing="0" cellpadding="3">
......
......@@ -93,13 +93,18 @@ var autoLock = {
Init: function(config) {
//make sure we are on ticket view page!
void(autoLock.form=document.forms['reply']);
if(!autoLock.form || !autoLock.form.id.value) {
return;
//make sure we are on ticket view page & locking is enabled!
var fObj=$('form#reply');
if(!fObj
|| !$(':input[name=id]',fObj).length
|| !$(':input[name=locktime]',fObj).length
|| $(':input[name=locktime]',fObj).val()==0) {
return;
}
void(autoLock.tid=parseInt(autoLock.form.id.value));
void(autoLock.tid=parseInt($(':input[name=id]',fObj).val()));
void(autoLock.lockTime=parseInt($(':input[name=locktime]',fObj).val()));
autoLock.lockId=0;
autoLock.timerId=0;
autoLock.lasteventTime=0;
......@@ -108,9 +113,6 @@ var autoLock = {
autoLock.renewTime=0;
autoLock.renewFreq=0; //renewal frequency in seconds...based on returned lock time.
autoLock.time=0;
if(config && config.ticket_lock_time)
autoLock.timeTime=config.ticket_lock_time
autoLock.lockAttempts=0; //Consecutive lock attempt errors
autoLock.maxattempts=2; //Maximum failed lock attempts before giving up.
autoLock.warn=true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment