diff --git a/app/Libraries/MyStorage/FileLibrary.php b/app/Libraries/MyStorage/FileLibrary.php index fd45fff..a31a870 100644 --- a/app/Libraries/MyStorage/FileLibrary.php +++ b/app/Libraries/MyStorage/FileLibrary.php @@ -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)); diff --git a/app/Libraries/MyStorage/MangboardLibrary.php b/app/Libraries/MyStorage/MangboardLibrary.php index 58af7e2..1022cd1 100644 --- a/app/Libraries/MyStorage/MangboardLibrary.php +++ b/app/Libraries/MyStorage/MangboardLibrary.php @@ -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__ . " 작업 완료"); diff --git a/app/Libraries/MyUtil/ImageLibrary.php b/app/Libraries/MyUtil/ImageLibrary.php index 3149ebb..0510f0d 100644 --- a/app/Libraries/MyUtil/ImageLibrary.php +++ b/app/Libraries/MyUtil/ImageLibrary.php @@ -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; } } diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 8ff37f8..b9d5b8c 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -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) { diff --git a/app/Models/Mangboard/BoardModel.php b/app/Models/Mangboard/BoardModel.php index 0b9a085..4ea7ce0 100644 --- a/app/Models/Mangboard/BoardModel.php +++ b/app/Models/Mangboard/BoardModel.php @@ -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 { diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php index 1dae5b7..97147de 100644 --- a/app/Models/Mangboard/FileModel.php +++ b/app/Models/Mangboard/FileModel.php @@ -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); diff --git a/app/Models/Mangboard/UserModel.php b/app/Models/Mangboard/UserModel.php index 5d5afc4..de1cc14 100644 --- a/app/Models/Mangboard/UserModel.php +++ b/app/Models/Mangboard/UserModel.php @@ -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 { diff --git a/app/Models/SNSUserModel.php b/app/Models/SNSUserModel.php index bec2be1..2f98303 100644 --- a/app/Models/SNSUserModel.php +++ b/app/Models/SNSUserModel.php @@ -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 { diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 3f19f41..a625dd2 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -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 { diff --git a/app/Traits/FileTrait.php b/app/Traits/FileTrait.php index 5bd407c..6ced9c0 100644 --- a/app/Traits/FileTrait.php +++ b/app/Traits/FileTrait.php @@ -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; } }