Commit 821f5331 authored by Ad Schellevis's avatar Ad Schellevis

add revision information on config save

parent 5114af53
...@@ -260,11 +260,37 @@ class Config extends Singleton ...@@ -260,11 +260,37 @@ class Config extends Singleton
} }
/**
* update config revision information (ROOT.revision tag)
* @param array|null $revision revision tag (associative array)
* @param \SimpleXMLElement|null pass trough xml node
*/
private function updateRevision($revision, $node = null)
{
// input must be an array
if (is_array($revision)) {
if ($node == null) {
if (isset($this->simplexml->revision)) {
$node = $this->simplexml->revision;
} else {
$node = $this->simplexml->addChild("revision");
}
}
foreach ($revision as $revKey => $revItem) {
$childNode = $node->addChild($revKey);
if (is_array($revItem)) {
$this->updateRevision($revItem, $childNode);
} else {
$childNode[0] = $revItem;
}
}
}
}
/** /**
* backup current (running) config * backup current (running) config
* @param string|null $message log message
*/ */
private function backup($message) private function backup()
{ {
$target_dir = dirname($this->config_file)."/backup/"; $target_dir = dirname($this->config_file)."/backup/";
$target_filename = "config-".time().".xml"; $target_filename = "config-".time().".xml";
...@@ -330,17 +356,24 @@ class Config extends Singleton ...@@ -330,17 +356,24 @@ class Config extends Singleton
/** /**
* save config to filesystem * save config to filesystem
* @param string|null $message log message * @param array|null $revision revision tag (associative array)
* @param bool $nobackup do not backup current config * @param bool $nobackup do not backup current config
* @throws ConfigException * @throws ConfigException
*/ */
public function save($message = null, $nobackup = false) public function save($revision = null, $nobackup = false)
{ {
$xml_text = $this->__toString(); $this->checkvalid();
if ($nobackup == false) { if ($nobackup == false) {
$this->backup($message); $this->backup();
} }
// update revision information ROOT.revision tag
$this->updateRevision($revision);
// serialize to text
$xml_text = $this->__toString();
// save configuration, try to obtain a lock before doing so. // save configuration, try to obtain a lock before doing so.
$target_filename = $this->config_file; $target_filename = $this->config_file;
if (file_exists($target_filename)) { if (file_exists($target_filename)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment