From 522b17046393ddd815ed169bf8f6ba06f38b7a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Mon, 23 Sep 2024 10:16:15 +0900 Subject: [PATCH] Automation init...4 --- app/Libraries/MyCrawler/MyCrawler.php | 23 ++++++++++---------- app/Libraries/MyStorage/MangboardStorage.php | 2 +- app/Models/CommonModel.php | 4 ++-- app/Traits/ImageTrait.php | 13 ++++------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/app/Libraries/MyCrawler/MyCrawler.php b/app/Libraries/MyCrawler/MyCrawler.php index a9ccdb0..7de618d 100644 --- a/app/Libraries/MyCrawler/MyCrawler.php +++ b/app/Libraries/MyCrawler/MyCrawler.php @@ -180,7 +180,8 @@ abstract class MyCrawler extends CommonLibrary return $storages; } - private function create_board_process(int $cnt, array $listInfo, array $storages, array $formDatas = ['image_path' => "", 'content' => ""]): BoardEntity + //Board 등록작업 + private function create_board(int $cnt, array $listInfo, array $storages, array $formDatas = ['image_path' => "", 'content' => ""]): BoardEntity { //Board DB 등록작업등 //미디어관련정보 entity에 넣기 @@ -221,14 +222,12 @@ abstract class MyCrawler extends CommonLibrary )); return $board_entity; } - private function backend_process(int $cnt, array $listInfo, array $storages): void + //File DB 등록작업, 작은이미지 생성 + private function create_storages(BoardEntity $board_entity, array $storages) { - //Board 등록작업등 - $board_entity = $this->create_board_process($cnt, $listInfo, $storages); - //File DB 등록작업, 작은이미지 생성 foreach ($storages as $storage) { try { - $storage->backend_process($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable()); + $storage->create($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable()); } catch (\Exception $e) { log_message("notice", sprintf( "\n---%s -> %s 게시물의 %s번째:%s 파일 등록 오류---\n%s\n--------------------------------\n", @@ -240,16 +239,15 @@ abstract class MyCrawler extends CommonLibrary )); } } - log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다."); } - private function detail_content_process(int $cnt, array $listInfo): array + private function detail_copy_process(int $cnt, array $listInfo): array { list($selector, $listInfo) = $this->getDetailSelector($listInfo); $formDatas = []; $formDatas['image_path'] = ""; $formDatas['content'] = $selector->html(); //Board 등록작업등 - $this->create_board_process($cnt, $listInfo, [], $formDatas); + $this->create_board($cnt, $listInfo, [], $formDatas); log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다."); return $listInfo; } @@ -271,7 +269,10 @@ abstract class MyCrawler extends CommonLibrary if (!count($storages)) { throw new \Exception("등록할 자료가 없습니다."); } - $this->backend_process($cnt, $listInfo, $storages); + //Board 등록작업등 + $board_entity = $this->create_board($cnt, $listInfo, $storages); + //File DB 등록작업, 작은이미지 생성 + $this->create_storages($board_entity, $storages); } log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다."); return $listInfo; @@ -287,7 +288,7 @@ abstract class MyCrawler extends CommonLibrary log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작"); try { if ($this->isCopy) { - $listInfo = $this->detail_content_process($i, $listInfo); + $listInfo = $this->detail_copy_process($i, $listInfo); } else { //listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다. $listInfo = $this->detail_download_process($i, $listInfo); diff --git a/app/Libraries/MyStorage/MangboardStorage.php b/app/Libraries/MyStorage/MangboardStorage.php index bd2f8d2..af78bd4 100644 --- a/app/Libraries/MyStorage/MangboardStorage.php +++ b/app/Libraries/MyStorage/MangboardStorage.php @@ -88,7 +88,7 @@ class MangboardStorage extends FileStorage return $content; } - final public function backend_process(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): void + final public function create(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): void { //File DB에 넣기 $formDatas['board_pid'] = $board_entity->getPk(); diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index a7c9021..ba828b5 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -197,9 +197,7 @@ abstract class CommonModel extends Model var_export($this->errors(), true) )); } - log_message("debug", $this->table . "=> " . __FUNCTION__ . " 작업 완료"); } - log_message("debug", $this->table . "=> " . __FUNCTION__ . " 데이터 변환없음"); return $entity; } final protected function create_process($entity, array $formDatas): mixed @@ -217,6 +215,7 @@ abstract class CommonModel extends Model $pkField = $this->getPKField(); $entity->$pkField = $this->getInsertID(); } + log_message("debug", $this->table . "=> " . __FUNCTION__ . " 작업 완료"); return $entity; } final protected function modify_process($entity, array $formDatas): mixed @@ -229,6 +228,7 @@ abstract class CommonModel extends Model $entity->$field = $this->convertEntityData($field, $formDatas); } $this->save_process($entity); + log_message("debug", $this->table . "=> " . __FUNCTION__ . " 작업 완료"); return $entity; } } diff --git a/app/Traits/ImageTrait.php b/app/Traits/ImageTrait.php index 8e289b3..9741778 100644 --- a/app/Traits/ImageTrait.php +++ b/app/Traits/ImageTrait.php @@ -116,20 +116,15 @@ trait ImageTrait $this->save_ImageTrait($storage->getFullPath() . DIRECTORY_SEPARATOR . $target_file_name); // 메모리 해제 $this->destroy_ImageTrait(); - log_message("debug", sprintf( - "%s %s->%s(W:%s,H:%s) 작업완료)", + log_message("notice", sprintf( + "%s -> %s 게시물의 %s번째:%s->%s 작은이미지(W:%s,H:%s) 생성 완료", __FUNCTION__, + $board_entity->getTitle(), + $storage->getOriginSequence(), $storage->getOriginName(), $target_file_name, $width, $height )); - log_message("notice", sprintf( - "%s -> %s 게시물의 %s번째:%s 작은이미지 생성 완료", - __FUNCTION__, - $board_entity->getTitle(), - $storage->getOriginSequence(), - $target_file_name - )); } }