BasketUploadForm: allow uploading snapshots...
...for existing Baskets fixes #1952
This commit is contained in:
parent
749ab6a356
commit
62bff81fac
|
@ -125,6 +125,26 @@ class BasketController extends ActionController
|
||||||
$this->content()->add($form);
|
$this->content()->add($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function uploadSnapshotAction()
|
||||||
|
{
|
||||||
|
$basket = Basket::load($this->params->get('name'), $this->db());
|
||||||
|
$this->actions()->add(
|
||||||
|
Link::create(
|
||||||
|
$this->translate('back'),
|
||||||
|
'director/basket/snapshots',
|
||||||
|
['name' => $basket->get('basket_name')],
|
||||||
|
['class' => 'icon-left-big']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->basketTabs()->activate('snapshots');
|
||||||
|
$this->addTitle($this->translate('Upload a Configuration Basket Snapshot'));
|
||||||
|
$form = (new BasketUploadForm())
|
||||||
|
->setObject($basket)
|
||||||
|
->setDb($this->db())
|
||||||
|
->handleRequest();
|
||||||
|
$this->content()->add($form);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Icinga\Exception\NotFoundError
|
* @throws \Icinga\Exception\NotFoundError
|
||||||
*/
|
*/
|
||||||
|
@ -145,6 +165,12 @@ class BasketController extends ActionController
|
||||||
$basket->get('basket_name')
|
$basket->get('basket_name')
|
||||||
));
|
));
|
||||||
$this->basketTabs()->activate('snapshots');
|
$this->basketTabs()->activate('snapshots');
|
||||||
|
$this->actions()->add(Link::create(
|
||||||
|
$this->translate('Upload'),
|
||||||
|
'director/basket/upload-snapshot',
|
||||||
|
['name' => $basket->get('basket_name')],
|
||||||
|
['class' => 'icon-upload']
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if ($basket !== null) {
|
if ($basket !== null) {
|
||||||
$this->content()->add(
|
$this->content()->add(
|
||||||
|
|
|
@ -25,10 +25,12 @@ class BasketUploadForm extends DirectorObjectForm
|
||||||
*/
|
*/
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
|
if ($this->object === null) {
|
||||||
$this->addElement('text', 'basket_name', [
|
$this->addElement('text', 'basket_name', [
|
||||||
'label' => $this->translate('Basket Name'),
|
'label' => $this->translate('Basket Name'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
$this->setAttrib('enctype', 'multipart/form-data');
|
$this->setAttrib('enctype', 'multipart/form-data');
|
||||||
|
|
||||||
$this->addElement('file', 'uploaded_file', [
|
$this->addElement('file', 'uploaded_file', [
|
||||||
|
@ -53,16 +55,6 @@ class BasketUploadForm extends DirectorObjectForm
|
||||||
return '\\Icinga\\Module\\Director\\DirectorObject\\Automation\\Basket';
|
return '\\Icinga\\Module\\Director\\DirectorObject\\Automation\\Basket';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setObjectSuccessUrl()
|
|
||||||
{
|
|
||||||
/** @var Basket $basket */
|
|
||||||
$basket = $this->object();
|
|
||||||
$this->setSuccessUrl(
|
|
||||||
'director/basket',
|
|
||||||
['name' => $basket->get('basket_name')]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws IcingaException
|
* @throws IcingaException
|
||||||
|
@ -134,13 +126,17 @@ class BasketUploadForm extends DirectorObjectForm
|
||||||
|
|
||||||
$basket->set('owner_type', 'user');
|
$basket->set('owner_type', 'user');
|
||||||
$basket->set('owner_value', $this->getAuth()->getUser()->getUsername());
|
$basket->set('owner_value', $this->getAuth()->getUser()->getUsername());
|
||||||
|
if ($basket->hasBeenLoadedFromDb()) {
|
||||||
|
$this->setSuccessUrl('director/basket/snapshots', ['name' => $basket->get('basket_name')]);
|
||||||
|
} else {
|
||||||
|
$this->setSuccessUrl('director/basket', ['name' => $basket->get('basket_name')]);
|
||||||
$basket->store($this->db);
|
$basket->store($this->db);
|
||||||
|
}
|
||||||
|
|
||||||
BasketSnapshot::forBasketFromJson(
|
BasketSnapshot::forBasketFromJson(
|
||||||
$basket,
|
$basket,
|
||||||
$this->rawUpload
|
$this->rawUpload
|
||||||
)->store($this->db);
|
)->store($this->db);
|
||||||
$this->setObjectSuccessUrl();
|
|
||||||
$this->beforeSuccessfulRedirect();
|
$this->beforeSuccessfulRedirect();
|
||||||
$this->redirectOnSuccess($this->translate('Basket has been uploaded'));
|
$this->redirectOnSuccess($this->translate('Basket has been uploaded'));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue