cfmgrv4 init...10

This commit is contained in:
최준흠 2025-03-12 15:56:01 +09:00
parent 364567c138
commit 0e2f198687
11 changed files with 179 additions and 91 deletions

View File

@ -54,6 +54,93 @@ abstract class CloudflareController extends AdminController
}
return $this->_recordModel;
}
//생성관련
protected function create_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::create_process_result($message);
// $this->init(__FUNCTION__);
// helper(['form']);
// $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
// return view(
// strtolower($this->view_path . $this->getService()->getClassPath() . "/create_result"),
// data: ['viewDatas' => $this->getViewDatas()]
// );
}
protected function create_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::create_process_failed($message);
}
//수정관련
protected function modify_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::modify_process_result($message);
}
protected function modify_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::modify_process_failed($message);
}
//단일필드작업
protected function toggle_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::toggle_process_result($message);
}
protected function toggle_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::toggle_process_failed($message);
}
//일괄처리작업
protected function batchjob_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::batchjob_process_result($message);
}
protected function batchjob_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::batchjob_process_failed($message);
}
//Delete관련
protected function delete_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::delete_process_result($message);
}
protected function delete_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::delete_process_failed($message);
}
//일괄삭제
protected function batchdelete_process_result($message): RedirectResponse|string
{
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, $message, $this->myauth->getUIDByAuthInfo());
return parent::batchjob_delete_process_result($message);
}
protected function batchdelete_process_failed($message): RedirectResponse|string
{
MyLogService::add("error", $message);
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["FAILED"], $this->myauth->getUIDByAuthInfo());
return parent::batchjob_delete_process_failed($message);
}
//Sync관련련
protected function sync_process(string $uid): void {}
protected function sync_process_result($message): RedirectResponse|string
{

View File

@ -11,6 +11,7 @@ use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Services\MyLogService;
class ZoneController extends CloudflareController
{
@ -131,16 +132,7 @@ class ZoneController extends CloudflareController
}
$this->entitys = $entitys;
}
protected function create_process_result($message): RedirectResponse|string
{
$this->init(__FUNCTION__);
helper(['form']);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
return view(
strtolower($this->view_path . $this->getService()->getClassPath() . "/create_result"),
data: ['viewDatas' => $this->getViewDatas()]
);
}
public function create(): RedirectResponse|string
{
$this->init(__FUNCTION__, [$this->getService()->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']);

View File

@ -13,7 +13,6 @@ use CodeIgniter\Validation\Validation;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
use App\Services\MyLogService;
abstract class CommonController extends BaseController
{
@ -127,6 +126,10 @@ abstract class CommonController extends BaseController
$url = strtolower(base_url() . $this->uri_path . $this->getService()->getClassName()) . "/view/" . $this->entity->getPK();
return redirect()->to($url)->with('error', $message);
}
protected function create_process_failed($message): RedirectResponse|string
{
return redirect()->back()->withInput()->with('error', $message);
}
final protected function create_procedure(): RedirectResponse|string
{
//Transaction Start
@ -135,18 +138,11 @@ abstract class CommonController extends BaseController
helper(['form']);
$this->create_process();
$this->getService()->getModel()->transCommit();
if ($this->isMyLog) {
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo());
}
return $this->create_process_result(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()->withInput()->with('error', $e->getMessage());
return $this->create_process_result($e->getMessage());
}
}
// 수정
@ -192,10 +188,6 @@ abstract class CommonController extends BaseController
if ($this->entity === null) {
throw new \Exception(__FUNCTION__ . " => {$uid} 정보를 찾을수 없습니다.");
}
//수정된값 Log남기기
foreach ($this->fields as $field) {
MyLogService::add("info", "{$field}: {$this->formDatas[$field]}=>{$this->entity->$field}");
}
$this->entity = $this->getService()->modify($this->entity, $this->formDatas);
}
protected function modify_process_result($message): RedirectResponse|string
@ -203,6 +195,10 @@ abstract class CommonController extends BaseController
$url = strtolower(base_url() . $this->uri_path . $this->getService()->getClassName()) . "/view/" . $this->entity->getPK();
return redirect()->to($url)->with('error', $message);
}
protected function modify_process_failed($message): RedirectResponse|string
{
return redirect()->back()->withInput()->with('error', $message);
}
final protected function modify_procedure(mixed $uid): RedirectResponse|string
{
//Transaction Start
@ -211,18 +207,11 @@ abstract class CommonController extends BaseController
helper(['form']);
$this->modify_process($uid);
$this->getService()->getModel()->transCommit();
if ($this->isMyLog) {
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo());
}
return $this->modify_process_result(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()->withInput()->with('error', $e->getMessage());
return $this->modify_process_result($e->getMessage());
}
}
//단일필드작업
@ -230,6 +219,10 @@ abstract class CommonController extends BaseController
{
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message);
}
protected function toggle_process_failed($message): RedirectResponse|string
{
return redirect()->back()->with('error', $message);
}
final protected function toggle_procedure(mixed $uid, string $field): RedirectResponse
{
//Transaction Start
@ -239,19 +232,11 @@ abstract class CommonController extends BaseController
$this->fields = [$field];
$this->modify_process($uid);
$this->getService()->getModel()->transCommit();
if ($this->isMyLog) {
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo());
}
return $this->toggle_process_result(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 $this->toggle_process_failed($e->getMessage());
}
}
//일괄처리작업
@ -259,6 +244,10 @@ abstract class CommonController extends BaseController
{
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message);
}
protected function batchjob_process_failed($message): RedirectResponse|string
{
return redirect()->back()->with('error', $message);
}
final protected function batchjob_procedure(): RedirectResponse
{
//Transaction Start
@ -281,19 +270,11 @@ abstract class CommonController extends BaseController
$this->modify_process($uid);
}
$this->getService()->getModel()->transCommit();
if ($this->isMyLog) {
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo());
}
return $this->batchjob_process_result(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 $this->batchjob_process_failed($e->getMessage());
}
}
//View
@ -314,13 +295,17 @@ abstract class CommonController extends BaseController
data: ['viewDatas' => $this->getViewDatas()]
);
}
protected function view_process_failed($message): RedirectResponse|string
{
return redirect()->back()->with('error', $message);
}
final protected function view_procedure(mixed $uid): RedirectResponse|string
{
try {
$this->view_process($uid);
return $this->view_process_result();
} catch (\Exception $e) {
return redirect()->back()->with('error', $e->getMessage());
return $this->view_process_failed($e->getMessage());
}
}
//삭제 delete,batchjob_delete 공통사용
@ -331,16 +316,16 @@ abstract class CommonController extends BaseController
if ($this->entity === null) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
//삭제된값 Log남기기
foreach ($this->fields as $field) {
MyLogService::add("info", "{$field}: {$this->entity->$field}");
}
$this->entity = $this->getService()->delete($this->entity->getPK());
}
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 public function delete(mixed $uid): RedirectResponse
{
//Transaction Start
@ -348,20 +333,20 @@ abstract class CommonController extends BaseController
try {
$this->delete_process($uid);
$this->getService()->getModel()->transCommit();
if ($this->isMyLog) {
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo());
}
return $this->delete_process_result(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 $this->delete_process_failed($e->getMessage());
}
return redirect()->back()->with('error', $e->getMessage());
}
protected function batchjob_delete_process_result($message): RedirectResponse|string
{
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message);
}
protected function batchjob_delete_process_failed($message): RedirectResponse|string
{
return redirect()->back()->with('error', $message);
}
//일괄삭제
final public function batchjob_delete(): RedirectResponse|string
@ -378,19 +363,11 @@ abstract class CommonController extends BaseController
$this->delete_process($uid);
}
$this->getService()->getModel()->transCommit();
if ($this->isMyLog) {
MyLogService::save($this->getService()->getClassName(), __FUNCTION__, MESSAGES["SUCCESS"], $this->myauth->getUIDByAuthInfo());
}
return $this->delete_process_result(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 $this->delete_process_result($e->getMessage());
}
}
// 리스트
@ -418,7 +395,7 @@ abstract class CommonController extends BaseController
{
$this->list_condition_process();
$total_count = $this->getService()->getModel()->countAllResults();
// MyLogService::add("debug", $this->getService()->getModel()->getLastQuery());
// log_message("debug", $this->getService()->getModel()->getLastQuery());
return $total_count;
}
//PageNation 처리
@ -466,7 +443,7 @@ abstract class CommonController extends BaseController
}
$this->getService()->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page);
$entitys = $this->getService()->getModel()->select($this->getService()->getModel()::TABLE . '.*')->findAll();
MyLogService::add("debug", $this->getService()->getModel()->getLastQuery());
log_message("debug", $this->getService()->getModel()->getLastQuery());
return $entitys;
}
protected function list_process_result(): string

View File

@ -6,6 +6,7 @@ use App\Entities\Cloudflare\AccountEntity;
use App\Entities\Cloudflare\AuthEntity;
use App\Models\Cloudflare\AccountModel;
use stdClass;
use App\Services\MyLogService;
class AccountService extends CloudflareService
{
@ -43,6 +44,10 @@ class AccountService extends CloudflareService
{
//부모데이터정의
$this->setParentEntity($parent_entity);
//생성값 formDatas Log남기기
foreach ($formDatas as $field => $value) {
MyLogService::add("info", "{$field}:{$value}");
}
return $this->getModel()->create($formDatas);
}
@ -50,14 +55,22 @@ class AccountService extends CloudflareService
{
//부모데이터정의
$this->setParentEntity($parent_entity);
//변경전 entity 값, 변경값 formDatas Log남기기
foreach ($formDatas as $field => $value) {
MyLogService::add("info", "{$field}:{$entity->$field}=>{$value}");
}
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(AuthEntity $parent_entity): void
public function delete(AuthEntity $parent_entity, AccountEntity $entity): void
{
//부모데이터정의
$this->setParentEntity($parent_entity);
$this->getModel()->delete();
//삭제전 entity 값 Log남기기
foreach ($this->getModel()->getAllowedFields() as $field) {
MyLogService::add("info", "{$field}:{$entity->$field}");
}
$this->getModel()->delete($entity->getPK());
}
//Result 형태

View File

@ -4,6 +4,7 @@ namespace App\Services\Cloudflare;
use App\Entities\Cloudflare\AuthEntity;
use App\Models\Cloudflare\AuthModel;
use App\Services\MyLogService;
class AuthService extends CloudflareService
{
@ -24,16 +25,28 @@ class AuthService extends CloudflareService
public function create(array $formDatas): AuthEntity
{
//생성값 formDatas Log남기기
foreach ($formDatas as $field => $value) {
MyLogService::add("info", "{$field}:{$value}");
}
return $this->getModel()->create($formDatas);
}
public function modify(AuthEntity $entity, array $formDatas): AuthEntity
{
//변경전 entity 값, 변경값 formDatas Log남기기
foreach ($formDatas as $field => $value) {
MyLogService::add("info", "{$field}:{$entity->$field}=>{$value}");
}
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
public function delete(AuthEntity $entity): void
{
$this->getModel()->delete();
//삭제전 entity 값 Log남기기
foreach ($this->getModel()->getAllowedFields() as $field) {
MyLogService::add("info", "{$field}:{$entity->$field}");
}
$this->getModel()->delete($entity->getPK());
}
}

View File

@ -94,7 +94,6 @@ class FirewallService extends CloudflareService
MyLogService::add("info", "{$body->result->id}:{$entity->expression}=>{$rule}");
//DB수정
$entity = $this->getModel()->modify($entity, $formDatas);
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["UPDATED"]);
// log_message("debug", $this->getModel()->getLastQuery());
}
}

View File

@ -96,7 +96,6 @@ class RecordService extends CloudflareService
}
//DB생성
$entity = $this->getModel()->create($formDatas);
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["CREATED"]);
// log_message("debug", $this->getModel()->getLastQuery());
return $entity;
}
@ -141,7 +140,6 @@ class RecordService extends CloudflareService
}
//DB수정
$entity = $this->getModel()->modify($entity, $formDatas);
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["UPDATED"]);
// log_message("debug", $this->getModel()->getLastQuery());
return $entity;
}
@ -157,7 +155,6 @@ class RecordService extends CloudflareService
foreach ($this->getModel()->getAllowedFields() as $field) {
MyLogService::add("info", "{$field}:{$entity->$field}");
}
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["DELETED"]);
// log_message("debug", $this->getModel()->getLastQuery());
return $entity;
}

View File

@ -125,7 +125,6 @@ class ZoneService extends CloudflareService
}
//DB생성
$entity = $this->getModel()->create($formDatas);
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["CREATED"]);
// log_message("debug", $this->getModel()->getLastQuery());
return $entity;
}
@ -144,7 +143,6 @@ class ZoneService extends CloudflareService
}
//DB수정
$entity = $this->getModel()->modify($entity, $formDatas);
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["UPDATED"]);
// log_message("debug", $this->getModel()->getLastQuery());
return $entity;
}
@ -160,7 +158,6 @@ class ZoneService extends CloudflareService
foreach ($this->getModel()->getAllowedFields() as $field) {
MyLogService::add("info", "{$field}:{$entity->$field}");
}
MyLogService::add("info", __FUNCTION__ . " {$entity->getTitle()} " . MESSAGES["DELETED"]);
// log_message("debug", $this->getModel()->getLastQuery());
return $entity;
}

View File

@ -21,14 +21,26 @@ class MapurlService extends CommonService
}
public function create(array $formDatas): MapurlEntity
{
//생성값 formDatas Log남기기
foreach ($formDatas as $field => $value) {
MyLogService::add("info", "{$field}:{$value}");
}
return $this->getModel()->create($formDatas);
}
public function modify(MapurlEntity $entity, array $formDatas): MapurlEntity
{
//변경전 entity 값, 변경값 formDatas Log남기기
foreach ($formDatas as $field => $value) {
MyLogService::add("info", "{$field}:{$entity->$field}=>{$value}");
}
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
public function delete(MapurlEntity $entity): void
{
$this->getModel()->delete();
//삭제전 entity 값 Log남기기
foreach ($this->getModel()->getAllowedFields() as $field) {
MyLogService::add("info", "{$field}:{$entity->$field}");
}
$this->getModel()->delete($entity->getPK());
}
}

View File

@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\UserSNSModel;
use App\Entities\UserSNSEntity;
use Google\Service\AndroidEnterprise\Resource\Users;
class UserSNSService extends CommonService
{
@ -27,8 +28,8 @@ class UserSNSService extends CommonService
{
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
public function delete(UserSNSEntity $entity): void
{
$this->getModel()->delete();
$this->getModel()->delete($entity->getPK());
}
}

View File

@ -39,8 +39,8 @@ class UserService extends CommonService
// die(var_export($formDatas, true));
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
public function delete(UserEntity $entity): void
{
$this->getModel()->delete();
$this->getModel()->delete($entity);
}
}