class_name = "Account"; parent::__construct(); $this->class_path .= $this->class_name; } private function getParentEntity(): AuthEntity { if ($this->_parent_entity === null) { throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다."); } return $this->_parent_entity; } private function setParentEntity(AuthEntity $parent_entity): void { $this->_parent_entity = $parent_entity; $this->setAuthEntity($this->getParentEntity()); } protected function getModel(): AccountModel { if ($this->_model === null) { $this->_model = new AccountModel(); } return $this->_model; } public function create(AuthEntity $parent_entity, array $formDatas): AccountEntity { //부모데이터정의 $this->setParentEntity($parent_entity); return $this->getModel()->create($formDatas); } public function modify(AuthEntity $parent_entity, AccountEntity $entity, array $formDatas): AccountEntity { //부모데이터정의 $this->setParentEntity($parent_entity); return $this->getModel()->modify($entity, $formDatas); } public function delete(AuthEntity $parent_entity): void { //부모데이터정의 $this->setParentEntity($parent_entity); $this->getModel()->delete(); } //Result 형태 // [ // {"id":"078e88a7735965b661715af13031ecb0", // "name":"Cloudwin002@idcjp.jp's Auth", // "type":"standard", // "settings":{ // "enforce_twofactor":false, // "api_access_enabled":null, // "access_approval_expiry":null, // "use_account_custom_ns_by_default":false // }, // "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}}, // "created_on":"2017-06-26T05:44:49.470184Z"} // ] protected function getArrayByResult(\stdClass $result, array $formDatas = []): array { $formDatas[AccountModel::PK] = $result->id; $formDatas[AccountModel::PARENT] = $this->getAuthEntity()->getPK(); $formDatas[AccountModel::TITLE] = $result->name; $formDatas['type'] = $result->type; $formDatas['status'] = $this->getAuthEntity()->status; $formDatas['updated_at'] = date("Y-m-d H:i:s"); $formDatas['created_at'] = $result->created_on; return $formDatas; } public function reload(AuthEntity $parent_entity): array { //부모데이터정의 $this->setParentEntity($parent_entity); log_message("notice", "\n----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리 시작-----------"); $entitys = []; try { $results = $this->reload_procedure("accounts"); $total = count($results); if ($total > 0) { $cnt = 1; foreach ($results as $result) { if (!is_object($result) || get_class($result) !== 'stdClass') { throw new \Exception("Account: result is not a stdClass:\n" . var_export($result, true) . "\n"); } $formDatas = $this->getArrayByResult($result); $entity = $this->getModel()->modify(new AccountEntity(), $formDatas); log_message("debug", "{$cnt}/{$total} => {$entity->getTitle()} Account 처리,[{$this->getMySocket()::$_request}]"); $entitys[$entity->getPK()] = $entity; $cnt++; } //부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용 $this->getModel()->where(AccountModel::PARENT, $this->getParentEntity()->getPK()); $this->getModel()->whereNotIn(AccountModel::PK, array_keys($entitys)); $this->getModel()->delete(); // log_message("debug", $this->getModel()->getLastQuery()); } } catch (\Exception $e) { log_message("error", $e->getMessage()); throw new \Exception($e->getMessage()); } log_message("notice", message: "\n-----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------"); return $entitys; } public function audit(AuthEntity $parent_entity, AccountEntity $entity): array { //부모데이터정의 $this->setParentEntity($parent_entity); log_message("notice", "\n----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리 시작-----------"); $entitys = []; try { $results = $this->reload_procedure("accounts/{$entity->getPK()}/audit_logs?since=" . date("Y-m-d") . "T00:00:00"); foreach ($results as $result) { if (isset($result->action->result) && $result->action->result && isset($result->metadata->newValueJson->zone_id)) { //해당 Zone을 Sync작업한다 $zone_service = new ZoneService(); $zone_entity = $zone_service->getEntityByPK($result->metadata->newValueJson->zone_id); $zone_entity = $zone_service->sync($entity, $zone_entity); //해당 Zone의 Record reload작업한다 $record_service = new RecordService(); $record_service->reload($zone_entity); //해당 Zone의 Firewall reload작업한다 $firewall_service = new FirewallService(); $firewall_service->reload($zone_entity); log_message("debug", "{$entity->getTitle()} Account 의 {$zone_entity->getTitle()} Sync및 Record,Firewall Reload 처리작업"); } } } catch (\Exception $e) { log_message("error", $e->getMessage()); throw new \Exception($e->getMessage()); } log_message("notice", message: "\n-----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------"); return $entitys; } }