From 3fa39c29842bbc5842e042e81e6e26fe6debc9e2 Mon Sep 17 00:00:00 2001 From: BafS Date: Mon, 11 Jul 2016 02:10:40 +0200 Subject: [PATCH] Create slug folder(s) if not existing Add makeDirectory in FilesSystem.php --- app/Parvula/FilesSystem.php | 13 ++++++++++++- app/Parvula/Models/Mappers/PagesFlatFiles.php | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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)) {