mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 00:34:03 +02:00
Use Icinga\Util\File instead of fopen
This commit is contained in:
parent
9066a0c2fa
commit
c563479888
@ -17,6 +17,7 @@ use Icinga\Application\Icinga;
|
|||||||
use Icinga\Logger\Logger;
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Util\Translator;
|
use Icinga\Util\Translator;
|
||||||
use Icinga\Web\Hook;
|
use Icinga\Web\Hook;
|
||||||
|
use Icinga\Util\File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module handling
|
* Module handling
|
||||||
@ -319,10 +320,12 @@ class Module
|
|||||||
|
|
||||||
if (file_exists($this->metadataFile)) {
|
if (file_exists($this->metadataFile)) {
|
||||||
|
|
||||||
$fh = fopen($this->metadataFile, 'r');
|
$file = File::open($this->metadataFile, 'r');
|
||||||
|
$lines = $file->readlines();
|
||||||
|
$file->close();
|
||||||
$key = null;
|
$key = null;
|
||||||
|
|
||||||
while (false !== ($line = fgets($fh))) {
|
foreach ($lines as $line) {
|
||||||
$line = rtrim($line);
|
$line = rtrim($line);
|
||||||
|
|
||||||
if ($key === 'description') {
|
if ($key === 'description') {
|
||||||
|
@ -6,9 +6,9 @@ namespace Icinga\Logger\Writer;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
|
use Icinga\Util\File;
|
||||||
use Icinga\Logger\Logger;
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Logger\LogWriter;
|
use Icinga\Logger\LogWriter;
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,12 +93,6 @@ class FileWriter extends LogWriter
|
|||||||
*/
|
*/
|
||||||
protected function write($text)
|
protected function write($text)
|
||||||
{
|
{
|
||||||
$fd = fopen($this->path, 'a');
|
File::open($this->path, 'a')->write($text . PHP_EOL)->close();
|
||||||
|
|
||||||
if ($fd === false || fwrite($fd, $text . PHP_EOL) === false) {
|
|
||||||
throw new Exception('Failed to write to log file "' . $this->path . '"');
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($fd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ class IniStore extends PreferencesStore
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
File::create($this->preferencesFile);
|
File::open($this->preferencesFile, 'a')->chmod(0664)->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_writable($this->preferencesFile)) {
|
if (!is_writable($this->preferencesFile)) {
|
||||||
|
@ -78,6 +78,21 @@ class File
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read file line by line
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function readlines()
|
||||||
|
{
|
||||||
|
$lines = array();
|
||||||
|
while (($line = fgets($this->handle)) !== false) {
|
||||||
|
$lines[] = $line;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write contents to file
|
* Write contents to file
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user