public function itemAction() { $id = isset($_GET["id"]) ? $_GET["id"] : null; $swid = isset($_GET["swid"]) ? $_GET["swid"] : null; if ($_SERVER['REQUEST_METHOD'] != "GET" || $_SERVER["Repository_Enabled"] !== 'true' || is_numeric($swid) == false && is_numeric($id) == false) { header("Status: 404 Not Found"); return; } if ($id == null && $swid !== null) { $rl = new RestRepositoryAreaLatestItem(array("swid" => $swid)); } else { $rl = new RestRepositoryAreaItem(array("id" => $id)); } $res = $rl->getRawData(); $this->_helper->viewRenderer->setNoRender(); if ($rl->getError() != RestErrorEnum::RE_OK) { switch ($rl->getError()) { case RestErrorEnum::RE_ACCESS_DENIED: break; } header("Status: 404 Not Found"); echo $rl->getError(); return; } else { header("Content-Type: text/xml"); echo $rl->get($res); } }
/** * handles PUT and POST HTTP methods to REST requests * * @method integer the method enumeration according to RestMethodEnum * * @return iRestResponse * @access private */ private function putpost($method) { $id = $this->getParam("id"); $name = $this->getParam("name"); $value = $this->getParam("value"); $rs = new Repository_Model_MetaProductRepoAreas(); //TODO: replace equals(0) with is(null) if foreign key fixed $rs->filter->id->equals($id); $found = count($rs->items) > 0 ? true : false; if (!$found) { $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND); return false; } $r = $rs->items[0]; if (!$r instanceof Repository_Model_MetaProductRepoArea) { $this->setError(RestErrorEnum::RE_BACKEND_ERROR); return false; } db()->beginTransaction(); try { $r->{$name} = $value; $r->save(); db()->commit(); } catch (Exception $e) { db()->rollBack(); $this->setError(RestErrorEnum::RE_BACKEND_ERROR, $e->getMessage()); return false; } $res = new RestRepositoryAreaItem(array("id" => $id), $this); $ret = $res->get(); return $ret; }
public function newreleaseAction() { $this->_helper->layout->disableLayout(); $userid = $this->session->userid; if (is_numeric($userid) == false || $_SERVER["Repository_Enabled"] !== 'true') { $this->_helper->viewRenderer->setNoRender(); header("Status: 404 Not Found"); return; } $this->view->error = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $this->_helper->viewRenderer->setNoRender(); $swid = isset($_POST["swid"]) ? $_POST["swid"] : null; $swname = isset($_POST["swname"]) ? $_POST["swname"] : null; $repoareaid = isset($_POST["repoareaname"]) ? $_POST["repoareaname"] : null; if (Repository::canManageRelease($swid, $userid) === false) { header("Status: 404 Not Found"); return; } header("Content-Type: text/xml"); if (is_numeric($swid) == false) { echo "<response error='No software id given to create new release.' ></response>"; return; } $parentid = isset($_POST["parentid"]) ? $_POST["parentid"] : ""; if (trim($parentid) == "") { $parentid = 0; } if (is_numeric($parentid) == false) { echo "<response error='Release update is not associated with any release.' ></response>"; return; } $displayVersion = isset($_POST["displayversion"]) ? $_POST["displayversion"] : null; if (trim($displayVersion) == "") { echo "<response error='No display version given for the release.' ></response>"; return; } $id = Repository::createRelease($swid, $swname, $displayVersion, $repoareaid, $parentid, $userid); if (is_numeric($id) == true) { Repository::addReleaseByExternalId($id, $this->session->userid, "1"); Repository::addReleaseByExternalId($id, $this->session->userid, "2"); $rel = new Repository_Model_MetaProductReleases(); $rel->filter->id->equals($id); if (count($rel->items) > 0) { $r = $rel->items[0]; $newrel = new RestRepositoryAreaItem(array("id" => $r->repoareaid)); echo "<response id='" . $id . "'>"; echo $newrel->get(); echo "</response>"; } else { echo "<response error='Could not retrieve new product release information.'></response>"; } } else { if (is_numeric($id) == false) { echo "<response error='" . $id . "'></response>"; } else { echo "<response error='Unkown error occured during release creation.'></response>"; } } } else { if ($_SERVER['REQUEST_METHOD'] == "GET") { $swid = $this->_getParam("swid"); if (is_numeric($swid) == false) { $this->view->error = "No software id given"; return; } $rtype = strtolower(trim($this->_getParam("releasetype"))); if ($rtype == "") { $rtype = "major"; } switch ($rtype) { case "update": break; case "major": break; default: $this->view->error = "Invalid release type given. The release type can be either major or update."; return; } $this->view->appName = $this->_getParam("name"); $this->view->baselist = Repository::getProductBaseReleases($swid); $this->view->type = $rtype; } else { $this->_helper->viewRenderer->setNoRender(); header("Status: 404 Not Found"); return; } } }