From 2dc97d782e6b4a24592fa4726f8089c66a2ac345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Thu, 19 Sep 2024 23:19:54 +0900 Subject: [PATCH] Automation init...3 --- .../Cloudflare/AccountController.php | 69 +++++--------- .../Cloudflare/Admin/AccountController.php | 52 +++++++++++ app/Controllers/Cloudflare/MyCloudflare.php | 22 +++++ .../Mangboard/Crawler/InvenCrawler.php | 10 +- .../MyCrawler.php} | 50 ++++++++-- .../Mangboard/Crawler/SirCrawler.php | 10 +- .../Mangboard/Crawler/YamapCrawler.php | 8 +- .../Mangboard/Crawler/YamoonCrawler.php | 8 +- .../MySocket/Cloudflare/AccountSocket.php | 3 - app/Libraries/MySocket/CloudflareSocket.php | 1 - .../MyStorage/Cloudflare/AccountStorage.php | 51 ++++++++++ app/Libraries/MyStorage/MangboardStorage.php | 34 +++++-- app/Models/Cloudflare/AccountModel.php | 1 + app/Models/Cloudflare/FirewallModel.php | 93 ------------------- app/Models/Mangboard/BoardModel.php | 46 --------- app/Models/Mangboard/FileModel.php | 33 ------- 16 files changed, 236 insertions(+), 255 deletions(-) create mode 100644 app/Controllers/Cloudflare/Admin/AccountController.php create mode 100644 app/Controllers/Cloudflare/MyCloudflare.php rename app/Controllers/Mangboard/{CrawlerController.php => Crawler/MyCrawler.php} (87%) create mode 100644 app/Libraries/MyStorage/Cloudflare/AccountStorage.php delete mode 100644 app/Models/Cloudflare/FirewallModel.php diff --git a/app/Controllers/Cloudflare/AccountController.php b/app/Controllers/Cloudflare/AccountController.php index 597a394..6f39ef8 100644 --- a/app/Controllers/Cloudflare/AccountController.php +++ b/app/Controllers/Cloudflare/AccountController.php @@ -1,67 +1,48 @@ session = $this->loginCheck_AuthTrait(); } - final public function getMySocket(string $email, $api_key): AccountSocket + final protected function getMySocket(): AccountSocket { if ($this->_mySocket === null) { - $this->_mySocket = new AccountSocket($email, $api_key); + $this->_mySocket = new AccountSocket($this->_email, $this->_api_key); } return $this->_mySocket; } - final public function getModel(): AccountModel + final protected function getMyStorage(): AccountStorage { - if ($this->_model === null) { - $this->_model = new AccountModel(); + if ($this->_myStorage === null) { + $this->_myStorage = new AccountStorage(); } - return $this->_model; + return $this->_myStorage; } - public function create(string $email, $api_key, array $formDatas = []) + + public function create(): void { + $this->_email = $this->request->getVar('email'); + $this->_api_key = $this->request->getVar('key'); //전송 - $result = $this->getMySocket($email, $api_key)->create($email); - //답변형태 - // [ - // {"id":"078e88a7735965b661715af13031ecb0", - // "name":"Cloudwin002@idcjp.jp's Account", - // "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"} - // ] - $formDatas[$this->getModel()->getTitleField()] = $email; - $formDatas['key'] = $api_key; - $formDatas[$this->getModel()->PK()] = $result->id; - $formDatas[$this->getModel()->getTitleField()] = $result->name; - $formDatas['type'] = $result->type; - $formDatas['status'] = 'use'; - $formDatas['updated_at'] = $result->created_on; - $formDatas['created_at'] = $result->created_on; - $entity = $this->getModel()->create($formDatas); - log_message("notice", __FUNCTION__ . "=> {$entity->getTitle()} 생성을 완료하였습니다."); + $result = $this->getMySocket()->create($this->_email); + $formDatas = []; + $formDatas['key'] = $this->_api_key; + $entity = $this->getMyStorage()->create_process($result, $formDatas); + log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); } } diff --git a/app/Controllers/Cloudflare/Admin/AccountController.php b/app/Controllers/Cloudflare/Admin/AccountController.php new file mode 100644 index 0000000..d6e679e --- /dev/null +++ b/app/Controllers/Cloudflare/Admin/AccountController.php @@ -0,0 +1,52 @@ +session = $this->loginCheck_AuthTrait(); + } + final protected function getMySocket(): AccountSocket + { + if ($this->_mySocket === null) { + $this->_mySocket = new AccountSocket($this->_email, $this->_api_key); + } + return $this->_mySocket; + } + final protected function getMyStorage(): AccountStorage + { + if ($this->_myStorage === null) { + $this->_myStorage = new AccountStorage(); + } + return $this->_myStorage; + } + + public function create(): void + { + $this->_email = $this->request->getVar('email'); + $this->_api_key = $this->request->getVar('key'); + //전송 + $result = $this->getMySocket()->create($this->_email); + $formDatas = []; + $formDatas['key'] = $this->_api_key; + $entity = $this->getMyStorage()->create_process($result, $formDatas); + log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); + } +} diff --git a/app/Controllers/Cloudflare/MyCloudflare.php b/app/Controllers/Cloudflare/MyCloudflare.php new file mode 100644 index 0000000..a712f76 --- /dev/null +++ b/app/Controllers/Cloudflare/MyCloudflare.php @@ -0,0 +1,22 @@ +getBoardModel()->createByCrawler( - $this->getBoardsEntity(), - $this->getUserEntity(), + //Board DB 등록작업등 + $formDatas = ['image_path' => "", 'content' => ""]; + //미디어관련정보 entity에 넣기 + $formDatas['title'] = $listInfo["title"]; + $formDatas['user_pid'] = $this->getUserEntity()->getPK(); + $formDatas['user_id'] = $this->getUserEntity()->getID(); + $formDatas['user_name'] = $listInfo["nickname"] != "" ? $listInfo["nickname"] : $this->getUserEntity()->getTitle(); + $formDatas['level'] = $this->getBoardsEntity()->getListLevel(); + $formDatas['hit'] = intval($listInfo['hit']); + $formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($listInfo['date'])); + $formDatas['data_type'] = "html"; + $formDatas['editor_type'] = "S"; + foreach ($storages as $storage) { + if ($formDatas['image_path'] == "") { + $formDatas['image_path'] = $storage->getBasePath() . DIRECTORY_SEPARATOR . $storage->getPath() . DIRECTORY_SEPARATOR . $storage->getOriginName(); + } + $formDatas['content'] .= $storage->getHTMLTag(); + } + //망보드 게시판에 등록 + if ($formDatas['content'] == "") { + throw new \Exception(sprintf( + "%s=>%s번째 %s 내용이 없어 => %s 등록 안함 : storage->%s", + __FUNCTION__, + $cnt, + $listInfo["title"], + $this->getBoardModel()->getTable(), + count($storages) + )); + } + $board_entity = $this->getBoardModel()->create($formDatas); + log_message("notice", sprintf( + "%s=>%s번째 %s => %s 등록 완료 : storage->%s", + __FUNCTION__, $cnt, - $listInfo, - $storages - ); + $listInfo["title"], + $this->getBoardModel()->getTable(), + count($storages) + )); + + //File DB 등록작업, 작은이미지 생성 foreach ($storages as $storage) { try { $storage->backend_process($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable()); diff --git a/app/Controllers/Mangboard/Crawler/SirCrawler.php b/app/Controllers/Mangboard/Crawler/SirCrawler.php index 38d8035..f499b15 100644 --- a/app/Controllers/Mangboard/Crawler/SirCrawler.php +++ b/app/Controllers/Mangboard/Crawler/SirCrawler.php @@ -2,14 +2,14 @@ namespace App\Controllers\Mangboard\Crawler; -use App\Controllers\Mangboard\CrawlerController; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\ResponseInterface; +use App\Controllers\Mangboard\MyCrawler; use Psr\Log\LoggerInterface; -use Symfony\Component\DomCrawler\Crawler; use DateTime; +use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\RequestInterface; +use Symfony\Component\DomCrawler\Crawler; -class SirCrawler extends CrawlerController +class SirCrawler extends MyCrawler { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { diff --git a/app/Controllers/Mangboard/Crawler/YamapCrawler.php b/app/Controllers/Mangboard/Crawler/YamapCrawler.php index 740daf7..e64b3b1 100644 --- a/app/Controllers/Mangboard/Crawler/YamapCrawler.php +++ b/app/Controllers/Mangboard/Crawler/YamapCrawler.php @@ -2,13 +2,13 @@ namespace App\Controllers\Mangboard\Crawler; -use App\Controllers\Mangboard\CrawlerController; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\ResponseInterface; +use App\Controllers\Mangboard\MyCrawler; use Psr\Log\LoggerInterface; +use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\RequestInterface; use Symfony\Component\DomCrawler\Crawler; -class YamapCrawler extends CrawlerController +class YamapCrawler extends MyCrawler { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { diff --git a/app/Controllers/Mangboard/Crawler/YamoonCrawler.php b/app/Controllers/Mangboard/Crawler/YamoonCrawler.php index be8ea82..6fa5dba 100644 --- a/app/Controllers/Mangboard/Crawler/YamoonCrawler.php +++ b/app/Controllers/Mangboard/Crawler/YamoonCrawler.php @@ -2,13 +2,13 @@ namespace App\Controllers\Mangboard\Crawler; -use App\Controllers\Mangboard\CrawlerController; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\ResponseInterface; +use App\Controllers\Mangboard\MyCrawler; use Psr\Log\LoggerInterface; +use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\RequestInterface; use Symfony\Component\DomCrawler\Crawler; -class YamoonCrawler extends CrawlerController +class YamoonCrawler extends MyCrawler { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { diff --git a/app/Libraries/MySocket/Cloudflare/AccountSocket.php b/app/Libraries/MySocket/Cloudflare/AccountSocket.php index 225b3f7..1c9c5b3 100644 --- a/app/Libraries/MySocket/Cloudflare/AccountSocket.php +++ b/app/Libraries/MySocket/Cloudflare/AccountSocket.php @@ -2,10 +2,7 @@ namespace App\Libraries\MySocket\Cloudflare; -use App\Entities\Cloudflare\AccountEntity; -use App\Libraries\CommonLibrary; use App\Libraries\MySocket\CloudflareSocket; -use Cloudflare\API\Auth\APIKey; class AccountSocket extends CloudflareSocket { diff --git a/app/Libraries/MySocket/CloudflareSocket.php b/app/Libraries/MySocket/CloudflareSocket.php index fbdd110..e443c21 100644 --- a/app/Libraries/MySocket/CloudflareSocket.php +++ b/app/Libraries/MySocket/CloudflareSocket.php @@ -3,7 +3,6 @@ namespace App\Libraries\MySocket; use App\Libraries\CommonLibrary; -use App\Entities\Cloudflare\AccountEntity; use Cloudflare\API\Adapter\Guzzle; use Cloudflare\API\Auth\APIKey; diff --git a/app/Libraries/MyStorage/Cloudflare/AccountStorage.php b/app/Libraries/MyStorage/Cloudflare/AccountStorage.php new file mode 100644 index 0000000..1cd282d --- /dev/null +++ b/app/Libraries/MyStorage/Cloudflare/AccountStorage.php @@ -0,0 +1,51 @@ +_accountModel === null) { + $this->_accountModel = new AccountModel(); + } + return $this->_accountModel; + } + + final public function create_process($result, array $formDatas): AccountEntity + { + //Result 형태 + // [ + // {"id":"078e88a7735965b661715af13031ecb0", + // "name":"Cloudwin002@idcjp.jp's Account", + // "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"} + // ] + $formDatas[$this->getAccountModel()->PK()] = $result->id; + $formDatas[$this->getAccountModel()->getTitleField()] = $result->name; + $formDatas['type'] = $result->type; + $formDatas['status'] = 'use'; + $formDatas['updated_at'] = $result->created_on; + $formDatas['created_at'] = $result->created_on; + $entity = $this->getAccountModel()->create($formDatas); + log_message("notice", __FUNCTION__ . "=> {$entity->getTitle()} 생성을 완료하였습니다."); + return $entity; + } +} diff --git a/app/Libraries/MyStorage/MangboardStorage.php b/app/Libraries/MyStorage/MangboardStorage.php index 248d674..b9a8071 100644 --- a/app/Libraries/MyStorage/MangboardStorage.php +++ b/app/Libraries/MyStorage/MangboardStorage.php @@ -74,15 +74,33 @@ class MangboardStorage extends FileStorage return $content; } - final public function backend_process(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table) + final public function backend_process(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): void { - $this->getFileModel()->createByCrawler( - $boards_entity, - $this->_user_entity, - $board_entity, - $board_table, - $this - ); + //File DB에 넣기 + $formDatas['board_pid'] = $board_entity->getPk(); + $formDatas['user_pid'] = $this->_user_entity->getPK(); + $formDatas['user_name'] = $this->_user_entity->getTitle(); + $formDatas['board_name'] = $boards_entity->getTitle(); + $formDatas['table_name'] = $board_table; + $formDatas['file_path'] = $this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath() . DIRECTORY_SEPARATOR . $this->getOriginName(); + $formDatas['file_name'] = $this->getOriginName(); + $formDatas['file_type'] = $this->getMimeType(); + $formDatas['file_caption'] = $this->getOriginName(); + $formDatas['file_alt'] = $this->getOriginName(); + $formDatas['file_description'] = "Filedata"; + $formDatas['file_size'] = $this->getFileSize(); + $formDatas['file_sequence'] = $this->getOriginSequence(); + $formDatas['reg_date'] = date("Y-m-d H:i:s"); + $entity = $this->getFileModel()->create($formDatas); + log_message("notice", sprintf( + "%s -> %s 게시물의 %s번째:%s 파일 등록 완료", + __FUNCTION__, + $board_entity->getTitle(), + $this->getOriginSequence(), + $entity->getTitle() + )); + + //작은이미지 만들기 $this->create_small_ImageTrait($board_entity, $this); } } diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/AccountModel.php index bf8fe0e..5dc99a9 100644 --- a/app/Models/Cloudflare/AccountModel.php +++ b/app/Models/Cloudflare/AccountModel.php @@ -10,6 +10,7 @@ class AccountModel extends Model { protected $table = 'cloudflareaccount'; protected $primaryKey = 'uid'; + protected $useAutoIncrement = false; protected $returnType = AccountEntity::class; //object,array,entity명::class protected $allowedFields = ['uid', 'email', 'key', 'oldkey', 'type', 'status', 'updated_at', 'created_at']; protected $useTimestamps = true; diff --git a/app/Models/Cloudflare/FirewallModel.php b/app/Models/Cloudflare/FirewallModel.php deleted file mode 100644 index fb6d614..0000000 --- a/app/Models/Cloudflare/FirewallModel.php +++ /dev/null @@ -1,93 +0,0 @@ - "if_exist|min_length[10]|max_length[200]", - "zone_uid" => "if_exist|min_length[10]|max_length[200]", - "description" => "if_exist|string", - "filter_id" => "if_exist|min_length[10]|max_length[200]", - "filter_expression" => "if_exist|string", - "filter_paused" => "if_exist|in_list[on,off]", - "paused" => "if_exist|in_list[on,off]", - "action" => "if_exist|string", - "updated_at" => "if_exist|valid_date", - "created_at" => "if_exist|valid_date", - ]; - protected $validationMessages = []; - protected $skipValidation = true; - protected $cleanValidationRules = true; - - // Callbacks - protected $allowCallbacks = true; - protected $beforeInsert = []; - protected $afterInsert = []; - protected $beforeUpdate = []; - protected $afterUpdate = []; - protected $beforeFind = []; - protected $afterFind = []; - protected $beforeDelete = []; - protected $afterDelete = []; - - public function getTableName() - { - return $this->table; - } - - public function getEntity(string $uid): FirewallEntity - { - $entity = $this->asObject(FirewallEntity::class)->where("uid", $uid)->first(); - if (is_null($entity)) { - throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다."); - } - return $entity; - } - public function getEntitys(array $wheres) - { - return $this->asObject(FirewallEntity::class)->where($wheres)->findAll(); - } - public function getEntitysByZone(ZoneEntity $zone) - { - return $this->getEntitys([self::PARENT_FIELD, $zone->getPrimaryKey()]); - } - - //Index 검색용 - public function setIndexWordFilter(string $word) - { - $this->like("description", $word, "both"); //befor , after , both - } - public function setIndexDateFilter($start, $end) - { - $this->where("created_at >=", $start); - $this->where("created_at <=", $end); - } - public function setIndexOrderBy($field, $order = "ASC") - { - $this->orderBy("zone_uid ASC, description ASC, {$field} {$order}"); - } -} diff --git a/app/Models/Mangboard/BoardModel.php b/app/Models/Mangboard/BoardModel.php index 608a207..6aee6a1 100644 --- a/app/Models/Mangboard/BoardModel.php +++ b/app/Models/Mangboard/BoardModel.php @@ -149,50 +149,4 @@ class BoardModel extends CommonModel { return $this->modify_process($entity, $formDatas); } - public function createByCrawler( - BoardsEntity $boards_entity, - UserEntity $user_entity, - int $cnt, - array $listInfo, - array $storages = [], - array $formDatas = ['image_path' => "", 'content' => ""] - ): BoardEntity { - //미디어관련정보 entity에 넣기 - $formDatas['title'] = $listInfo["title"]; - $formDatas['user_pid'] = $user_entity->getPK(); - $formDatas['user_id'] = $user_entity->getID(); - $formDatas['user_name'] = $listInfo["nickname"] != "" ? $listInfo["nickname"] : $user_entity->getTitle(); - $formDatas['level'] = $boards_entity->getListLevel(); - $formDatas['hit'] = intval($listInfo['hit']); - $formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($listInfo['date'])); - $formDatas['data_type'] = "html"; - $formDatas['editor_type'] = "S"; - foreach ($storages as $storage) { - if ($formDatas['image_path'] == "") { - $formDatas['image_path'] = $storage->getBasePath() . DIRECTORY_SEPARATOR . $storage->getPath() . DIRECTORY_SEPARATOR . $storage->getOriginName(); - } - $formDatas['content'] .= $storage->getHTMLTag(); - } - //망보드 게시판에 등록 - if ($formDatas['content'] == "") { - throw new \Exception(sprintf( - "%s=>%s번째 %s 내용이 없어 => %s 등록 안함 : storage->%s", - __FUNCTION__, - $cnt, - $listInfo["title"], - $this->getTable(), - count($storages) - )); - } - $entity = $this->create($formDatas); - log_message("notice", sprintf( - "%s=>%s번째 %s => %s 등록 완료 : storage->%s", - __FUNCTION__, - $cnt, - $listInfo["title"], - $this->getTable(), - count($storages) - )); - return $entity; - } } diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php index 22de1f9..6d5c748 100644 --- a/app/Models/Mangboard/FileModel.php +++ b/app/Models/Mangboard/FileModel.php @@ -125,37 +125,4 @@ class FileModel extends CommonModel { return $this->modify_process($entity, $formDatas); } - public function createByCrawler( - BoardsEntity $boards_entity, - UserEntity $user_entity, - BoardEntity $board_entity, - string $board_table, - MangboardStorage $storage, - array $formDatas = [] - ): FileEntity { - //Board PID 넣기 - $formDatas['board_pid'] = $board_entity->getPk(); - $formDatas['user_pid'] = $user_entity->getPK(); - $formDatas['user_name'] = $user_entity->getTitle(); - $formDatas['board_name'] = $boards_entity->getTitle(); - $formDatas['table_name'] = $board_table; - $formDatas['file_path'] = $storage->getBasePath() . DIRECTORY_SEPARATOR . $storage->getPath() . DIRECTORY_SEPARATOR . $storage->getOriginName(); - $formDatas['file_name'] = $storage->getOriginName(); - $formDatas['file_type'] = $storage->getMimeType(); - $formDatas['file_caption'] = $storage->getOriginName(); - $formDatas['file_alt'] = $storage->getOriginName(); - $formDatas['file_description'] = "Filedata"; - $formDatas['file_size'] = $storage->getFileSize(); - $formDatas['file_sequence'] = $storage->getOriginSequence(); - $formDatas['reg_date'] = date("Y-m-d H:i:s"); - $entity = $this->create($formDatas); - log_message("notice", sprintf( - "%s -> %s 게시물의 %s번째:%s 파일 등록 완료", - __FUNCTION__, - $board_entity->getTitle(), - $storage->getOriginSequence(), - $entity->getTitle() - )); - return $entity; - } }