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

Made yii\gii\CodeFile indepdendent of controller context #395

Merged
merged 2 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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