Skip to content

Commit

Permalink
Fixes #395: Made yii\gii\CodeFile indepdendent of controller contex…
Browse files Browse the repository at this point in the history
…t, do not apply `$newDirMode` and `$newFileMode` if module is not available
  • Loading branch information
cebe authored and samdark committed Feb 2, 2019
1 parent b7becd5 commit bfe6044
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Yii Framework 2 gii extension Change Log
-----------------------

- Enh #390, Bug #260: Create (bootstrap)-independent version (simialbi)
- Enh #395: Made `yii\gii\CodeFile` indepdendent of controller context, do not apply `$newDirMode` and `$newFileMode` if module is not available (CeBe)


2.0.8 December 08, 2018
Expand Down
20 changes: 13 additions & 7 deletions src/CodeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ public function __construct($path, $content, $config = [])
*/
public function save()
{
$module = Yii::$app->controller->module;
$module = isset(Yii::$app->controller) ? Yii::$app->controller->module : null;
if ($this->operation === self::OP_CREATE) {
$dir = dirname($this->path);
if (!is_dir($dir)) {
$mask = @umask(0);
$result = @mkdir($dir, $module->newDirMode, true);
@umask($mask);
if ($module instanceof \yii\gii\Module) {
$mask = @umask(0);
$result = @mkdir($dir, $module->newDirMode, true);
@umask($mask);
} else {
$result = @mkdir($dir, 0777, true);
}
if (!$result) {
return "Unable to create the directory '$dir'.";
}
Expand All @@ -97,9 +101,11 @@ public function save()
return "Unable to write the file '{$this->path}'.";
}

$mask = @umask(0);
@chmod($this->path, $module->newFileMode);
@umask($mask);
if ($module instanceof \yii\gii\Module) {
$mask = @umask(0);
@chmod($this->path, $module->newFileMode);
@umask($mask);
}

return true;
}
Expand Down

0 comments on commit bfe6044

Please sign in to comment.