Automation Init...3

This commit is contained in:
최준흠 2024-09-10 11:00:17 +09:00
parent a5b0a6feca
commit 17f7065f7b
9 changed files with 85 additions and 75 deletions

View File

@ -40,16 +40,16 @@ class YamapController extends CommonController
foreach ($items as $item) {
if ($i <= $max_limit) {
try {
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리
$fileEntitys = $crawler->detailPage($item["detail_url"]);
//4.망보드 일반게시판에 게시물 등록 처리
$crawler->createBoard($item, $fileEntitys);
log_message("notice", "{$i}번째 {$item["nickname"]} 작업완료.");
$i++;
log_message("notice", "게시물 {$i}번째 {$item["nickname"]} 작업완료.");
} catch (\Exception $e) {
log_message("debug", $e->getMessage());
}
}
$i++;
}
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
return "완료되었습니다.";

View File

@ -64,7 +64,7 @@ class YamapLibrary extends MyCrawlerLibrary
// getenv('daemonidc.login.url'),
// getenv('daemonidc.login.user_id'),
// getenv('daemonidc.login.user_password')
// );
// );
return $entity;
}
@ -75,7 +75,7 @@ class YamapLibrary extends MyCrawlerLibrary
//div.bbs_item를 가진 객체를 찾아서 같은 형식의 객체(sibling)를 배열로 넘김
$crawler->filter(getenv("yamap.list.item.tag"))->each(
function (Crawler $node) use (&$items): void {
//bbs_item에서 span.g_nickname 객체를 찾아서 작성자가 "관리자" 아닌지 확인 후 Return Bool
//bbs_item에서 span.g_nickname 객체를 찾아서 작성자가 "관리자" 아닌지 확인 후 Return Bool
$nickname = $node->filter(getenv("yamap.list.item.nickname.tag"))->text();
$hit = $node->filter(getenv("yamap.list.item.hit.tag"))->text();
$date = $node->filter(getenv("yamap.list.item.date.tag"))->text();
@ -131,9 +131,9 @@ class YamapLibrary extends MyCrawlerLibrary
// exit;
//망보드 게시판에 등록
$entity = $this->getBoardModel()->create($entity);
log_message("debug", "Board DB 등록 완료");
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
$this->getMyStorage()->setBoardPID($fileEntitys, $entity->getPK());
log_message("debug", $this->getBoardModel()->getTable() . " Table에 등록 완료");
return $entity;
}
}

View File

@ -74,12 +74,10 @@ class MangboardLibrary extends MyStorageLibrary
{
$this->_boardLevel = $boardLevel;
}
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()}");
// log_message("debug", $this->getModel()->getTable() . " Table에 {$file_sequence}번째 등록 준비->{$entity->getTitle()}|{$entity->getMimeType()}");
//망보드 파일관리 table에 등록
$entity->user_pid = $this->getUser()->getPK();
$entity->user_name = $this->getUser()->getTitle();
@ -89,19 +87,15 @@ class MangboardLibrary extends MyStorageLibrary
$entity->file_caption = $fileName;
$entity->file_alt = $entity->getTitle();
$entity->file_description = "Filedata";
log_message("debug", var_export($entity, true));
$entity = $this->getModel()->create($entity);
exit;
log_message("debug", "{$file_sequence}번째 File DB등록 완료->{$entity}");
log_message("debug", $this->getModel()->getTable() . " Table에 {$file_sequence}번째 등록 완료->{$entity}");
return $entity;
}
public function setBoardPID(array $fileEntitys, int $board_pid)
{
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
foreach ($fileEntitys as $fileEntity) {
$fileEntity->board_pid = $board_pid;
$this->getModel()->setFields(["board_pid"]);
$this->getModel()->modify($fileEntity);
}
}

View File

@ -46,10 +46,9 @@ abstract class CommonModel extends Model
protected $afterDelete = [];
private $_action = DB_ACTION["CREATE"];
protected function __construct(array $fields)
protected function __construct()
{
parent::__construct();
$this->setFields($fields);
}
abstract public function getTitleField(): string;
@ -65,7 +64,7 @@ abstract class CommonModel extends Model
{
return $this->_action = $action;
}
final public function getFields(array $options = []): array //options=>except or only
final public function getFields(array $options = []): array
{
if (isset($options['except'])) {
return array_diff_key($this->allowedFields, array_flip($options['except']));
@ -74,16 +73,12 @@ abstract class CommonModel extends Model
}
return $this->allowedFields;
}
final public function setFields(array $fields): void
{
$this->allowedFields = $fields;
}
final public function setFieldRules(array $fields, array $rules = []): void
final public function getFieldRules(array $fields, array $rules = []): array
{
foreach ($fields as $field) {
$rules = $this->getFieldRule($field, $rules);
}
$this->validationRules[$field] = $rules;
return $rules;
}
public function getFieldRule(string $field, array $rules): array
{
@ -169,8 +164,6 @@ abstract class CommonModel extends Model
}
//최종 변경사항이 있으면 저장
if ($entity->hasChanged()) {
//Field에 맞는 Validation Rule 재정의
$this->setFieldRules($this->getFields());
if (!$this->save($entity)) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->getLastQuery());
log_message("error", implode("\n", $this->errors()));
@ -184,6 +177,8 @@ abstract class CommonModel extends Model
final protected function create_process($entity): mixed
{
$this->setAction(DB_ACTION['CREATE']);
//Field에 맞는 Validation Rule 재정의
$this->setValidationRules($this->getFieldRules($this->getFields()));
//primaryKey가 수동입력이면
$pkField = $this->getPKField();
if (!$this->useAutoIncrement && $entity->$pkField === null) {
@ -196,11 +191,16 @@ abstract class CommonModel extends Model
if ($this->useAutoIncrement) {
$entity->$pkField = $this->getInsertID();
}
// log_message("debug", $this->getTable() . " CREATE 작업 완료");
return $entity;
}
final protected function modify_process($entity): mixed
{
$this->setAction(DB_ACTION['MODIFY']);
return $this->save_process($entity);
//Field에 맞는 Validation Rule 재정의
$this->setValidationRules($this->getFieldRules($this->getFields()));
$this->save_process($entity);
// log_message("debug", $this->getTable() . " MODIFY 작업 완료");
return $entity;
}
}

View File

@ -71,24 +71,24 @@ class BoardModel extends CommonModel
// protected $table = 'mb_board_free';
protected $primaryKey = 'pid';
protected $returnType = BoardEntity::class;
protected $allowedFields = [
"gid",
"title",
"user_pid",
"user_id",
"user_name",
"level",
"data_type",
"editor_type",
"image_path",
"reg_date",
"hit",
"content"
];
public function __construct(string $table)
{
$this->table = $table;
$fields = [
"title",
"user_pid",
"user_id",
"user_name",
"level",
"data_type",
"editor_type",
"image_path",
"reg_date",
"hit",
"content"
];
parent::__construct($fields);
parent::__construct();
}
public function getTitleField(): string
{
@ -98,7 +98,7 @@ class BoardModel extends CommonModel
{
switch ($field) {
case 'gid':
$rules[$field] = "required|numeric";
$rules[$field] = "if_exist|numeric";
break;
case "data_type":
$rules[$field] = "if_exist|trim|in_list[html,text]";
@ -138,11 +138,7 @@ class BoardModel extends CommonModel
//create용
public function create(BoardEntity $entity): BoardEntity
{
$entity = $this->create_process($entity);
//GID값이 PK랑 같은 값 전달 후 Entity 수정
$entity->gid = $entity->getPK();
$this->setFields(["gid"]);
return $this->modify($entity);
return $this->create_process($entity);
}
//modify용

View File

@ -35,26 +35,26 @@ class FileModel extends CommonModel
protected $table = 'mb_files';
protected $primaryKey = 'pid';
protected $returnType = FileEntity::class;
protected $allowedFields = [
"user_pid",
"user_name",
"board_pid",
"board_name",
"table_name",
"file_name",
"file_path",
"file_type",
"file_caption",
"file_alt",
"file_description",
"file_size",
"file_sequence",
"reg_date"
];
public function __construct()
{
$fields = [
"user_pid",
"user_name",
"board_pid",
"board_name",
"table_name",
"file_name",
"file_path",
"file_type",
"file_caption",
"file_alt",
"file_description",
"file_size",
"file_sequence",
"reg_date"
];
parent::__construct($fields);
parent::__construct();
}
public function getTitleField(): string
{

View File

@ -99,11 +99,19 @@ class UserModel extends CommonModel
protected $table = 'mb_users';
protected $primaryKey = 'pid';
protected $returnType = UserEntity::class;
protected $allowedFields = [
"user_id",
"passwd",
"user_name",
"user_email",
"user_state",
"user_level",
"user_point"
];
public function __construct()
{
$fields = ["user_id", "passwd", "user_name", "user_email", "user_state", "user_level", "user_point"];
parent::__construct($fields);
parent::__construct();
}
public function getTitleField(): string
{
@ -221,11 +229,7 @@ class UserModel extends CommonModel
//create용
public function create(UserEntity $entity): UserEntity
{
$entity = $this->create_process($entity);
//GID값이 PK랑 같은 값 전달 후 Entity 수정
$entity->gid = $entity->getPK();
$this->setFields(["gid"]);
return $this->modify($entity);
return $this->create_process($entity);
}
//modify용

View File

@ -10,11 +10,18 @@ class SNSUserModel extends CommonModel
protected $table = 'sns_users';
protected $primaryKey = 'uid';
protected $returnType = SNSUSerEntity::class;
protected $allowedFields = [
"id",
"passwd",
"name",
"email",
"detail",
"status"
];
public function __construct()
{
$fields = ["id", "passwd", "name", "email", "detail", "status"];
parent::__construct($fields);
parent::__construct();
}
public function getTitleField(): string
{

View File

@ -10,11 +10,20 @@ class UserModel extends CommonModel
protected $table = 'users';
protected $primaryKey = 'uid';
protected $returnType = UserEntity::class;
protected $allowedFields = [
"id",
"passwd",
"name",
"email",
"pohne",
"mobild",
"role",
"status"
];
public function __construct()
{
$fields = ["id", "passwd", "name", "email", "pohne", "mobild", "role", "status"];
parent::__construct($fields);
parent::__construct();
}
public function getTitleField(): string
{