Source of file APIProject.php
Size: 2,783 Bytes - Last Modified: 2021-12-23T10:29:15+00:00
/var/www/docs.ssmods.com/process/src/code/api/nouns/APIProject.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 | <?php class APIProject extends APINoun { /** * * @var array */ private static $allowed_actions = array( 'index', 'fetch' ); /** * * @param SS_HTTPRequest $request * @return SS_HTTPResponse */ public function index(SS_HTTPRequest $request) { if(!$this->record->canView($this->getMember())) { return $this->message('You are not authorized to this environment', 403); } switch($request->httpMethod()) { case 'GET': $response = array( "name" => $this->record->Name, "href" => Director::absoluteURL($this->record->APILink("")), "created" => $this->record->Created, "last-edited" => $this->record->LastEdited, "disk-quota-mb" => $this->record->DiskQuotaMB, "environments" => array(), ); foreach($this->record->DNEnvironmentList() as $environment) { $response['environments'][] = array( 'name' => $environment->Name, 'href' => Director::absoluteURL($this->record->APILink($environment->Name)), ); } return $this->getAPIResponse($response); break; default: return $this->message('API not found', 404); break; } return $this->httpError(404, '404 - These aren\'t the droids you\'re looking for.'); } /** * * @param SS_HTTPRequest $request * @return SS_HTTPResponse */ public function fetch(SS_HTTPRequest $request) { if(!$this->record->canView($this->getMember())) { return $this->message('You are not authorized to do that on this environment', 403); } switch($request->httpMethod()) { case 'GET': return $this->getFetch($this->getRequest()->param('ID')); break; case 'POST': return $this->createFetch(); break; default: return $this->message('API not found', 404); break; } } /** * * @param int $ID * @return SS_HTTPResponse */ protected function getFetch($ID) { $ping = DNGitFetch::get()->byID($ID); if(!$ping) { return $this->message('Fetch not found', 404); } $output = array( 'status' => $ping->ResqueStatus(), 'message' => $ping->LogContent() ); return $this->getAPIResponse($output); } /** * * @return SS_HTTPResponse */ protected function createFetch() { $fetch = DNGitFetch::create(); $fetch->ProjectID = $this->record->ID; $fetch->write(); $fetch->start(); $location = Director::absoluteBaseURL().$this->Link().'/fetch/'.$fetch->ID; $output = array( 'message' => 'Ping queued as job ' . $fetch->ResqueToken, 'href' => $location, ); $response = $this->getAPIResponse($output); $response->setStatusCode(201); $response->addHeader('Location', $location); return $response; } /** * @return string */ public function Link() { return Controller::join_links( $this->parent->Link(), $this->record->Name ); } } |