Skip to content

Commit

Permalink
Fixed yii\console\controllers\AssetController does not create missi…
Browse files Browse the repository at this point in the history
…ng folders for the target bundles
  • Loading branch information
klimov-paul committed Apr 3, 2015
1 parent 901d640 commit e9ecdf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ Yii Framework 2 Change Log

- Bug #6642: Fixed the bug that using confirmation dialog via `data-confirm` in an `ActiveForm` may cause the dialog to appear twice (pana1990, qiangxue)
- Bug #6871: Fixed the bug that using defaults and hostnames in URL rules may cause an out-of-range index issue (qiangxue)
- Bug #7473: Fixed `yii\console\controllers\AssetController` does not create missing folders for the target bundles (schmunk42, klimov-paul)
- Bug #7529: Fixed `yii\web\Response::sendContentAsFile()` that was broken in 2.0.3 (samdark)
- Bug #7603: Fixed escape characters in `FormatConverter` to work with unicode characters (maddoger, cebe)
- Bug #7757: Fix fetching tables schema for oci and mysql when PDO::ATTR_CASE is set (nineinchnick)
Expand Down
29 changes: 19 additions & 10 deletions framework/console/controllers/AssetController.php
Expand Up @@ -11,6 +11,7 @@
use yii\console\Exception;
use yii\console\Controller;
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\VarDumper;
use yii\web\AssetBundle;

Expand Down Expand Up @@ -325,9 +326,7 @@ protected function loadTargets($targets, $bundles)
*/
protected function buildTarget($target, $type, $bundles)
{
$tempFile = $target->basePath . '/' . strtr($target->$type, ['{hash}' => 'temp']);
$inputFiles = [];

foreach ($target->depends as $name) {
if (isset($bundles[$name])) {
if (!$this->isBundleExternal($bundles[$name])) {
Expand All @@ -339,16 +338,26 @@ protected function buildTarget($target, $type, $bundles)
throw new Exception("Unknown bundle: '{$name}'");
}
}
if ($type === 'js') {
$this->compressJsFiles($inputFiles, $tempFile);

if (empty($inputFiles)) {
$target->$type = [];
} else {
$this->compressCssFiles($inputFiles, $tempFile);
}
if (!file_exists($target->basePath)) {

This comment has been minimized.

Copy link
@SDKiller

SDKiller Apr 3, 2015

Contributor

\yii\helpers\BaseFileHelper::createDirectory already checks for directory existence:

        if (is_dir($path)) {
            return true;
        }

And BTW, would not be possible 'false-positive' results with file_exists check if occasionally there will be regular file with the same name as directory we intend to create?

This comment has been minimized.

Copy link
@klimov-paul

klimov-paul Apr 3, 2015

Author Member

Make sense, thank you.
97c0ffc

FileHelper::createDirectory($target->basePath, $this->getAssetManager()->dirMode);
}
$tempFile = $target->basePath . '/' . strtr($target->$type, ['{hash}' => 'temp']);

$targetFile = strtr($target->$type, ['{hash}' => md5_file($tempFile)]);
$outputFile = $target->basePath . '/' . $targetFile;
rename($tempFile, $outputFile);
$target->$type = [$targetFile];
if ($type === 'js') {
$this->compressJsFiles($inputFiles, $tempFile);
} else {
$this->compressCssFiles($inputFiles, $tempFile);
}

$targetFile = strtr($target->$type, ['{hash}' => md5_file($tempFile)]);
$outputFile = $target->basePath . '/' . $targetFile;
rename($tempFile, $outputFile);
$target->$type = [$targetFile];
}
}

/**
Expand Down

0 comments on commit e9ecdf8

Please sign in to comment.