/** * @httpMethod POST * @path /{type}/{secret} */ public function insertCommit() { try { $type = $this->getUriFragments('type'); $secret = $this->getUriFragments('secret'); // parse request $type = TypeAbstract::factory($type); $project = $type->getRequest(Base::getRawInput()); // get project $con = new Condition(array('secret', '=', $secret)); $id = $this->sql->select($this->registry['table.vcshook'], array('id'), $con, Sql::SELECT_FIELD); if (!empty($id) && $project->hasCommits()) { $count = 0; foreach ($project->getCommits() as $commit) { try { $record = $this->hm->getHandler('AmunService\\Vcshook\\Commit')->getRecord(); $record->setProjectId($id); $record->setAuthor($commit->getAuthor()); $record->setUrl($commit->getUrl()); $record->setMessage($commit->getMessage()); $record->setTimestamp($commit->getTimestamp()); // notify listener $this->event->notifyListener('vcshook.commit', array($record)); $count++; } catch (\Exception $e) { // import fails we go the next commit and ignore the // error } } if ($count == 0) { throw new Exception('No commits inserted'); } } else { throw new Exception('Invalid project or no commits available'); } $msg = new Message('Inserted ' . $count . ' commits', true); $this->setResponse($msg); } catch (\Exception $e) { $msg = new Message($e->getMessage(), false); $this->setResponse($msg, null, 500); } }
/** * Renders the content as html markup * * @httpMethod POST * @path / * @nickname doRender * @responseClass PSX_Data_ResultSet */ public function doRender() { if ($this->user->hasRight('content_page_preview')) { try { $oembed = $this->get->oembed('boolean'); $markdown = $this->get->markdown('boolean'); $input = Base::getRawInput(); $filter = new Filter\Html($this->registry, $this->user, $oembed); if ($markdown) { $input = Markdown::decode($input); } header('Content-Type: text/html'); echo $filter->apply($input); exit; } catch (\Exception $e) { $msg = new Message($e->getMessage(), false); $this->setResponse($msg); } } else { $msg = new Message('Access not allowed', false); $this->setResponse($msg, null, $this->user->isAnonymous() ? 401 : 403); } }