Skip to content

Commit 892cfc0

Browse files
committed
Schedule: Include the report's configuration in checksums
fixes #267
1 parent e6d60b4 commit 892cfc0

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

library/Reporting/Report.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Icinga\Module\Icingadb\ProvidedHook\Reporting\ServiceSlaReport;
1010
use Icinga\Module\Icingadb\ProvidedHook\Reporting\SlaReport;
1111
use Icinga\Module\Pdfexport\PrintableHtmlDocument;
12-
use Icinga\Module\Reporting\Model;
1312
use Icinga\Module\Reporting\Web\Widget\Template;
13+
use Icinga\Util\Json;
1414
use ipl\Html\HtmlDocument;
1515

1616
use function ipl\I18n\t;
@@ -38,6 +38,9 @@ class Report
3838
/** @var Template */
3939
protected $template;
4040

41+
/** @var ?string */
42+
protected ?string $templateName = null;
43+
4144
/**
4245
* Create report from the given model
4346
*
@@ -57,6 +60,7 @@ public static function fromModel(Model\Report $reportModel): self
5760

5861
$template = $reportModel->template->first();
5962
if ($template !== null) {
63+
$report->templateName = $template->name;
6064
$report->template = Template::fromModel($template);
6165
}
6266

@@ -121,6 +125,27 @@ public function getReportlets()
121125
return $this->reportlets;
122126
}
123127

128+
/**
129+
* Get a checksum for this report
130+
*
131+
* @return string
132+
*/
133+
public function getChecksum(): string
134+
{
135+
return md5(
136+
$this->getName()
137+
. $this->getTimeframe()->getName()
138+
. $this->templateName
139+
. Json::encode(array_map(
140+
function (Reportlet $reportlet) {
141+
return $reportlet->getConfig();
142+
},
143+
$this->getReportlets()
144+
)),
145+
true
146+
);
147+
}
148+
124149
/**
125150
* @return Schedule
126151
*/

library/Reporting/Schedule.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ public function setReport(Report $report): self
123123
public function getChecksum(): string
124124
{
125125
return md5(
126-
$this->getName() . $this->getReport()->getName() . $this->getAction() . Json::encode($this->getConfig()),
126+
$this->getName()
127+
. $this->getAction()
128+
. Json::encode($this->getConfig())
129+
. $this->getReport()->getChecksum(),
127130
true
128131
);
129132
}

0 commit comments

Comments
 (0)