Esempio n. 1
0
 function lock()
 {
     require_once $this->controller->rootdir . '/class/lock.class.php';
     require_once $this->controller->rootdir . '/class/event.class.php';
     $event = new event();
     $lock_cmd = $this->response->html->request()->get('lock');
     $resource_id = $this->response->html->request()->get('resource_id');
     $section = $this->response->html->request()->get('section');
     if (!strlen($lock_cmd) || !strlen($resource_id) || !strlen($section)) {
         $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Got empty paramater for lock, section or resource_id!", "", "", 0, 0, 0);
         return;
     }
     $lock = new lock();
     switch ($lock_cmd) {
         case 'aquire':
             $description = $this->response->html->request()->get('description');
             $token = $this->response->html->request()->get('token');
             $lock_fields['lock_resource_id'] = $resource_id;
             $lock_fields['lock_section'] = $section;
             $lock_fields['lock_description'] = $description;
             $lock_fields['lock_token'] = $token;
             $lock_id = $lock->add($lock_fields);
             if (strlen($lock_id)) {
                 echo $lock_id;
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 5, "openqrm.api.class.php", "Section " . $section . " is now locked by " . $resource_id . "!", "", "", 0, 0, 0);
             } else {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Section " . $section . " is still locked!", "", "", 0, 0, 0);
             }
             break;
         case 'release':
             $lock->get_instance_by_section($section);
             if (!strlen($lock->id)) {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Resource " . $resource_id . " trying to remove lock but no lock active for section " . $section, "", "", 0, 0, 0);
                 return;
             }
             if ($resource_id == $lock->resource_id) {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 5, "openqrm.api.class.php", "Resource " . $resource_id . " released lock for section " . $section, "", "", 0, 0, 0);
                 echo $lock->id;
                 $lock->remove_by_section($section);
             } else {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Resource " . $resource_id . " trying to remove lock from " . $lock->resource_id . " for section " . $section, "", "", 0, 0, 0);
             }
             break;
     }
 }