mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2026-06-05 06:43:11 -04:00
Add SPDX license headers and mark source files as GPL-3.0-or-later to preserve the option to relicense under later GPL versions.
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
use Icinga\Module\Director\Objects\ImportSource;
|
|
use Icinga\Module\Director\Web\Form\DirectorForm;
|
|
|
|
class ImportRunForm extends DirectorForm
|
|
{
|
|
/** @var ImportSource */
|
|
protected $source;
|
|
|
|
public function setImportSource(ImportSource $source)
|
|
{
|
|
$this->source = $source;
|
|
return $this;
|
|
}
|
|
|
|
public function setup()
|
|
{
|
|
$this->submitLabel = false;
|
|
$this->addElement('submit', 'submit', [
|
|
'label' => $this->translate('Trigger Import Run'),
|
|
'decorators' => ['ViewHelper']
|
|
]);
|
|
}
|
|
|
|
public function onSuccess()
|
|
{
|
|
$source = $this->source;
|
|
if ($source->runImport()) {
|
|
$this->setSuccessMessage(
|
|
$this->translate('Imported new data from this Import Source')
|
|
);
|
|
} else {
|
|
$this->setSuccessMessage(
|
|
$this->translate(
|
|
'Nothing to do, data provided by this Import Source'
|
|
. " didn't change since the last import run"
|
|
)
|
|
);
|
|
}
|
|
|
|
if ($source->get('import_state') === 'failing') {
|
|
$this->addError($this->translate('Triggering this Import Source failed'));
|
|
} else {
|
|
parent::onSuccess();
|
|
}
|
|
}
|
|
}
|