コード例 #1
0
 /**
  * @return SS_HTTPResponse
  */
 public function publishCompanyService()
 {
     try {
         $company_service_live_id = intval($this->request->param('COMPANY_SERVICE_ID'));
         $data = $this->getJsonRequest();
         if (!$data) {
             return $this->serverError();
         }
         //save the live version
         if ($company_service_live_id == 0) {
             // this means is a draft without a live version yet
             $data['live_service_id'] = $this->manager->addCompanyService($data)->getIdentifier();
             //save the draft
             if ($data['id']) {
                 //it could be that the draft was never saved yet, in that case id should be 0
                 $this->draft_manager->updateCompanyService($data);
             } else {
                 $this->draft_manager->addCompanyService($data);
             }
         } else {
             //if there is a live version of this draft, update it
             $this->draft_manager->updateCompanyService($data);
             $data['id'] = $data['live_service_id'];
             $this->manager->updateCompanyService($data);
         }
         return $this->published();
     } catch (EntityAlreadyExistsException $ex1) {
         SS_Log::log($ex1, SS_Log::ERR);
         return $this->addingDuplicate($ex1->getMessage());
     } catch (PolicyException $ex2) {
         SS_Log::log($ex2, SS_Log::ERR);
         return $this->validationError($ex2->getMessage());
     } catch (EntityValidationException $ex3) {
         SS_Log::log($ex3, SS_Log::ERR);
         return $this->validationError($ex3->getMessages());
     }
 }