From 80a2e974b4153686c3f9a1965c7b88dd8e640477 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 14 Sep 2012 07:00:49 -0400 Subject: [PATCH] Create directory structure for config files automatically when saving. --- module/VuFind/src/VuFind/Config/Writer.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/module/VuFind/src/VuFind/Config/Writer.php b/module/VuFind/src/VuFind/Config/Writer.php index 365ad328c22..bb5da67b58f 100644 --- a/module/VuFind/src/VuFind/Config/Writer.php +++ b/module/VuFind/src/VuFind/Config/Writer.php @@ -146,6 +146,20 @@ class Writer */ public function save() { + // Create parent directory structure if necessary: + $stack = array(); + $dirname = dirname($this->filename); + while (!empty($dirname) && !is_dir($dirname)) { + $stack[] = $dirname; + $dirname = dirname($dirname); + } + foreach (array_reverse($stack) as $dir) { + if (!mkdir($dir)) { + return false; + } + } + + // Write the file: return file_put_contents($this->filename, $this->getContent()); } -- GitLab