From cea52a1b4ba6f715afe98b7e00c984d551ca8597 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 8 Nov 2017 16:07:12 +0100 Subject: [PATCH] Implement ApplicationBootstrap::getStorageDir() refs #2582 --- .../Application/ApplicationBootstrap.php | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index d0330770e..4b9fe1b0c 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -77,6 +77,13 @@ abstract class ApplicationBootstrap */ protected $configDir; + /** + * Common storage directory + * + * @var string + */ + protected $storageDir; + /** * Icinga class loader * @@ -122,10 +129,11 @@ abstract class ApplicationBootstrap /** * Constructor * - * @param string $baseDir Icinga Web 2 base directory - * @param string $configDir Path to Icinga Web 2's configuration files + * @param string $baseDir Icinga Web 2 base directory + * @param string $configDir Path to Icinga Web 2's configuration files + * @param string $storageDir Path to Icinga Web 2's stored files */ - protected function __construct($baseDir = null, $configDir = null) + protected function __construct($baseDir = null, $configDir = null, $storageDir = null) { if ($baseDir === null) { $baseDir = dirname($this->getBootstrapDirectory()); @@ -148,6 +156,17 @@ abstract class ApplicationBootstrap $canonical = realpath($configDir); $this->configDir = $canonical ? $canonical : $configDir; + if ($storageDir === null) { + $storageDir = getenv('ICINGAWEB_STORAGEDIR'); + if ($storageDir === false) { + $storageDir = Platform::isWindows() + ? $baseDir . '/storage' + : '/var/lib/icingaweb2'; + } + } + $canonical = realpath($storageDir); + $this->storageDir = $canonical ? $canonical : $storageDir; + set_include_path( implode( PATH_SEPARATOR, @@ -284,6 +303,18 @@ abstract class ApplicationBootstrap return $this->getDirWithSubDir($this->configDir, $subDir); } + /** + * Get the common storage directory + * + * @param string $subDir Optional sub directory to get + * + * @return string + */ + public function getStorageDir($subDir = null) + { + return $this->getDirWithSubDir($this->storageDir, $subDir); + } + /** * Get the Icinga library directory *