cfmgrv4 init...10

This commit is contained in:
최준흠 2025-03-13 15:55:12 +09:00
parent 97c4dc825b
commit c8787e4e82
6 changed files with 111 additions and 32 deletions

View File

@ -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 = [

View File

@ -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

View File

@ -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;

View File

@ -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__);

View File

@ -12,4 +12,8 @@ return [
'updated_at' => "수정일",
'created_at' => "작성일",
],
"STATUS" => [
"use" => "완료처리",
"unuse" => "실패처리",
],
];

View File

@ -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);