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)) {
throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다.");
}
//최초 게시물만 등록하기 위함
$item = $items[0];
$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) {

View File

@ -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
{

View File

@ -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

View File

@ -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
{

View File

@ -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
{

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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
{
//망보드 파일관리 table에 등록
try {
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
if (!$entity) {
return null;
}
$entity = new FileEntity($entity->toRawArray()); //형변환을 위해서
log_message("debug", "{$file_sequence}번째 File DB등록 준비->{$entity->getTitle()}|{$entity->getMimeType()}");
//망보드 파일관리 table에 등록
$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;
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return null;
}
}
public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity

View File

@ -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":