From be472e347361060e59239b2deb19c9b46b1828e5 Mon Sep 17 00:00:00 2001 From: bscheshirwork Date: Fri, 16 Nov 2018 19:13:40 +0300 Subject: [PATCH] Refactor createFolder and removeFile operations --- GalleryBehavior.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/GalleryBehavior.php b/GalleryBehavior.php index 3f59507..b25a8ba 100644 --- a/GalleryBehavior.php +++ b/GalleryBehavior.php @@ -8,6 +8,7 @@ use yii\base\Exception; use yii\db\ActiveRecord; use yii\db\Query; +use yii\helpers\FileHelper; use yii\imagine\Image; /** @@ -253,9 +254,7 @@ public function replaceImage($imageId, $path) private function removeFile($fileName) { - if (file_exists($fileName)) { - @unlink($fileName); - } + return FileHelper::unlink($fileName); } /** @@ -277,14 +276,7 @@ public function getGalleryId() private function createFolders($filePath) { - $parts = explode('/', $filePath); - // skip file name - $parts = array_slice($parts, 0, count($parts) - 1); - $targetPath = implode('/', $parts); - $path = realpath($targetPath); - if (!$path) { - mkdir($targetPath, 0777, true); - } + return FileHelper::createDirectory(FileHelper::normalizePath($filePath), 0777); } /////////////////////////////// ========== Public Actions ============ ///////////////////////////