diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index fdad736f833..0bea5c0a23a 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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) diff --git a/framework/console/controllers/AssetController.php b/framework/console/controllers/AssetController.php index 591f6287734..dcd336fcf1d 100644 --- a/framework/console/controllers/AssetController.php +++ b/framework/console/controllers/AssetController.php @@ -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; @@ -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])) { @@ -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)) { + 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]; + } } /**