Automation init...3

This commit is contained in:
최준흠 2024-09-09 20:41:06 +09:00
parent ff17626b53
commit 1f42a513f8
10 changed files with 54 additions and 59 deletions

View File

@ -34,12 +34,23 @@ class YamapController extends CommonController
if (!count($items)) { if (!count($items)) {
throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다."); throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다.");
} }
//최초 게시물만 등록하기 위함 $max_limit = intval(getenv("yamap.list.item.max_limit"));
$item = $items[0]; $max_limit = count($items) <= $max_limit ? $items : $max_limit;
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리 $i = 0;
$fileEntitys = $crawler->detailPage($item["detail_url"]); foreach ($items as $item) {
//4.망보드 일반게시판에 게시물 등록 처리 if ($i <= $max_limit) {
$crawler->createBoard($item, $fileEntitys); 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__ . " 작업이 완료되었습니다."); log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
return "완료되었습니다."; return "완료되었습니다.";
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -8,7 +8,7 @@ class BoardEntity extends CommonEntity
{ {
public function __toString(): string public function __toString(): string
{ {
return "{$this->getPK()}:{$this->getTitle()}"; return "{$this->getPK()}|{$this->getTitle()}";
} }
public function getTitle(): string public function getTitle(): string
{ {

View File

@ -8,7 +8,7 @@ class FileEntity extends MyStorageEntity
{ {
public function __toString(): string public function __toString(): string
{ {
return "{$this->getPK()}:{$this->getTitle()}"; return "{$this->getPK()}|{$this->getTitle()}|{$this->getSequence()}번째";
} }
//Common Function //Common Function

View File

@ -8,7 +8,7 @@ class UserEntity extends CommonEntity
{ {
public function __toString(): string 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 public function getTitle(): string
{ {

View File

@ -12,7 +12,7 @@ class FileEntity extends CommonEntity
} }
public function __toString(): string public function __toString(): string
{ {
return "{$this->getTitle()}"; return "{$this->getPath()}|{$this->getTitle()}|{$this->getMimeType()}";
} }
public function getTitle(): string public function getTitle(): string
{ {

View File

@ -8,7 +8,7 @@ class SNSUserEntity extends CommonEntity
{ {
public function __toString(): string 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 public function getTitle(): string
{ {
@ -28,22 +28,4 @@ class SNSUserEntity extends CommonEntity
{ {
return $this->attributes['id']; 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;
}
} }

View File

@ -131,7 +131,7 @@ class YamapLibrary extends MyCrawlerLibrary
// exit; // exit;
//망보드 게시판에 등록 //망보드 게시판에 등록
$entity = $this->getBoardModel()->create($entity); $entity = $this->getBoardModel()->create($entity);
log_message("debug", __FUNCTION__ . "=>등록이 완료되었습니다."); log_message("debug", "Board DB 등록 완료");
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기 //망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
foreach ($fileEntitys as $fileEntity) { foreach ($fileEntitys as $fileEntity) {

View File

@ -47,26 +47,28 @@ class FileLibrary extends MyStorageLibrary
return $mediaTag; 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(); $fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
if (!is_dir($fullPath)) { if (!is_dir($fullPath)) {
if (!mkdir($fullPath)) { if (!mkdir($fullPath)) {
throw new \Exception("Make Directory Error:" . $fullPath); throw new \Exception("디렉토리 생성 실패:{$fullPath}");
} }
} }
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName; $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
log_message("debug", "Storage Save-> " . $saveFilePath); if (file_exists($saveFilePath)) {
if (!file_put_contents($saveFilePath, $content)) { throw new \Exception("이미 존재하는 파일:{$saveFilePath}");
return null; }
if (!file_put_contents($saveFilePath, $content)) {
throw new \Exception("파일저장 실패:{$saveFilePath}");
} }
$entity = new FileEntity(); $entity = new FileEntity();
$entity->setPath($this->getPath()); $entity->setPath($this->getPath());
$entity->setTitle($fileName); $entity->setTitle($fileName);
$entity->setMimeType(mime_content_type($saveFilePath)); $entity->setMimeType(mime_content_type($saveFilePath));
$entity->setSize(filesize($saveFilePath)); $entity->setSize(filesize($saveFilePath));
$entity->setMediaHTML($this->getMediaTag($mediaType, $entity)); $entity->setMediaHTML($this->getMediaTag($mediaType, $entity));
log_message("debug", "{$file_sequence}번째 파일저장 완료->{$entity}");
return $entity; return $entity;
} }
} }

View File

@ -3,8 +3,8 @@
namespace App\Libraries\MyStorage; namespace App\Libraries\MyStorage;
use App\Models\Mangboard\FileModel;
use App\Libraries\MyStorage\FileLibrary; use App\Libraries\MyStorage\FileLibrary;
use App\Models\Mangboard\FileModel;
use App\Entities\Mangboard\UserEntity; use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\FileEntity; use App\Entities\Mangboard\FileEntity;
use App\Entities\Mangboard\BoardEntity; 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에 등록 //망보드 파일관리 table에 등록
try { $entity = new FileEntity($entity->toArray()); //형변환을 위해서
$entity = parent::save($fileName, $mediaType, $content, $file_sequence); $entity->setPath($this->getPath());
if (!$entity) { $entity->user_pid = $this->getUser()->getPK();
return null; $entity->user_name = $this->getUser()->getTitle();
} $entity->board_name = $this->getBoardName();
$entity = new FileEntity($entity->toRawArray()); //형변환을 위해서 $entity->table_name = $this->getBoardTable();
$entity->setPath($this->getPath()); $entity->reg_date = date("Y-m-d H:i:s");
$entity->user_pid = $this->getUser()->getPK(); $entity->file_caption = $fileName;
$entity->user_name = $this->getUser()->getTitle(); $entity->file_alt = $entity->getTitle();
$entity->board_name = $this->getBoardName(); $entity->file_description = "Filedata";
$entity->table_name = $this->getBoardTable(); $entity->setSequence($file_sequence);
$entity->reg_date = date("Y-m-d H:i:s"); $entity = $this->getModel()->create($entity);
$entity->file_description = "Filedata"; log_message("debug", "{$file_sequence}번째 File DB등록 완료->{$entity}");
$entity->setSequence($file_sequence); return $entity;
$entity = $this->getModel()->create($entity);
return $entity;
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return null;
}
} }
public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity

View File

@ -47,8 +47,10 @@ class FileModel extends CommonModel
"file_name", "file_name",
"file_path", "file_path",
"file_type", "file_type",
"file_size", "file_caption",
"file_alt",
"file_description", "file_description",
"file_size",
"file_sequence", "file_sequence",
"reg_date" "reg_date"
]; ];
@ -75,6 +77,8 @@ class FileModel extends CommonModel
$rules[$field] = "required|trim|string"; $rules[$field] = "required|trim|string";
break; break;
case "file_description": case "file_description":
case "file_caption":
case "file_alt":
$rules[$field] = "if_exist|trim|string"; $rules[$field] = "if_exist|trim|string";
break; break;
case "reg_date": case "reg_date":