mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-06 05:29:35 -05:00
LegacyStorage: reorganize some methods
This commit is contained in:
parent
9087c2614c
commit
a2fd587989
2 changed files with 55 additions and 30 deletions
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue