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->collectExtraFiles();
|
||||
$checksum = $this->calculateChecksum();
|
||||
$exists = $this->db->fetchOne(
|
||||
$activity = $this->getLastActivityChecksum();
|
||||
|
||||
$lastActivity = $this->binFromDb(
|
||||
$this->db->fetchOne(
|
||||
$this->db->select()->from(
|
||||
self::$table,
|
||||
'COUNT(*)'
|
||||
'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()
|
||||
|
@ -262,11 +280,13 @@ class IcingaConfig
|
|||
);
|
||||
}
|
||||
|
||||
$activity = $this->dbBin($this->getLastActivityChecksum());
|
||||
$this->db->insert(
|
||||
self::$table,
|
||||
array(
|
||||
'duration' => $this->generationTime,
|
||||
'last_activity_checksum' => $this->dbBin($this->getLastActivityChecksum()),
|
||||
'first_activity_checksum' => $activity,
|
||||
'last_activity_checksum' => $activity,
|
||||
'checksum' => $this->dbBin($this->getChecksum()),
|
||||
)
|
||||
);
|
||||
|
@ -338,17 +358,9 @@ class IcingaConfig
|
|||
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->lastActivityChecksum = $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);
|
||||
}
|
||||
$this->lastActivityChecksum = $this->binFromDb($result->last_activity_checksum);
|
||||
|
||||
$query = $this->db->select()->from(
|
||||
array('cf' => 'director_generated_config_file'),
|
||||
|
|
Loading…
Reference in New Issue