From a2fd5879896a320154e3f95e699bd9cd3d0223f0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 23 Nov 2016 10:44:24 +0100 Subject: [PATCH] LegacyStorage: reorganize some methods --- .../Businessprocess/Storage/LegacyStorage.php | 71 +++++++++++-------- library/Businessprocess/Storage/Storage.php | 14 ++++ 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/library/Businessprocess/Storage/LegacyStorage.php b/library/Businessprocess/Storage/LegacyStorage.php index 8d9761b..5e1e533 100644 --- a/library/Businessprocess/Storage/LegacyStorage.php +++ b/library/Businessprocess/Storage/LegacyStorage.php @@ -2,55 +2,63 @@ namespace Icinga\Module\Businessprocess\Storage; +use DirectoryIterator; +use Icinga\Application\Benchmark; use Icinga\Application\Icinga; use Icinga\Authentication\Auth; -use Icinga\Data\ConfigObject; use Icinga\Exception\ConfigurationError; -use Icinga\Module\Businessprocess\BusinessProcess; use Icinga\Module\Businessprocess\BpNode; -use Icinga\Module\Businessprocess\Storage\Storage; -use DirectoryIterator; +use Icinga\Module\Businessprocess\BusinessProcess; use Icinga\Exception\SystemPermissionException; -use Icinga\Application\Benchmark; class LegacyStorage extends Storage { + /** @var string */ protected $configDir; + /** @var int */ protected $parsing_line_number; + /** @var string */ protected $currentFilename; public function getConfigDir() { if ($this->configDir === null) { - $dir = Icinga::app() - ->getModuleManager() - ->getModule('businessprocess') - ->getConfigDir(); - - // TODO: This is silly. We need Config::requireDirectory(). - if (! is_dir($dir)) { - if (! is_dir(dirname($dir))) { - if (! @mkdir(dirname($dir))) { - throw new SystemPermissionException('Could not create config directory "%s"', dirname($dir)); - } - } - if (! mkdir($dir)) { - throw new SystemPermissionException('Could not create config directory "%s"', $dir); - } - } - $dir = $dir . '/processes'; - if (! is_dir($dir)) { - if (! mkdir($dir)) { - throw new SystemPermissionException('Could not create config directory "%s"', $dir); - } - } - $this->configDir = $dir; + $this->prepareDefaultConfigDir(); } + return $this->configDir; } + protected function prepareDefaultConfigDir() + { + $dir = Icinga::app() + ->getModuleManager() + ->getModule('businessprocess') + ->getConfigDir(); + + // TODO: This is silly. We need Config::requireDirectory(). + if (! is_dir($dir)) { + if (! is_dir(dirname($dir))) { + if (! @mkdir(dirname($dir))) { + throw new SystemPermissionException('Could not create config directory "%s"', dirname($dir)); + } + } + if (! mkdir($dir)) { + throw new SystemPermissionException('Could not create config directory "%s"', $dir); + } + } + $dir = $dir . '/processes'; + if (! is_dir($dir)) { + if (! mkdir($dir)) { + throw new SystemPermissionException('Could not create config directory "%s"', $dir); + } + } + + $this->configDir = $dir; + } + /** * @return array */ @@ -191,13 +199,16 @@ class LegacyStorage extends Storage $bp = new BusinessProcess(); $bp->setName($name); $this->parseString($string, $bp); - $this->loadHeader($name, $bp); + // $this->loadHeader($name, $bp); return $bp; } + /** + * @inheritdoc + */ public function deleteProcess($name) { - unlink($this->getFilename($name)); + return @unlink($this->getFilename($name)); } /** diff --git a/library/Businessprocess/Storage/Storage.php b/library/Businessprocess/Storage/Storage.php index 21d130f..89e1a7f 100644 --- a/library/Businessprocess/Storage/Storage.php +++ b/library/Businessprocess/Storage/Storage.php @@ -7,8 +7,15 @@ use Icinga\Module\Businessprocess\BusinessProcess; abstract class Storage { + /** + * @var ConfigObject + */ protected $config; + /** + * Storage constructor. + * @param ConfigObject $config + */ public function __construct(ConfigObject $config) { $this->config = $config; @@ -25,13 +32,20 @@ abstract class Storage abstract public function listProcesses(); /** + * @param $name * @return BusinessProcess */ abstract public function loadProcess($name); /** + * @param BusinessProcess $name + * @return mixed */ abstract public function storeProcess(BusinessProcess $name); + /** + * @param $name + * @return bool Whether the process has been deleted + */ abstract public function deleteProcess($name); }