diff --git a/app/Parvula/FilesSystem.php b/app/Parvula/FilesSystem.php index 9c526a8..9ed87f8 100644 --- a/app/Parvula/FilesSystem.php +++ b/app/Parvula/FilesSystem.php @@ -30,7 +30,7 @@ function __construct($workingDirectory = '.') { } /** - * Check if file exists + * Check if a file or directory exists * * @param string $filename File name * @return boolean If file exists @@ -145,6 +145,17 @@ public function rename($oldName, $newName) { return rename($this->workingDirectory . $oldName, $this->workingDirectory . $newName); } + /** + * Makes directory (including sub directories) + * + * @param string $path Directory to create + * @param integer $mode Optional + * @return bool + */ + public function makeDirectory($path, $mode = 0777) { + return mkdir($this->workingDirectory . $path, $mode, true); + } + /** * Try to change the mode of the specified file to that given in mode * diff --git a/app/Parvula/Models/Mappers/PagesFlatFiles.php b/app/Parvula/Models/Mappers/PagesFlatFiles.php index 3956958..5e1d86f 100644 --- a/app/Parvula/Models/Mappers/PagesFlatFiles.php +++ b/app/Parvula/Models/Mappers/PagesFlatFiles.php @@ -133,6 +133,11 @@ public function create($page) { return false; } + // If parent folder does not exists + if (!$fs->exists(dirname($pagePath))) { + $fs->makeDirectory(dirname($pagePath)); + } + $data = $this->renderer->render($page); if (!$fs->write($pagePath, $data)) {