Merge pull request #3064 from Icinga/feature/var-lib-icingaweb2-2582

Implement ApplicationBootstrap::getStorageDir()
This commit is contained in:
lippserd 2017-11-16 20:27:34 +01:00 committed by GitHub
commit b3c1006eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 3 deletions

View File

@ -77,6 +77,13 @@ abstract class ApplicationBootstrap
*/ */
protected $configDir; protected $configDir;
/**
* Common storage directory
*
* @var string
*/
protected $storageDir;
/** /**
* Icinga class loader * Icinga class loader
* *
@ -122,10 +129,11 @@ abstract class ApplicationBootstrap
/** /**
* Constructor * Constructor
* *
* @param string $baseDir Icinga Web 2 base directory * @param string $baseDir Icinga Web 2 base directory
* @param string $configDir Path to Icinga Web 2's configuration files * @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) { if ($baseDir === null) {
$baseDir = dirname($this->getBootstrapDirectory()); $baseDir = dirname($this->getBootstrapDirectory());
@ -148,6 +156,17 @@ abstract class ApplicationBootstrap
$canonical = realpath($configDir); $canonical = realpath($configDir);
$this->configDir = $canonical ? $canonical : $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( set_include_path(
implode( implode(
PATH_SEPARATOR, PATH_SEPARATOR,
@ -284,6 +303,18 @@ abstract class ApplicationBootstrap
return $this->getDirWithSubDir($this->configDir, $subDir); 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 * Get the Icinga library directory
* *