31
31
* @author Elias Luhr <[email protected] >
32
32
*
33
33
* @property ActiveRecord modelClass
34
- * @property string extention
34
+ * @property string extension
35
35
* @property PrototypeController controller
36
36
*/
37
37
class ExportAction extends Action
38
38
{
39
39
public $ modelClass ;
40
- public $ extention ;
40
+ public $ extension ;
41
41
42
42
private static $ availableModelTypes = [
43
43
Html::class,
@@ -53,7 +53,7 @@ class ExportAction extends Action
53
53
protected function run ()
54
54
{
55
55
56
- $ this ->controller ->stdout ("Exporting {$ this ->extention } files " . PHP_EOL , Console::FG_BLUE );
56
+ $ this ->controller ->stdout ("Exporting {$ this ->extension } files " . PHP_EOL , Console::FG_BLUE );
57
57
if (!class_exists ($ this ->modelClass )) {
58
58
$ this ->controller ->stderr ("Model class ' {$ this ->modelClass }' does not exist " , Console::FG_RED );
59
59
return ExitCode::IOERR ;
@@ -83,7 +83,15 @@ protected function run()
83
83
$ fileName = Inflector::slug (str_replace ('/ ' ,'- ' ,$ entry ->key ));
84
84
}
85
85
try {
86
- if (file_put_contents ($ exportPath . DIRECTORY_SEPARATOR . $ fileName . '. ' . $ this ->extention , $ entry ->value ) === false ) {
86
+ // check if filename "looks" like a path, if yes, we must create subdirs
87
+ if ($ fileName !== basename ($ fileName )) {
88
+ $ subDir = $ exportPath . DIRECTORY_SEPARATOR . trim (dirname ($ fileName ), DIRECTORY_SEPARATOR );
89
+ if (!FileHelper::createDirectory ($ subDir )) {
90
+ throw new ErrorException ("Error while creating sub directory ' {$ subDir }' for file ' {$ fileName }' " );
91
+ }
92
+ }
93
+
94
+ if (file_put_contents ($ exportPath . DIRECTORY_SEPARATOR . $ fileName . '. ' . $ this ->extension , $ entry ->value ) === false ) {
87
95
throw new ErrorException ("Error while writing file for key ' {$ entry ->key }' " );
88
96
}
89
97
$ this ->controller ->stdout ('. ' );
0 commit comments