mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-24 06:14:26 +02:00
IcingaConfig: work with new database fields
This basically helps to detect whether someone travelled back in time by manually reverting single checks. Hard to explain in a few lines
This commit is contained in:
parent
b20924bf59
commit
0a63c6bde8
@ -144,17 +144,35 @@ class IcingaConfig
|
|||||||
$this->generateFromDb();
|
$this->generateFromDb();
|
||||||
$this->collectExtraFiles();
|
$this->collectExtraFiles();
|
||||||
$checksum = $this->calculateChecksum();
|
$checksum = $this->calculateChecksum();
|
||||||
$exists = $this->db->fetchOne(
|
$activity = $this->getLastActivityChecksum();
|
||||||
$this->db->select()->from(
|
|
||||||
self::$table,
|
$lastActivity = $this->binFromDb(
|
||||||
'COUNT(*)'
|
$this->db->fetchOne(
|
||||||
)->where(
|
$this->db->select()->from(
|
||||||
'checksum = ?',
|
self::$table,
|
||||||
$this->dbBin($checksum)
|
'last_activity_checksum'
|
||||||
|
)->where(
|
||||||
|
'checksum = ?',
|
||||||
|
$this->dbBin($checksum)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (int) $exists === 0;
|
if ($lastActivity === false || $lastActivity === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($lastActivity !== $activity) {
|
||||||
|
$this->db->update(
|
||||||
|
self::$table,
|
||||||
|
array(
|
||||||
|
'last_activity_checksum' => $this->dbBin($activity)
|
||||||
|
),
|
||||||
|
$this->db->quoteInto('checksum = ?', $this->dbBin($checksum))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function storeIfModified()
|
protected function storeIfModified()
|
||||||
@ -262,12 +280,14 @@ class IcingaConfig
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$activity = $this->dbBin($this->getLastActivityChecksum());
|
||||||
$this->db->insert(
|
$this->db->insert(
|
||||||
self::$table,
|
self::$table,
|
||||||
array(
|
array(
|
||||||
'duration' => $this->generationTime,
|
'duration' => $this->generationTime,
|
||||||
'last_activity_checksum' => $this->dbBin($this->getLastActivityChecksum()),
|
'first_activity_checksum' => $activity,
|
||||||
'checksum' => $this->dbBin($this->getChecksum()),
|
'last_activity_checksum' => $activity,
|
||||||
|
'checksum' => $this->dbBin($this->getChecksum()),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
/** @var IcingaConfigFile $file */
|
/** @var IcingaConfigFile $file */
|
||||||
@ -338,17 +358,9 @@ class IcingaConfig
|
|||||||
throw new Exception(sprintf('Got no config for %s', Util::binary2hex($checksum)));
|
throw new Exception(sprintf('Got no config for %s', Util::binary2hex($checksum)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checksum = $result->checksum;
|
$this->checksum = $this->binFromDb($result->checksum);
|
||||||
$this->duration = $result->duration;
|
$this->duration = $result->duration;
|
||||||
$this->lastActivityChecksum = $result->last_activity_checksum;
|
$this->lastActivityChecksum = $this->binFromDb($result->last_activity_checksum);
|
||||||
|
|
||||||
if (is_resource($this->checksum)) {
|
|
||||||
$this->checksum = stream_get_contents($this->checksum);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_resource($this->lastActivityChecksum)) {
|
|
||||||
$this->lastActivityChecksum = stream_get_contents($this->lastActivityChecksum);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = $this->db->select()->from(
|
$query = $this->db->select()->from(
|
||||||
array('cf' => 'director_generated_config_file'),
|
array('cf' => 'director_generated_config_file'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user