From c8787e4e8248bb494a1bb6437fdaf35dfe46f693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Thu, 13 Mar 2025 15:55:12 +0900 Subject: [PATCH] cfmgrv4 init...10 --- .../Admin/Cloudflare/AuthController.php | 3 + .../Admin/Cloudflare/CloudflareController.php | 90 ++++++++++++++++--- .../Admin/Cloudflare/ZoneController.php | 2 + app/Controllers/CommonController.php | 32 +++---- app/Language/en/MyLog.php | 4 + app/Services/MyLogService.php | 12 +-- 6 files changed, 111 insertions(+), 32 deletions(-) diff --git a/app/Controllers/Admin/Cloudflare/AuthController.php b/app/Controllers/Admin/Cloudflare/AuthController.php index 79bce97..868ca23 100644 --- a/app/Controllers/Admin/Cloudflare/AuthController.php +++ b/app/Controllers/Admin/Cloudflare/AuthController.php @@ -4,6 +4,8 @@ namespace App\Controllers\Admin\Cloudflare; use App\Helpers\Cloudflare\AuthHelper; use App\Services\Cloudflare\AuthService; +use App\Services\MyLogService; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -25,6 +27,7 @@ class AuthController extends CloudflareController } return $this->service; } + //생성 protected function create_init(string $action, $fields = []): void { $fields = [ diff --git a/app/Controllers/Admin/Cloudflare/CloudflareController.php b/app/Controllers/Admin/Cloudflare/CloudflareController.php index 31385dd..c20cd79 100644 --- a/app/Controllers/Admin/Cloudflare/CloudflareController.php +++ b/app/Controllers/Admin/Cloudflare/CloudflareController.php @@ -54,8 +54,83 @@ abstract class CloudflareController extends AdminController } return $this->_recordModel; } - + //생성 + protected function create_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return parent::create_process_result($message); + } + protected function create_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return parent::create_process_failed($message); + } + //수정 + protected function modify_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return parent::modify_process_result($message); + } + protected function modify_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return parent::modify_process_failed($message); + } + //단일필드작업 + protected function toggle_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return parent::toggle_process_result($message); + } + protected function toggle_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return parent::toggle_process_failed($message); + } + //일괄처리작업 + protected function batchjob_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return parent::batchjob_process_result($message); + } + protected function batchjob_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return parent::batchjob_process_failed($message); + } + //삭제 delete,batchjob_delete 공통사용 + protected function delete_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return parent::delete_process_result($message); + } + protected function delete_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return parent::delete_process_failed($message); + } + //일괄삭제 + protected function batchjob_delete_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return parent::batchjob_delete_process_result($message); + } + protected function batchjob_delete_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return parent::batchjob_delete_process_failed($message); + } //Sync관련 + protected function sync_process_result($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']); + return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message); + } + protected function sync_process_failed($message): RedirectResponse|string + { + MyLogService::save($this->getService(), $this->myauth, $message); + return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message); + } protected function sync_process(string $uid): void {} final protected function sync_procedure(string $uid): RedirectResponse { @@ -64,11 +139,11 @@ abstract class CloudflareController extends AdminController try { $this->sync_process($uid); $this->getService()->getModel()->transCommit(); - return redirect()->to($this->myauth->popPreviousUrl())->with('error', MESSAGES["SUCCESS"]); + return $this->sync_process_result(MESSAGES["SUCCESS"]); } catch (\Exception $e) { //Transaction Rollback $this->getService()->getModel()->transRollback(); - return redirect()->to($this->myauth->popPreviousUrl())->with('error', $e->getMessage()); + return $this->sync_process_failed($e->getMessage()); } } final public function sync(string $uid): RedirectResponse @@ -84,19 +159,12 @@ abstract class CloudflareController extends AdminController $this->getService()->getModel()->transStart(); try { $this->reload_process($uid); - if ($this->isMyLog) { - MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo()); - } $this->getService()->getModel()->transCommit(); return redirect()->to($this->myauth->popPreviousUrl())->with('error', MESSAGES["SUCCESS"]); } catch (\Exception $e) { //Transaction Rollback $this->getService()->getModel()->transRollback(); - if ($this->isMyLog) { - MyLogService::add("error", $e->getMessage()); - MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo()); - } - return redirect()->back()->with('error', $e->getMessage()); + return redirect()->to($this->myauth->popPreviousUrl())->with('error', $e->getMessage()); } } final public function reload(string $uid): RedirectResponse diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index 1d70365..365da2f 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -7,6 +7,8 @@ use App\Helpers\Cloudflare\ZoneHelper; use App\Models\Cloudflare\AccountModel; use App\Services\Cloudflare\RecordService; use App\Services\Cloudflare\ZoneService; +use App\Services\MyLogService; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 4a38af4..dc2125c 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -337,6 +337,14 @@ abstract class CommonController extends BaseController } //삭제 delete,batchjob_delete 공통사용 + protected function delete_process_result($message): RedirectResponse|string + { + return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message); + } + protected function delete_process_failed($message): RedirectResponse|string + { + return redirect()->back()->with('error', $message); + } protected function delete_process(mixed $uid): void { //자신정보정의 @@ -346,14 +354,6 @@ abstract class CommonController extends BaseController } $this->entity = $this->getService()->delete($this->entity); } - protected function delete_process_result($message): RedirectResponse|string - { - return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message); - } - protected function delete_process_failed($message): RedirectResponse|string - { - return redirect()->back()->with('error', $message); - } final protected function delete_procedure(mixed $uid): RedirectResponse|string { //Transaction Start @@ -409,6 +409,10 @@ abstract class CommonController extends BaseController } //View + protected function view_init(string $action, $fields = []): void + { + $this->init($action, $fields); + } protected function view_process(mixed $uid): void { //자신정보정의 @@ -439,10 +443,6 @@ abstract class CommonController extends BaseController return $this->view_process_failed($e->getMessage()); } } - protected function view_init(string $action, $fields = []): void - { - $this->init($action, $fields); - } final public function view(string $uid): RedirectResponse|string { $this->view_init(__FUNCTION__); @@ -450,6 +450,10 @@ abstract class CommonController extends BaseController } // 리스트 + protected function index_init(string $action, $fields = []): void + { + $this->init($action, $fields); + } protected function index_condition_process(): void { //조건절 처리 @@ -558,10 +562,6 @@ abstract class CommonController extends BaseController return $this->helper->alert($e->getMessage()); } } - protected function index_init(string $action, $fields = []): void - { - $this->init($action, $fields); - } public function index(): string { $this->index_init(__FUNCTION__); diff --git a/app/Language/en/MyLog.php b/app/Language/en/MyLog.php index 5f5914c..04155cb 100644 --- a/app/Language/en/MyLog.php +++ b/app/Language/en/MyLog.php @@ -12,4 +12,8 @@ return [ 'updated_at' => "수정일", 'created_at' => "작성일", ], + "STATUS" => [ + "use" => "완료처리", + "unuse" => "실패처리", + ], ]; diff --git a/app/Services/MyLogService.php b/app/Services/MyLogService.php index 069377f..a2aea84 100644 --- a/app/Services/MyLogService.php +++ b/app/Services/MyLogService.php @@ -2,8 +2,9 @@ namespace App\Services; -use App\Models\MyLogModel; use App\Entities\MyLogEntity; +use App\Models\MyLogModel; +use App\Services\Auth\AuthService; class MyLogService { @@ -23,14 +24,15 @@ class MyLogService log_message($level, $message); } - static public function save($class_name, $method_name, $title, $user_uid): MyLogEntity + static public function save($service, AuthService $myauth, string $title, string $status = "unuse"): MyLogEntity { $formDatas = [ - 'user_uid' => $user_uid, - 'class_name' => $class_name, - 'method_name' => $method_name, + 'user_uid' => $myauth->getUIDByAuthInfo(), + 'class_name' => $service->getClassName(), + 'method_name' => $service->getClassPath(), 'title' => $title, 'content' => implode("\n", self::$_logBuffers), + 'status' => $status, ]; self::$_logBuffers = []; // dd($formDatas);