3131 * @author Elias Luhr <[email protected] > 3232 *
3333 * @property ActiveRecord modelClass
34- * @property string extention
34+ * @property string extension
3535 * @property PrototypeController controller
3636 */
3737class ExportAction extends Action
3838{
3939 public $ modelClass ;
40- public $ extention ;
40+ public $ extension ;
4141
4242 private static $ availableModelTypes = [
4343 Html::class,
@@ -53,7 +53,7 @@ class ExportAction extends Action
5353 protected function run ()
5454 {
5555
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 );
5757 if (!class_exists ($ this ->modelClass )) {
5858 $ this ->controller ->stderr ("Model class ' {$ this ->modelClass }' does not exist " , Console::FG_RED );
5959 return ExitCode::IOERR ;
@@ -83,7 +83,15 @@ protected function run()
8383 $ fileName = Inflector::slug (str_replace ('/ ' ,'- ' ,$ entry ->key ));
8484 }
8585 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 ) {
8795 throw new ErrorException ("Error while writing file for key ' {$ entry ->key }' " );
8896 }
8997 $ this ->controller ->stdout ('. ' );
0 commit comments