Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asset command does not create necessary folders #7473

Closed
schmunk42 opened this issue Feb 26, 2015 · 4 comments
Closed

asset command does not create necessary folders #7473

schmunk42 opened this issue Feb 26, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@schmunk42
Copy link
Contributor

Using Yii 2.0.2

I was playing around with the asset command, but had to create the output folders manually, along with touching the temporary files. Otherwise I got this error:

root@f6bc58f56730:/app# ./yii asset config/assets.php config/assets-prod.php
Loading configuration from 'config/assets.php'...
Collecting source bundles information...
Creating output bundle 'allBackEnd':
PHP Warning 'yii\base\ErrorException' with message 'md5_file(/app/web/assets/js/backend-temp.js): failed to open stream: No such file or directory'

in /app/vendor/yiisoft/yii2/console/controllers/AssetController.php:348

Stack trace:
#0 /app/vendor/yiisoft/yii2/console/controllers/AssetController.php(182): yii\console\controllers\AssetController->buildTarget()
#1 /app/vendor/yiisoft/yii2/base/InlineAction.php(55): yii\console\controllers\AssetController->actionCompress()
#2 /app/vendor/yiisoft/yii2/base/InlineAction.php(55): ::call_user_func_array:{/app/vendor/yiisoft/yii2/base/InlineAction.php:55}()
#3 /app/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams()
#4 /app/vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->runAction()
#5 /app/vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAction()
#6 /app/vendor/yiisoft/yii2/console/Application.php(161): yii\base\Module->runAction()
#7 /app/vendor/yiisoft/yii2/console/Application.php(137): yii\console\Application->runAction()
#8 /app/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest()
#9 /app/yii(26): yii\base\Application->run()
#10 {main}

Below is a patch which creates the needed directory and temp-file.

diff --git a/console/controllers/AssetController.php b/console/controllers/AssetController.php
index 00fc73b..63ba279 100644
--- a/console/controllers/AssetController.php
+++ b/console/controllers/AssetController.php
@@ -11,6 +11,7 @@ use Yii;
 use yii\console\Exception;
 use yii\console\Controller;
 use yii\helpers\Console;
+use yii\helpers\FileHelper;
 use yii\helpers\VarDumper;
 use yii\web\AssetBundle;

@@ -326,6 +327,11 @@ class AssetController extends Controller
     protected function buildTarget($target, $type, $bundles)
     {
         $tempFile = $target->basePath . '/' . strtr($target->$type, ['{hash}' => 'temp']);
+        if (!is_file($tempFile)) {
+            FileHelper::createDirectory(dirname($tempFile), 0755, true);
+            touch($tempFile);
+        }
+
         $inputFiles = [];

         foreach ($target->depends as $name) {

Should I create a PR for this?

@cebe
Copy link
Member

cebe commented Feb 26, 2015

There was a similar issue before but I could not find it right now. PR welcome :)

@cebe cebe added this to the 2.0.x milestone Feb 26, 2015
schmunk42 added a commit to schmunk42/yii2 that referenced this issue Feb 26, 2015
@klimov-paul
Copy link
Member

#7414

@klimov-paul
Copy link
Member

Issue resolved by commit e9ecdf8

@klimov-paul klimov-paul modified the milestones: 2.0.4, 2.0.x Apr 3, 2015
@SDKiller
Copy link
Contributor

SDKiller commented Apr 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants