2018-12-17 08:49:26 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Forms;
|
|
|
|
|
|
|
|
|
|
use Icinga\Application\Icinga;
|
2023-08-14 03:50:53 -04:00
|
|
|
use Icinga\Application\Web;
|
2018-12-17 08:49:26 -05:00
|
|
|
use Icinga\Exception\Http\HttpException;
|
|
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
|
|
|
|
use Icinga\Module\Businessprocess\BpNode;
|
2019-01-14 08:59:56 -05:00
|
|
|
use Icinga\Module\Businessprocess\Exception\ModificationError;
|
2018-12-17 08:49:26 -05:00
|
|
|
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
|
|
|
|
|
use Icinga\Module\Businessprocess\Node;
|
2023-08-09 04:13:36 -04:00
|
|
|
use Icinga\Module\Businessprocess\Web\Form\BpConfigBaseForm;
|
2018-12-17 08:49:26 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Form\CsrfToken;
|
2019-02-22 03:12:07 -05:00
|
|
|
use Icinga\Web\Session;
|
2018-12-17 08:49:26 -05:00
|
|
|
use Icinga\Web\Session\SessionNamespace;
|
|
|
|
|
|
2023-08-09 04:13:36 -04:00
|
|
|
class MoveNodeForm extends BpConfigBaseForm
|
2018-12-17 08:49:26 -05:00
|
|
|
{
|
|
|
|
|
/** @var BpConfig */
|
|
|
|
|
protected $bp;
|
|
|
|
|
|
|
|
|
|
/** @var Node */
|
|
|
|
|
protected $node;
|
|
|
|
|
|
|
|
|
|
/** @var BpNode */
|
|
|
|
|
protected $parentNode;
|
|
|
|
|
|
|
|
|
|
/** @var SessionNamespace */
|
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
|
|
public function __construct($options = null)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($options);
|
|
|
|
|
|
|
|
|
|
// Zend's plugin loader reverses the order of added prefix paths thus trying our paths first before trying
|
|
|
|
|
// Zend paths
|
|
|
|
|
$this->addPrefixPaths(array(
|
|
|
|
|
array(
|
|
|
|
|
'prefix' => 'Icinga\\Web\\Form\\Element\\',
|
|
|
|
|
'path' => Icinga::app()->getLibraryDir('Icinga/Web/Form/Element'),
|
|
|
|
|
'type' => static::ELEMENT
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'prefix' => 'Icinga\\Web\\Form\\Decorator\\',
|
|
|
|
|
'path' => Icinga::app()->getLibraryDir('Icinga/Web/Form/Decorator'),
|
|
|
|
|
'type' => static::DECORATOR
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
|
{
|
2019-01-14 02:48:20 -05:00
|
|
|
$this->addElement(
|
|
|
|
|
'text',
|
|
|
|
|
'parent',
|
|
|
|
|
[
|
|
|
|
|
'allowEmpty' => true,
|
|
|
|
|
'filters' => ['Null'],
|
|
|
|
|
'validators' => [
|
|
|
|
|
['Callback', true, [
|
2019-02-14 09:32:51 -05:00
|
|
|
'callback' => function ($name) {
|
2019-01-14 02:48:20 -05:00
|
|
|
return empty($name) || $this->bp->hasBpNode($name);
|
|
|
|
|
},
|
|
|
|
|
'messages' => [
|
|
|
|
|
'callbackValue' => $this->translate('No process found with name %value%')
|
|
|
|
|
]
|
|
|
|
|
]]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
);
|
2018-12-17 08:49:26 -05:00
|
|
|
$this->addElement(
|
|
|
|
|
'number',
|
|
|
|
|
'from',
|
|
|
|
|
[
|
|
|
|
|
'required' => true,
|
|
|
|
|
'min' => 0
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'number',
|
|
|
|
|
'to',
|
|
|
|
|
[
|
|
|
|
|
'required' => true,
|
|
|
|
|
'min' => 0
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'hidden',
|
|
|
|
|
'csrfToken',
|
|
|
|
|
[
|
|
|
|
|
'required' => true
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->setSubmitLabel('movenode');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Node $node
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setNode(Node $node)
|
|
|
|
|
{
|
|
|
|
|
$this->node = $node;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param BpNode|null $node
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setParentNode(BpNode $node = null)
|
|
|
|
|
{
|
|
|
|
|
$this->parentNode = $node;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onSuccess()
|
|
|
|
|
{
|
|
|
|
|
if (! CsrfToken::isValid($this->getValue('csrfToken'))) {
|
|
|
|
|
throw new HttpException(403, 'nope');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$changes = ProcessChanges::construct($this->bp, $this->session);
|
|
|
|
|
if (! $this->bp->getMetadata()->isManuallyOrdered()) {
|
|
|
|
|
$changes->applyManualOrder();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 08:59:56 -05:00
|
|
|
try {
|
|
|
|
|
$changes->moveNode(
|
|
|
|
|
$this->node,
|
|
|
|
|
$this->getValue('from'),
|
|
|
|
|
$this->getValue('to'),
|
|
|
|
|
$this->getValue('parent'),
|
|
|
|
|
$this->parentNode !== null ? $this->parentNode->getName() : null
|
|
|
|
|
);
|
|
|
|
|
} catch (ModificationError $e) {
|
2019-01-25 01:44:35 -05:00
|
|
|
$this->notifyError($e->getMessage());
|
2023-08-14 03:50:53 -04:00
|
|
|
/** @var Web $app */
|
|
|
|
|
$app = Icinga::app();
|
|
|
|
|
$app->getResponse()
|
2019-02-22 03:12:07 -05:00
|
|
|
// Web 2's JS forces a content update for non-200s. Our own JS
|
|
|
|
|
// can't prevent this, hence we're not making this a 400 :(
|
|
|
|
|
//->setHttpResponseCode(400)
|
|
|
|
|
->setHeader('X-Icinga-Container', 'ignore')
|
|
|
|
|
->sendResponse();
|
|
|
|
|
exit;
|
2019-01-14 08:59:56 -05:00
|
|
|
}
|
2018-12-17 08:49:26 -05:00
|
|
|
|
|
|
|
|
// Trigger session destruction to make sure it get's stored.
|
|
|
|
|
unset($changes);
|
|
|
|
|
|
2024-04-22 04:51:06 -04:00
|
|
|
$this->notifySuccess($this->translate('Node order updated'));
|
2019-02-22 03:12:07 -05:00
|
|
|
|
|
|
|
|
$response = $this->getRequest()->getResponse()
|
2023-07-26 10:55:09 -04:00
|
|
|
->setHeader('X-Icinga-Container', 'ignore')
|
|
|
|
|
->setHeader('X-Icinga-Extra-Updates', implode(';', [
|
|
|
|
|
$this->getRequest()->getHeader('X-Icinga-Container'),
|
|
|
|
|
$this->getSuccessUrl()->getAbsoluteUrl()
|
|
|
|
|
]));
|
2019-02-22 03:12:07 -05:00
|
|
|
|
|
|
|
|
Session::getSession()->write();
|
|
|
|
|
$response->sendResponse();
|
|
|
|
|
exit;
|
2018-12-17 08:49:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasBeenSent()
|
|
|
|
|
{
|
|
|
|
|
return true; // This form has no id
|
|
|
|
|
}
|
|
|
|
|
}
|