Automation init...3

This commit is contained in:
최준흠 2024-09-10 20:12:25 +09:00
parent d442bf2765
commit 24bb1fca5d
10 changed files with 104 additions and 84 deletions

View File

@ -19,7 +19,7 @@ class FileLibrary extends MyStorageLibrary
{
return $this->_path;
}
public function getFileEntity(): FileEntity
public function createFileEntity(): FileEntity
{
return new FileEntity();
}
@ -65,7 +65,7 @@ class FileLibrary extends MyStorageLibrary
if (!file_put_contents($saveFilePath, $content)) {
throw new \Exception(__FUNCTION__ . "파일저장 실패:{$saveFilePath}");
}
$entity = $this->getFileEntity();
$entity = $this->createFileEntity();
$entity->setPath($this->getPath());
$entity->setTitle($fileName);
$entity->setMimeType(mime_content_type($saveFilePath));

View File

@ -27,10 +27,6 @@ class MangboardLibrary extends FileLibrary
}
return $this->_model;
}
public function getFileEntity(): FileEntity
{
return new FileEntity();
}
public function getUser(): UserEntity
{
if ($this->_user === null) {
@ -75,6 +71,12 @@ class MangboardLibrary extends FileLibrary
{
$this->_boardLevel = $boardLevel;
}
//주의:Override함
public function createFileEntity(): FileEntity
{
return new FileEntity();
}
private function create_small_image(FileEntity $entity, int $file_sequence): FileEntity
{
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
@ -85,8 +87,9 @@ class MangboardLibrary extends FileLibrary
$image->setDebug($this->getDebug());
//Small 디렉토리 생성
$image->makeDirectory($image->getDestinationPath());
$dstfile = $image->make_small_image($entity->getTitle());
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 {$dstfile} 작업 완료");
if (!$image->make_small_image($entity->getTitle())) {
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 " . $entity->getTitle() . " 작업 완료");
}
return $entity;
}
//망보드 파일관리 table에 등록
@ -100,6 +103,8 @@ class MangboardLibrary extends FileLibrary
$entity->reg_date = date("Y-m-d H:i:s");
$entity->file_caption = $entity->getTitle();
$entity->file_alt = $entity->getTitle();
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
$entity->file_path = $entity->getPath() . DIRECTORY_SEPARATOR . $entity->getTitle();
$entity->file_description = "Filedata";
$entity = $this->getModel()->create($entity);
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 작업 완료");
@ -108,8 +113,8 @@ class MangboardLibrary extends FileLibrary
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity
{
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
$entity = $this->create_db($$entity, $file_sequence);
$entity = $this->create_small_image($entity, $file_sequence);
$entity = $this->create_db($entity, $file_sequence);
return $entity;
}
public function setBoardPID(array $fileEntitys, int $board_pid)
@ -117,6 +122,8 @@ class MangboardLibrary extends FileLibrary
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
foreach ($fileEntitys as $fileEntity) {
$fileEntity->board_pid = $board_pid;
//수정시 mb_files에서 file_path가 변경하지 못하게 하기위함
$this->getModel()->setFields($this->getModel()->getFields(['file_path']));
$this->getModel()->modify($fileEntity);
}
log_message("notice", __FUNCTION__ . " 작업 완료");

View File

@ -107,10 +107,13 @@ class ImageLibrary extends MyUtilLibrary
imagedestroy($this->_image);
}
public function make_small_image(string $file, int $width = 480, int $height = 319): string
public function make_small_image(string $file, int $width = 480, int $height = 319): bool
{
if (!$this->isFileType($this->getSourcePath(), $file)) {
return false;
}
//소스파일
$srcfile = $this->getSourcePath() . DIRECTORY_SEPARATOR . $file;
$srcfile = $this->getSourcePath() . DIRECTORY_SEPARATOR . $file;
$fileInfos = pathinfo($srcfile, PATHINFO_ALL);
//저장파일
$dstfile = $this->getDestinationPath() . DIRECTORY_SEPARATOR . $fileInfos['filename'] . "_small." . $fileInfos['extension'];
@ -119,6 +122,6 @@ class ImageLibrary extends MyUtilLibrary
$this->save($dstfile); // 저장
$this->destroy(); // 메모리 해제
log_message("notice", __FUNCTION__ . " 작업 완료");
return $dstfile;
return true;
}
}

View File

@ -46,9 +46,10 @@ abstract class CommonModel extends Model
protected $afterDelete = [];
private $_action = DB_ACTION["CREATE"];
protected function __construct()
protected function __construct(array $fields)
{
parent::__construct();
$this->setFields($fields);
}
abstract public function getTitleField(): string;
@ -73,6 +74,14 @@ abstract class CommonModel extends Model
}
return $this->allowedFields;
}
final public function setFields(array $fields): void
{
$this->allowedFields = $fields;
//array_unshift는 array의 맨앞에 넣기위함
if (!$this->useAutoIncrement) {
array_unshift($this->allowedFields, $this->getPKField());
}
}
final public function getFieldRules(array $fields, array $rules = []): array
{
foreach ($fields as $field) {

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;
parent::__construct();
$fields = [
"gid",
"title",
"user_pid",
"user_id",
"user_name",
"level",
"data_type",
"editor_type",
"image_path",
"reg_date",
"hit",
"content"
];
parent::__construct($fields);
}
public function getTitleField(): string
{

View File

@ -35,26 +35,25 @@ 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()
{
parent::__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);
}
public function getTitleField(): string
{
@ -109,7 +108,7 @@ class FileModel extends CommonModel
}
switch ($field) {
case "file_path":
$entity->$field = $entity->$field . DIRECTORY_SEPARATOR . $entity->getTitle();
$entity->$field .= DIRECTORY_SEPARATOR . $entity->getTitle();
break;
default:
$entity = parent::convertEntityData($entity, $field);

View File

@ -99,19 +99,18 @@ 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()
{
parent::__construct();
$fields = [
"user_id",
"passwd",
"user_name",
"user_email",
"user_state",
"user_level",
"user_point"
];
parent::__construct($fields);
}
public function getTitleField(): string
{

View File

@ -10,18 +10,17 @@ 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()
{
parent::__construct();
$fields = [
"id",
"passwd",
"name",
"email",
"detail",
"status"
];
parent::__construct($fields);
}
public function getTitleField(): string
{

View File

@ -10,20 +10,19 @@ 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()
{
parent::__construct();
$fields = [
"id",
"passwd",
"name",
"email",
"pohne",
"mobild",
"role",
"status"
];
parent::__construct($fields);
}
public function getTitleField(): string
{

View File

@ -13,8 +13,7 @@ trait FileTrait
}
}
//디렉토리에 속한 파일 List
public function getFilesByExtentionType(string $path, string $type = "image"): array
public function isFileType(string $path, string $file, $type = "image"): bool
{
switch ($type) {
case "audio":
@ -28,12 +27,18 @@ trait FileTrait
$exts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
break;
}
$ext = pathinfo($path . DIRECTORY_SEPARATOR . $file, PATHINFO_EXTENSION);
return in_array($ext, $exts);
}
//디렉토리에 속한 파일 List
public function getFilesByExtentionType(string $path, string $type = "image"): array
{
// 디렉토리에서 파일 목록 가져오기
$files = [];
foreach (scandir($path) as $file) {
$ext = pathinfo($path . DIRECTORY_SEPARATOR . $file, PATHINFO_EXTENSION);
// 확장자가 이미지 형식인지 확인
if (in_array($ext, $exts)) {
if ($this->isFileType($path, $file, $type)) {
$files[] = $file;
}
}