コード例 #1
0
ファイル: Handler.php プロジェクト: visapi/amun
 public function update(RecordInterface $record)
 {
     if ($record->hasFields('id')) {
         // check whether project exists
         if (isset($record->url)) {
             $type = TypeAbstract::getType($record->type);
             if (!$type->hasProject($record->url)) {
                 throw new Exception('Project doesnt exist');
             }
         }
         $con = new Condition(array('id', '=', $record->id));
         $this->table->update($record->getData(), $con);
         $this->notify(RecordAbstract::UPDATE, $record);
         return $record;
     } else {
         throw new Exception('Missing field in record');
     }
 }
コード例 #2
0
ファイル: Callback.php プロジェクト: visapi/amun
 /**
  * @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);
     }
 }