Automation init...4

This commit is contained in:
최준흠 2024-09-23 10:16:15 +09:00
parent 67e107d271
commit 522b170463
4 changed files with 19 additions and 23 deletions

View File

@ -180,7 +180,8 @@ abstract class MyCrawler extends CommonLibrary
return $storages; 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 등록작업등 //Board DB 등록작업등
//미디어관련정보 entity에 넣기 //미디어관련정보 entity에 넣기
@ -221,14 +222,12 @@ abstract class MyCrawler extends CommonLibrary
)); ));
return $board_entity; 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) { foreach ($storages as $storage) {
try { try {
$storage->backend_process($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable()); $storage->create($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable());
} catch (\Exception $e) { } catch (\Exception $e) {
log_message("notice", sprintf( log_message("notice", sprintf(
"\n---%s -> %s 게시물의 %s번째:%s 파일 등록 오류---\n%s\n--------------------------------\n", "\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); list($selector, $listInfo) = $this->getDetailSelector($listInfo);
$formDatas = []; $formDatas = [];
$formDatas['image_path'] = ""; $formDatas['image_path'] = "";
$formDatas['content'] = $selector->html(); $formDatas['content'] = $selector->html();
//Board 등록작업등 //Board 등록작업등
$this->create_board_process($cnt, $listInfo, [], $formDatas); $this->create_board($cnt, $listInfo, [], $formDatas);
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다."); log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
return $listInfo; return $listInfo;
} }
@ -271,7 +269,10 @@ abstract class MyCrawler extends CommonLibrary
if (!count($storages)) { if (!count($storages)) {
throw new \Exception("등록할 자료가 없습니다."); 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__ . " 작업이 완료되었습니다."); log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
return $listInfo; return $listInfo;
@ -287,7 +288,7 @@ abstract class MyCrawler extends CommonLibrary
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작"); log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작");
try { try {
if ($this->isCopy) { if ($this->isCopy) {
$listInfo = $this->detail_content_process($i, $listInfo); $listInfo = $this->detail_copy_process($i, $listInfo);
} else { } else {
//listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다. //listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다.
$listInfo = $this->detail_download_process($i, $listInfo); $listInfo = $this->detail_download_process($i, $listInfo);

View File

@ -88,7 +88,7 @@ class MangboardStorage extends FileStorage
return $content; 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에 넣기 //File DB에 넣기
$formDatas['board_pid'] = $board_entity->getPk(); $formDatas['board_pid'] = $board_entity->getPk();

View File

@ -197,9 +197,7 @@ abstract class CommonModel extends Model
var_export($this->errors(), true) var_export($this->errors(), true)
)); ));
} }
log_message("debug", $this->table . "=> " . __FUNCTION__ . " 작업 완료");
} }
log_message("debug", $this->table . "=> " . __FUNCTION__ . " 데이터 변환없음");
return $entity; return $entity;
} }
final protected function create_process($entity, array $formDatas): mixed final protected function create_process($entity, array $formDatas): mixed
@ -217,6 +215,7 @@ abstract class CommonModel extends Model
$pkField = $this->getPKField(); $pkField = $this->getPKField();
$entity->$pkField = $this->getInsertID(); $entity->$pkField = $this->getInsertID();
} }
log_message("debug", $this->table . "=> " . __FUNCTION__ . " 작업 완료");
return $entity; return $entity;
} }
final protected function modify_process($entity, array $formDatas): mixed final protected function modify_process($entity, array $formDatas): mixed
@ -229,6 +228,7 @@ abstract class CommonModel extends Model
$entity->$field = $this->convertEntityData($field, $formDatas); $entity->$field = $this->convertEntityData($field, $formDatas);
} }
$this->save_process($entity); $this->save_process($entity);
log_message("debug", $this->table . "=> " . __FUNCTION__ . " 작업 완료");
return $entity; return $entity;
} }
} }

View File

@ -116,20 +116,15 @@ trait ImageTrait
$this->save_ImageTrait($storage->getFullPath() . DIRECTORY_SEPARATOR . $target_file_name); $this->save_ImageTrait($storage->getFullPath() . DIRECTORY_SEPARATOR . $target_file_name);
// 메모리 해제 // 메모리 해제
$this->destroy_ImageTrait(); $this->destroy_ImageTrait();
log_message("debug", sprintf( log_message("notice", sprintf(
"%s %s->%s(W:%s,H:%s) 작업완료)", "%s -> %s 게시물의 %s번째:%s->%s 작은이미지(W:%s,H:%s) 생성 완료",
__FUNCTION__, __FUNCTION__,
$board_entity->getTitle(),
$storage->getOriginSequence(),
$storage->getOriginName(), $storage->getOriginName(),
$target_file_name, $target_file_name,
$width, $width,
$height $height
)); ));
log_message("notice", sprintf(
"%s -> %s 게시물의 %s번째:%s 작은이미지 생성 완료",
__FUNCTION__,
$board_entity->getTitle(),
$storage->getOriginSequence(),
$target_file_name
));
} }
} }