Skip to content

Commit

Permalink
Create slug folder(s) if not existing
Browse files Browse the repository at this point in the history
Add makeDirectory in FilesSystem.php
  • Loading branch information
BafS committed Jul 11, 2016
1 parent c1cd0fc commit 3fa39c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/Parvula/FilesSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions app/Parvula/Models/Mappers/PagesFlatFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 3fa39c2

Please sign in to comment.