Skip to content

Commit

Permalink
Merge pull request #62 from bscheshirwork/disk-operations-use-helper
Browse files Browse the repository at this point in the history
[WIP] Refactor createFolder and removeFile operations
  • Loading branch information
zxbodya authored Nov 16, 2018
2 parents db899b2 + be472e3 commit 4164f01
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions GalleryBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use yii\base\Exception;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\helpers\FileHelper;
use yii\imagine\Image;

/**
Expand Down Expand Up @@ -253,9 +254,7 @@ public function replaceImage($imageId, $path)

private function removeFile($fileName)
{
if (file_exists($fileName)) {
@unlink($fileName);
}
return FileHelper::unlink($fileName);

This comment has been minimized.

Copy link
@bscheshirwork

bscheshirwork Nov 16, 2018

Contributor

Look like.
Needed preserve errors too.

}

/**
Expand All @@ -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 ============ ///////////////////////////
Expand Down

0 comments on commit 4164f01

Please sign in to comment.