Example #1
0
 function __construct($entry, $user)
 {
     $this->entry = Contextualization::getContextualization($entry);
     if ($this->entry === null) {
         $this->entry = new Default_Model_Context();
     }
     $this->swappliance = $this->entry->getApplication();
     $this->user = $user;
     $this->canEdit = false;
     if ($this->user instanceof Default_Model_Researcher) {
         $privs = $this->user->getPrivs();
         if ($privs) {
             $this->canEdit = $privs->canManageContextScripts($this->swappliance);
         }
     }
 }
Example #2
0
 public function action($method)
 {
     db()->beginTransaction();
     $context = Contextualization::initContextualization($this->_app, $this->getUser());
     if (!$context instanceof Contextualization) {
         if ($context === false) {
             $context = "Could not initialize contextualization";
         }
         $this->setError(RestErrorEnum::RE_BACKEND_ERROR, $context);
         return;
     }
     $data = $this->_parser->parse($this->getData());
     if ($this->_parser->getError() !== RestErrorEnum::RE_OK) {
         db()->rollBack();
         $this->setError($this->_parser->getError(), $this->_parser->getExtError(), false);
         $ret = false;
     } else {
         if (!is_array($data)) {
             db()->rollBack();
             return $this->_setErrorMessage($data, RestErrorEnum::RE_BACKEND_ERROR);
         } else {
             try {
                 $result = $context->action($this->getNamedAction($method), $data);
                 if ($result === false) {
                     db()->rollBack();
                     return $this->_setErrorMessage("Could not complete request", RestErrorEnum::RE_BACKEND_ERROR);
                 } else {
                     if (is_string($result)) {
                         db()->rollBack();
                         return $this->_setErrorMessage($result, RestErrorEnum::RE_BACKEND_ERROR);
                     }
                 }
             } catch (Exception $ex) {
                 db()->rollBack();
                 return $this->_setErrorMessage($ex->getMessage(), RestErrorEnum::RE_BACKEND_ERROR);
             }
             db()->commit();
             $ret = false;
             $retCount = 0;
             // sometimes fetching the new data might fail (race condition). Try up to 5 times
             while ($ret === false && $retCount < 5) {
                 sleep(1);
                 $ret = $this->get();
                 if ($ret === false && $res->getError() !== RestErrorEnum::RE_ITEM_NOT_FOUND) {
                     // give up on errors other than item not found
                     break;
                 } else {
                     $retCount += 1;
                 }
             }
         }
     }
     return $ret;
 }