From 2f7991e47129ad587fc8d2a196e1c3426d8eff3e Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 1 Dec 2014 13:57:57 +0100 Subject: [PATCH] LegacyStorage: support new header properties --- .../Businessprocess/Storage/LegacyStorage.php | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/library/Businessprocess/Storage/LegacyStorage.php b/library/Businessprocess/Storage/LegacyStorage.php index c20f692..bc59519 100644 --- a/library/Businessprocess/Storage/LegacyStorage.php +++ b/library/Businessprocess/Storage/LegacyStorage.php @@ -57,12 +57,35 @@ class LegacyStorage extends Storage $filename = $file->getFilename(); if (substr($filename, -5) === '.conf') { $name = substr($filename, 0, -5); - $files[$name] = $name; + $header = $this->readHeader($file->getPathname(), $name); + $files[$name] = $header['Title']; } } return $files; } + protected function readHeader($file, $name) + { + $fh = fopen($file, 'r'); + $cnt = 0; + $header = array( + 'Title' => $name, + 'Owner' => null, + 'Backend' => null, + 'Statetype' => 'soft', + 'SLA Hosts' => null + ); + while ($cnt < 15 && false !== ($line = fgets($fh))) { + $cnt++; + if (preg_match('/^\s*#\s+(.+?)\s*:\s*(.+)$/', $line, $m)) { + if (array_key_exists($m[1], $header)) { + $header[$m[1]] = $m[2]; + } + } + } + return $header; + } + /** * @return BusinessProcess */ @@ -84,7 +107,7 @@ class LegacyStorage extends Storage $bp = new BusinessProcess(); $fh = @fopen($file, 'r'); if (! $fh) { - throw new \Exception('Could not open ' . $file); + throw new SystemPermissionException('Could not open ' . $file); } $this->parsing_line_number = 0;