AnnouncementIniRepository: Don't transform retrieved timestamps to DateTime

refs #3414
This commit is contained in:
Johannes Meyer 2019-04-16 13:03:16 +02:00
parent 032ca7ae50
commit 37df008d7f
3 changed files with 18 additions and 22 deletions

View File

@ -13,6 +13,21 @@ use Icinga\Forms\RepositoryForm;
*/ */
class AnnouncementForm extends RepositoryForm class AnnouncementForm extends RepositoryForm
{ {
protected function fetchEntry()
{
$entry = parent::fetchEntry();
if ($entry !== false) {
if ($entry->start !== null) {
$entry->start = (new DateTime())->setTimestamp($entry->start);
}
if ($entry->end !== null) {
$entry->end = (new DateTime())->setTimestamp($entry->end);
}
}
return $entry;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -40,8 +40,8 @@
<?php endif ?> <?php endif ?>
<td><?= $this->escape($announcement->author) ?></td> <td><?= $this->escape($announcement->author) ?></td>
<td><?= $this->ellipsis($this->escape($announcement->message), 100) ?></td> <td><?= $this->ellipsis($this->escape($announcement->message), 100) ?></td>
<td><?= $this->formatDateTime($announcement->start->getTimestamp()) ?></td> <td><?= $this->formatDateTime($announcement->start) ?></td>
<td><?= $this->formatDateTime($announcement->end->getTimestamp()) ?></td> <td><?= $this->formatDateTime($announcement->end) ?></td>
<?php if ($this->hasPermission('admin')): ?> <?php if ($this->hasPermission('admin')): ?>
<td class="icon-col"><?= $this->qlink( <td class="icon-col"><?= $this->qlink(
null, null,

View File

@ -30,25 +30,6 @@ class AnnouncementIniRepository extends IniRepository
'end' => 'timestamp' 'end' => 'timestamp'
)); ));
/**
* Create a DateTime from a timestamp
*
* @param string $timestamp
*
* @return DateTime|null
*/
protected function retrieveTimestamp($timestamp)
{
if ($timestamp !== null) {
$dateTime = new DateTime();
$dateTime->setTimestamp($timestamp);
return $dateTime;
}
return null;
}
/** /**
* Get a DateTime's timestamp * Get a DateTime's timestamp
* *
@ -157,7 +138,7 @@ class AnnouncementIniRepository extends IniRepository
$refresh = null; $refresh = null;
foreach ($query as $row) { foreach ($query as $row) {
$min = min($row->start->getTimestamp(), $row->end->getTimestamp()); $min = min($row->start, $row->end);
if ($refresh === null) { if ($refresh === null) {
$refresh = $min; $refresh = $min;