2017-08-16 12:01:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Widget;
|
|
|
|
|
2019-09-06 09:54:03 +02:00
|
|
|
use dipl\Html\HtmlDocument;
|
2017-08-16 12:01:25 +02:00
|
|
|
use Icinga\Module\Director\Forms\ImportCheckForm;
|
|
|
|
use Icinga\Module\Director\Forms\ImportRunForm;
|
|
|
|
use Icinga\Module\Director\Objects\ImportSource;
|
2019-09-06 09:54:03 +02:00
|
|
|
use dipl\Html\Html;
|
|
|
|
use dipl\Translation\TranslationHelper;
|
2017-08-16 12:01:25 +02:00
|
|
|
|
2018-05-08 19:54:00 +02:00
|
|
|
class ImportSourceDetails extends HtmlDocument
|
2017-08-16 12:01:25 +02:00
|
|
|
{
|
|
|
|
use TranslationHelper;
|
|
|
|
|
|
|
|
protected $source;
|
|
|
|
|
|
|
|
public function __construct(ImportSource $source)
|
|
|
|
{
|
|
|
|
$this->source = $source;
|
|
|
|
}
|
|
|
|
|
2018-05-08 19:54:00 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\IcingaException
|
|
|
|
*/
|
|
|
|
protected function assemble()
|
2017-08-16 12:01:25 +02:00
|
|
|
{
|
|
|
|
$source = $this->source;
|
|
|
|
$description = $source->get('description');
|
|
|
|
if (strlen($description)) {
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag('p', null, $description));
|
2017-08-16 12:01:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ($source->get('import_state')) {
|
|
|
|
case 'unknown':
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag(
|
|
|
|
'p',
|
|
|
|
null,
|
2017-08-16 12:01:25 +02:00
|
|
|
$this->translate(
|
|
|
|
"It's currently unknown whether we are in sync with this Import Source."
|
|
|
|
. ' You should either check for changes or trigger a new Import Run.'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case 'in-sync':
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag('p', null, sprintf(
|
2017-08-16 12:01:25 +02:00
|
|
|
$this->translate(
|
|
|
|
'This Import Source was last found to be in sync at %s.'
|
|
|
|
),
|
|
|
|
$source->last_attempt
|
|
|
|
)));
|
|
|
|
// TODO: check whether...
|
|
|
|
// - there have been imports since then, differing from former ones
|
|
|
|
// - there have been activities since then
|
|
|
|
break;
|
|
|
|
case 'pending-changes':
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag('p', ['class' => 'warning'], $this->translate(
|
2017-08-16 12:01:25 +02:00
|
|
|
'There are pending changes for this Import Source. You should trigger a new'
|
|
|
|
. ' Import Run.'
|
|
|
|
)));
|
|
|
|
break;
|
|
|
|
case 'failing':
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag('p', ['class' => 'error'], sprintf(
|
2017-08-16 12:01:25 +02:00
|
|
|
$this->translate(
|
|
|
|
'This Import Source failed when last checked at %s: %s'
|
|
|
|
),
|
|
|
|
$source->last_attempt,
|
|
|
|
$source->last_error_message
|
|
|
|
)));
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-08 19:54:00 +02:00
|
|
|
$this->add(Html::tag('p', ['class' => 'error'], sprintf(
|
2017-08-16 12:01:25 +02:00
|
|
|
$this->translate('This Import Source has an invalid state: %s'),
|
|
|
|
$source->get('import_state')
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->add(
|
|
|
|
ImportCheckForm::load()
|
|
|
|
->setImportSource($source)
|
|
|
|
->handleRequest()
|
|
|
|
);
|
|
|
|
$this->add(
|
|
|
|
ImportRunForm::load()
|
|
|
|
->setImportSource($source)
|
|
|
|
->handleRequest()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|