From 445dfd7cb01c30d7740ef95018eb95cd1bf44042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Fri, 11 Oct 2024 11:41:13 +0900 Subject: [PATCH] cfmgrv4 init...1 --- app/Controllers/Admin/UserSNSController.php | 22 +++++++++++----- app/Controllers/MVController.php | 4 +-- app/Entities/Cloudflare/AccountEntity.php | 2 +- app/Entities/UserSNSEntity.php | 17 +++++++----- app/Helpers/Cloudflare/AccountHelper.php | 6 ++--- app/Helpers/Cloudflare/RecordHelper.php | 6 ++--- app/Helpers/Cloudflare/ZoneHelper.php | 9 +++---- app/Helpers/CommonHelper.php | 5 ++-- app/Helpers/UserHelper.php | 3 +-- app/Helpers/UserSNSHelper.php | 7 +++++ app/Language/en/UserSNS.php | 1 + app/Libraries/MyAuth/GoogleAuth.php | 5 ++-- app/Models/Cloudflare/AuthModel.php | 2 +- app/Models/CommonModel.php | 29 ++++++++++++--------- app/Models/UserModel.php | 11 +++++++- app/Models/UserSNSModel.php | 3 ++- 16 files changed, 78 insertions(+), 54 deletions(-) diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index 4fa17b4..8ef1dae 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -3,8 +3,9 @@ namespace App\Controllers\Admin; use App\Helpers\UserSNSHelper; -use App\Models\UserSNSModel; +use App\Models\UserModel; +use App\Models\UserSNSModel; use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; @@ -42,6 +43,13 @@ class UserSNSController extends AdminController protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { + case $this->getModel()::PARENT: + $userModel = model(UserModel::class); + // $this->getUserModel()->where('status', DEFAULTS['STATUS']); + $options[$field] = $userModel->getFormFieldOption($field); + // echo $this->getUserModel()->getLastQuery(); + // dd($options); + break; default: $options = parent::getFormFieldOption($field, $options); break; @@ -60,9 +68,9 @@ class UserSNSController extends AdminController private function init(string $action): void { $this->action = $action; - $this->fields = ['site', 'id', $this->getModel()::TITLE, 'email']; + $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; + $this->filter_fields = [$this->getModel()::PARENT, 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); } //수정 @@ -88,9 +96,9 @@ class UserSNSController extends AdminController public function index(): string { $this->action = __FUNCTION__; - $this->fields = ['site', 'id', $this->getModel()::TITLE, 'email', 'status']; + $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; + $this->filter_fields = [$this->getModel()::PARENT, 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->batchjob_fields = ['status']; return $this->list_procedure(); @@ -99,9 +107,9 @@ class UserSNSController extends AdminController public function download(string $output_type, $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; - $this->fields = ['site', 'id', $this->getModel()::TITLE, 'email', 'status']; + $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = ['status']; + $this->filter_fields = [$this->getModel()::PARENT, 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->batchjob_fields = ['status']; return $this->download_procedure($output_type, $uid); diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 34d6a38..88877b9 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -294,7 +294,7 @@ abstract class MVController extends CommonController { $this->list_condition_process(); $total_count = $this->getModel()->countAllResults(); - // echo $this->getModel()->getLastQuery(); + // log_message("debug", $this->getModel()->getLastQuery()); return $total_count; } //PageNation 처리 @@ -343,7 +343,7 @@ abstract class MVController extends CommonController ); } $entitys = $this->getModel()->select($this->getModel()->getTable() . '.*')->findAll(); - log_message("debug", $this->getModel()->getLastQuery()); + // log_message("debug", $this->getModel()->getLastQuery()); return $entitys; } final protected function list_procedure(): string diff --git a/app/Entities/Cloudflare/AccountEntity.php b/app/Entities/Cloudflare/AccountEntity.php index a914ec8..d779365 100644 --- a/app/Entities/Cloudflare/AccountEntity.php +++ b/app/Entities/Cloudflare/AccountEntity.php @@ -24,7 +24,7 @@ class AccountEntity extends CommonEntity $this->attributes[AccountModel::TITLE] = $title; } //Common Function - public function getParent(): string + public function getParent(): int { return $this->attributes[AccountModel::PARENT]; } diff --git a/app/Entities/UserSNSEntity.php b/app/Entities/UserSNSEntity.php index 8edbf3f..69f99ba 100644 --- a/app/Entities/UserSNSEntity.php +++ b/app/Entities/UserSNSEntity.php @@ -11,6 +11,10 @@ class UserSNSEntity extends CommonEntity { return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}"; } + public function getPK(): int + { + return $this->attributes[UserSNSModel::PK]; + } public function getTitle(): string { return $this->attributes[UserSNSModel::TITLE]; @@ -20,19 +24,18 @@ class UserSNSEntity extends CommonEntity $this->attributes[UserSNSModel::TITLE] = $title; } //Common Function - - public function getPK(): int + public function getParent(): int|null { - return $this->attributes[UserSNSModel::PK]; - } - public function getSite(): string - { - return $this->attributes['site']; + return $this->attributes[UserSNSModel::PARENT]; } public function getID(): string { return $this->attributes['id']; } + public function getSite(): string + { + return $this->attributes['site']; + } public function getEmail(): string { return $this->attributes['email']; diff --git a/app/Helpers/Cloudflare/AccountHelper.php b/app/Helpers/Cloudflare/AccountHelper.php index d36ddea..44d7bab 100644 --- a/app/Helpers/Cloudflare/AccountHelper.php +++ b/app/Helpers/Cloudflare/AccountHelper.php @@ -20,8 +20,7 @@ class AccountHelper extends CommonHelper $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); + ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); break; case AccountModel::TITLE: $form = form_input($field, $value, ["placeholder" => "예)test@exmaple.com", ...$extras]); @@ -29,8 +28,7 @@ class AccountHelper extends CommonHelper case 'type': $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field], - ], $value, $extras); + ] + $viewDatas['field_options'][$field], $value, $extras); break; default: $form = parent::getFieldForm($field, $value, $viewDatas, $extras); diff --git a/app/Helpers/Cloudflare/RecordHelper.php b/app/Helpers/Cloudflare/RecordHelper.php index dbf7cb4..7cabc8c 100644 --- a/app/Helpers/Cloudflare/RecordHelper.php +++ b/app/Helpers/Cloudflare/RecordHelper.php @@ -20,8 +20,7 @@ class RecordHelper extends CommonHelper $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); + ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); break; case RecordModel::TITLE: //host $form = form_input($field, $value, $extras); @@ -42,8 +41,7 @@ class RecordHelper extends CommonHelper case "proxiable": $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field], - ], $value, $extras); + ] + $viewDatas['field_options'][$field], $value, $extras); break; default: $form = parent::getFieldForm($field, $value, $viewDatas, $extras); diff --git a/app/Helpers/Cloudflare/ZoneHelper.php b/app/Helpers/Cloudflare/ZoneHelper.php index 6c93759..a13efc4 100644 --- a/app/Helpers/Cloudflare/ZoneHelper.php +++ b/app/Helpers/Cloudflare/ZoneHelper.php @@ -20,8 +20,7 @@ class ZoneHelper extends CommonHelper $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); + ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); break; case ZoneModel::TITLE: $form = form_input($field, $value, ["placeholder" => "예)exampel.com", ...$extras]); @@ -44,15 +43,13 @@ class ZoneHelper extends CommonHelper case 'status': $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], $value, $extras); + ] + $viewDatas['field_options'][$field], $value, $extras); break; case 'type': //A,AAA... case 'proxied': //CDN사용여부 $form = form_dropdown($field, [ "" => lang('Cloudflare/Record.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], $value, $extras); + ] + $viewDatas['field_options'][$field], $value, $extras); break; default: $form = parent::getFieldForm($field, $value, $viewDatas, $extras); diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index c13ca31..3b3dabb 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -149,8 +149,7 @@ abstract class CommonHelper case 'status': $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], $value, $extras); + ] + $viewDatas['field_options'][$field], $value, $extras); break; case 'updated_at': case 'created_at': @@ -181,7 +180,7 @@ abstract class CommonHelper $value = $value ? date("Y-m-d", strtotime($value)) : ""; break; default: - if (in_array($field, $viewDatas['filter_fields']) && $value) { + if (in_array($field, $viewDatas['filter_fields'])) { $extras["onChange"] = sprintf( 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', current_url(), diff --git a/app/Helpers/UserHelper.php b/app/Helpers/UserHelper.php index 51343e1..3f70ba5 100644 --- a/app/Helpers/UserHelper.php +++ b/app/Helpers/UserHelper.php @@ -45,8 +45,7 @@ class UserHelper extends CommonHelper $field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', - ...$viewDatas['field_options'][$field] - ], + ] + $viewDatas['field_options'][$field], $value, $extras ); diff --git a/app/Helpers/UserSNSHelper.php b/app/Helpers/UserSNSHelper.php index 99b89c5..99ec355 100644 --- a/app/Helpers/UserSNSHelper.php +++ b/app/Helpers/UserSNSHelper.php @@ -14,6 +14,12 @@ class UserSNSHelper extends CommonHelper { $value = $value ?: DEFAULTS['EMPTY']; switch ($field) { + case UserSNSModel::PARENT: + $extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field'; + $form = form_dropdown($field, [ + "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', + ] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]); + break; case 'id': case UserSNSModel::TITLE: $form = form_input($field, $value, $extras); @@ -33,4 +39,5 @@ class UserSNSHelper extends CommonHelper } return $form; } // + } diff --git a/app/Language/en/UserSNS.php b/app/Language/en/UserSNS.php index 7862de3..3b7ff48 100644 --- a/app/Language/en/UserSNS.php +++ b/app/Language/en/UserSNS.php @@ -3,6 +3,7 @@ return [ 'title' => "SNS 계정정보", 'label' => [ 'uid' => "번호", + 'user_uid' => "local계정", 'site' => "사이트", 'id' => "계정", 'name' => "이름", diff --git a/app/Libraries/MyAuth/GoogleAuth.php b/app/Libraries/MyAuth/GoogleAuth.php index e6e53d7..4ced677 100644 --- a/app/Libraries/MyAuth/GoogleAuth.php +++ b/app/Libraries/MyAuth/GoogleAuth.php @@ -41,10 +41,9 @@ class GoogleAuth extends MyAuth // Google 서비스 설정 $userSNS_entity = $this->getMySocket()->getUserSNSEntity(); //local db 사용와의 연결 확인 - $userModel = model(UserModel::class); - $user_entity = $userModel->getEntityByID($userSNS_entity->getID()); + $user_entity = $this->getModel()->getEntityByPK($userSNS_entity->getParent()); if ($user_entity === null) { - throw new PageNotFoundException("{$userSNS_entity->getSite()}의{$userSNS_entity->getEmail()}:{$userSNS_entity->getTitle()}님은 아직 사용자 연결이 이루어지지 않았습니다. "); + throw new PageNotFoundException("회원[{$userSNS_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다."); } return $user_entity; } catch (\Google_Service_Exception $e) { diff --git a/app/Models/Cloudflare/AuthModel.php b/app/Models/Cloudflare/AuthModel.php index 66ec28b..23a9fd0 100644 --- a/app/Models/Cloudflare/AuthModel.php +++ b/app/Models/Cloudflare/AuthModel.php @@ -48,7 +48,7 @@ class AuthModel extends CommonModel { switch ($field) { default: - $this->orderBy(self::PK, 'asc'); + $this->orderBy(self::TITLE, 'asc'); $options = parent::getFormFieldOption($field, $options); break; } diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 4fc2ea1..ff89093 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -114,7 +114,6 @@ abstract class CommonModel extends Model break; } // dd($options); - // exit; return $options; } final public function getEntity(): array|object|null @@ -157,21 +156,27 @@ abstract class CommonModel extends Model private function save_process($entity): mixed { - //최종 변경사항이 있으면 저장 - if ($entity->hasChanged()) { + try { + //최종 변경사항이 없으면 + if (!$entity->hasChanged()) { + throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다."); + } + // log_message("debug", var_export($entity, true)); + //최종 저장시 오류발생하면 if (!$this->save($entity)) { - throw new \Exception(sprintf( - "\n------%s SQL오류-----\n%s\n%s\n------------------------------\n", - __FUNCTION__, - $this->getLastQuery(), - var_export($this->errors(), true) - )); + throw new \Exception("저장오류:" . var_export($this->errors(), true)); } log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB 저장이 완료되었습니다."); - } else { - log_message("notice", __FUNCTION__ . " 변경된 내용이 없습니다."); + return $entity; + } catch (\Exception $e) { + $message = sprintf( + "\n------%s SQL오류-----\n%s\n%s\n------------------------------\n", + __FUNCTION__, + $this->getLastQuery(), + $e->getMessage() + ); + throw new \Exception($message); } - return $entity; } final protected function create_process($entity, array $formDatas): mixed { diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 4c6853d..7c3590c 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -73,7 +73,16 @@ class UserModel extends CommonModel } return $value; } - + public function getFormFieldOption(string $field, array $options = []): array + { + switch ($field) { + default: + $this->orderBy(self::TITLE, 'asc'); + $options = parent::getFormFieldOption($field, $options); + break; + } + return $options; + } public function getEntityByPK(string $uid): null|UserEntity { $this->where($this->getPKField(), intval($uid)); diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php index 5a2d83c..d0869e7 100644 --- a/app/Models/UserSNSModel.php +++ b/app/Models/UserSNSModel.php @@ -10,12 +10,14 @@ class UserSNSModel extends CommonModel const TABLE = "user_sns"; const PK = "uid"; const TITLE = "name"; + const PARENT = "user_uid"; const SITE = "site"; protected $table = self::TABLE; protected $primaryKey = self::PK; protected $returnType = UserSNSEntity::class; protected $allowedFields = [ "site", + "user_uid", "id", "name", "email", @@ -76,7 +78,6 @@ class UserSNSModel extends CommonModel $this->where('id', $id); return $this->getEntity(); } - //create용 public function create(array $formDatas = []): UserSNSEntity {