_session == null) { $this->_session = Services::session(); } return $this->_session; } final public function getToken(): string { return $this->getSession()->get($this->_token_name); } final public function getSite(): string { return $this->_site; } public function getService(): Service { if (!$this->_service) { $this->_service = new Service(); } return $this->_service; } final protected function setEntity(string $id, string $name, string $email, string $detail): Entity { $this->getService()->getModel()->where(Model::SITE, $this->getSite()); $this->getService()->getModel()->where('id', $id); $entity = $this->getEntity(); if (!$entity) { //Transaction Start $this->getService()->getModel()->transStart(); try { //없다면 새로 등록 $formDatas = [ 'site' => $this->getSite(), 'id' => $id, 'name' => $name, 'email' => $email, 'detail' => $detail, 'status' => 'unuse', ]; $entity = $this->getService()->getModel()->create($formDatas); $this->getService()->getModel()->transCommit(); } catch (\Exception $e) { //Transaction Rollback $this->getService()->getModel()->transRollback(); log_message("error", $e->getMessage()); throw new \Exception(__FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); } } //상태가 use(승인완료)가 아니라면 if ($entity->status !== DEFAULTS['STATUS']) { throw new PageNotFoundException("{$entity->getSite()}의{$entity->getEmail()}:{$entity->getTitle()}님은 {$entity->status}입니다 "); } return $entity; } }