diff --git a/app/Controllers/Crawler/YamapController.php b/app/Controllers/Crawler/YamapController.php index 8e12734..5f73a11 100644 --- a/app/Controllers/Crawler/YamapController.php +++ b/app/Controllers/Crawler/YamapController.php @@ -34,12 +34,23 @@ class YamapController extends CommonController if (!count($items)) { throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다."); } - //최초 게시물만 등록하기 위함 - $item = $items[0]; - //3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리 - $fileEntitys = $crawler->detailPage($item["detail_url"]); - //4.망보드 일반게시판에 게시물 등록 처리 - $crawler->createBoard($item, $fileEntitys); + $max_limit = intval(getenv("yamap.list.item.max_limit")); + $max_limit = count($items) <= $max_limit ? $items : $max_limit; + $i = 0; + foreach ($items as $item) { + if ($i <= $max_limit) { + try { + //3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리 + $fileEntitys = $crawler->detailPage($item["detail_url"]); + //4.망보드 일반게시판에 게시물 등록 처리 + $crawler->createBoard($item, $fileEntitys); + log_message("notice", "{$i}번째 {$item["nickname"]} 작업완료."); + } catch (\Exception $e) { + log_message("debug", $e->getMessage()); + } + } + $i++; + } log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다."); return "완료되었습니다."; } catch (\Exception $e) { diff --git a/app/Entities/Mangboard/BoardEntity.php b/app/Entities/Mangboard/BoardEntity.php index 4034221..ca091aa 100644 --- a/app/Entities/Mangboard/BoardEntity.php +++ b/app/Entities/Mangboard/BoardEntity.php @@ -8,7 +8,7 @@ class BoardEntity extends CommonEntity { public function __toString(): string { - return "{$this->getPK()}:{$this->getTitle()}"; + return "{$this->getPK()}|{$this->getTitle()}"; } public function getTitle(): string { diff --git a/app/Entities/Mangboard/FileEntity.php b/app/Entities/Mangboard/FileEntity.php index e213cca..90345c8 100644 --- a/app/Entities/Mangboard/FileEntity.php +++ b/app/Entities/Mangboard/FileEntity.php @@ -8,7 +8,7 @@ class FileEntity extends MyStorageEntity { public function __toString(): string { - return "{$this->getPK()}:{$this->getTitle()}"; + return "{$this->getPK()}|{$this->getTitle()}|{$this->getSequence()}번째"; } //Common Function diff --git a/app/Entities/Mangboard/UserEntity.php b/app/Entities/Mangboard/UserEntity.php index 492f45b..601939a 100644 --- a/app/Entities/Mangboard/UserEntity.php +++ b/app/Entities/Mangboard/UserEntity.php @@ -8,7 +8,7 @@ class UserEntity extends CommonEntity { public function __toString(): string { - return "{$this->getPK()}:{$this->getID()}:{$this->getTitle()},{$this->getLevel()}/{$this->getPoint()}"; + return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}|lvl:{$this->getLevel()},point:{$this->getPoint()}"; } public function getTitle(): string { diff --git a/app/Entities/MyStorage/FileEntity.php b/app/Entities/MyStorage/FileEntity.php index 0b0a2b1..c666228 100644 --- a/app/Entities/MyStorage/FileEntity.php +++ b/app/Entities/MyStorage/FileEntity.php @@ -12,7 +12,7 @@ class FileEntity extends CommonEntity } public function __toString(): string { - return "{$this->getTitle()}"; + return "{$this->getPath()}|{$this->getTitle()}|{$this->getMimeType()}"; } public function getTitle(): string { diff --git a/app/Entities/SNSUserEntity.php b/app/Entities/SNSUserEntity.php index 0771c09..476a06c 100644 --- a/app/Entities/SNSUserEntity.php +++ b/app/Entities/SNSUserEntity.php @@ -8,7 +8,7 @@ class SNSUserEntity extends CommonEntity { public function __toString(): string { - return "{$this->getPK()}:{$this->getID()}:{$this->getTitle()},{$this->getLevel()}/{$this->getPoint()}"; + return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}"; } public function getTitle(): string { @@ -28,22 +28,4 @@ class SNSUserEntity extends CommonEntity { return $this->attributes['id']; } - public function getPoint(): int - { - return $this->attributes['point']; - } - public function setPoint(int $point): void - { - - $this->attributes['point'] = $point; - } - - public function getLevel(): int - { - return $this->attributes['level']; - } - public function setLevel(int $value): void - { - $this->attributes['level'] = $value; - } } diff --git a/app/Libraries/MyCrawler/YamapLibrary.php b/app/Libraries/MyCrawler/YamapLibrary.php index f7d62be..07be3fa 100644 --- a/app/Libraries/MyCrawler/YamapLibrary.php +++ b/app/Libraries/MyCrawler/YamapLibrary.php @@ -131,7 +131,7 @@ class YamapLibrary extends MyCrawlerLibrary // exit; //망보드 게시판에 등록 $entity = $this->getBoardModel()->create($entity); - log_message("debug", __FUNCTION__ . "=>등록이 완료되었습니다."); + log_message("debug", "Board DB 등록 완료"); //망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기 foreach ($fileEntitys as $fileEntity) { diff --git a/app/Libraries/MyStorage/FileLibrary.php b/app/Libraries/MyStorage/FileLibrary.php index 82df807..02458ff 100644 --- a/app/Libraries/MyStorage/FileLibrary.php +++ b/app/Libraries/MyStorage/FileLibrary.php @@ -47,26 +47,28 @@ class FileLibrary extends MyStorageLibrary return $mediaTag; } - public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity + public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity { $fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath(); if (!is_dir($fullPath)) { if (!mkdir($fullPath)) { - throw new \Exception("Make Directory Error:" . $fullPath); + throw new \Exception("디렉토리 생성 실패:{$fullPath}"); } } $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName; - log_message("debug", "Storage Save-> " . $saveFilePath); - if (!file_put_contents($saveFilePath, $content)) { - return null; + if (file_exists($saveFilePath)) { + throw new \Exception("이미 존재하는 파일:{$saveFilePath}"); + } + if (!file_put_contents($saveFilePath, $content)) { + throw new \Exception("파일저장 실패:{$saveFilePath}"); } - $entity = new FileEntity(); $entity->setPath($this->getPath()); $entity->setTitle($fileName); $entity->setMimeType(mime_content_type($saveFilePath)); $entity->setSize(filesize($saveFilePath)); $entity->setMediaHTML($this->getMediaTag($mediaType, $entity)); + log_message("debug", "{$file_sequence}번째 파일저장 완료->{$entity}"); return $entity; } } diff --git a/app/Libraries/MyStorage/MangboardLibrary.php b/app/Libraries/MyStorage/MangboardLibrary.php index 6bcff8c..138e456 100644 --- a/app/Libraries/MyStorage/MangboardLibrary.php +++ b/app/Libraries/MyStorage/MangboardLibrary.php @@ -3,8 +3,8 @@ namespace App\Libraries\MyStorage; -use App\Models\Mangboard\FileModel; use App\Libraries\MyStorage\FileLibrary; +use App\Models\Mangboard\FileModel; use App\Entities\Mangboard\UserEntity; use App\Entities\Mangboard\FileEntity; use App\Entities\Mangboard\BoardEntity; @@ -76,29 +76,25 @@ class MangboardLibrary extends FileLibrary } - public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity + public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity { + $entity = parent::save($fileName, $mediaType, $content, $file_sequence); + log_message("debug", "{$file_sequence}번째 File DB등록 준비->{$entity->getTitle()}|{$entity->getMimeType()}"); //망보드 파일관리 table에 등록 - try { - $entity = parent::save($fileName, $mediaType, $content, $file_sequence); - if (!$entity) { - return null; - } - $entity = new FileEntity($entity->toRawArray()); //형변환을 위해서 - $entity->setPath($this->getPath()); - $entity->user_pid = $this->getUser()->getPK(); - $entity->user_name = $this->getUser()->getTitle(); - $entity->board_name = $this->getBoardName(); - $entity->table_name = $this->getBoardTable(); - $entity->reg_date = date("Y-m-d H:i:s"); - $entity->file_description = "Filedata"; - $entity->setSequence($file_sequence); - $entity = $this->getModel()->create($entity); - return $entity; - } catch (\Exception $e) { - log_message("error", $e->getMessage()); - return null; - } + $entity = new FileEntity($entity->toArray()); //형변환을 위해서 + $entity->setPath($this->getPath()); + $entity->user_pid = $this->getUser()->getPK(); + $entity->user_name = $this->getUser()->getTitle(); + $entity->board_name = $this->getBoardName(); + $entity->table_name = $this->getBoardTable(); + $entity->reg_date = date("Y-m-d H:i:s"); + $entity->file_caption = $fileName; + $entity->file_alt = $entity->getTitle(); + $entity->file_description = "Filedata"; + $entity->setSequence($file_sequence); + $entity = $this->getModel()->create($entity); + log_message("debug", "{$file_sequence}번째 File DB등록 완료->{$entity}"); + return $entity; } public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php index a1a3697..ea50cb3 100644 --- a/app/Models/Mangboard/FileModel.php +++ b/app/Models/Mangboard/FileModel.php @@ -47,8 +47,10 @@ class FileModel extends CommonModel "file_name", "file_path", "file_type", - "file_size", + "file_caption", + "file_alt", "file_description", + "file_size", "file_sequence", "reg_date" ]; @@ -75,6 +77,8 @@ class FileModel extends CommonModel $rules[$field] = "required|trim|string"; break; case "file_description": + case "file_caption": + case "file_alt": $rules[$field] = "if_exist|trim|string"; break; case "reg_date":