Skip to content

Commit 3fa39c2

Browse files
committed
Create slug folder(s) if not existing
Add makeDirectory in FilesSystem.php
1 parent c1cd0fc commit 3fa39c2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/Parvula/FilesSystem.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function __construct($workingDirectory = '.') {
3030
}
3131

3232
/**
33-
* Check if file exists
33+
* Check if a file or directory exists
3434
*
3535
* @param string $filename File name
3636
* @return boolean If file exists
@@ -145,6 +145,17 @@ public function rename($oldName, $newName) {
145145
return rename($this->workingDirectory . $oldName, $this->workingDirectory . $newName);
146146
}
147147

148+
/**
149+
* Makes directory (including sub directories)
150+
*
151+
* @param string $path Directory to create
152+
* @param integer $mode Optional
153+
* @return bool
154+
*/
155+
public function makeDirectory($path, $mode = 0777) {
156+
return mkdir($this->workingDirectory . $path, $mode, true);
157+
}
158+
148159
/**
149160
* Try to change the mode of the specified file to that given in mode
150161
*

app/Parvula/Models/Mappers/PagesFlatFiles.php

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ public function create($page) {
133133
return false;
134134
}
135135

136+
// If parent folder does not exists
137+
if (!$fs->exists(dirname($pagePath))) {
138+
$fs->makeDirectory(dirname($pagePath));
139+
}
140+
136141
$data = $this->renderer->render($page);
137142

138143
if (!$fs->write($pagePath, $data)) {

0 commit comments

Comments
 (0)