BasketController: allow to download JSON via Web
This commit is contained in:
parent
bea52a3091
commit
5d113b3833
|
@ -129,6 +129,12 @@ class BasketController extends ActionController
|
|||
], $this->db());
|
||||
$snapSum = bin2hex($snapshot->get('content_checksum'));
|
||||
|
||||
if ($this->params->get('action') === 'download') {
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json', true);
|
||||
echo $snapshot->getJsonDump();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addTitle(
|
||||
$this->translate('%s: %s (Snapshot)'),
|
||||
$basket->get('basket_name'),
|
||||
|
@ -147,7 +153,16 @@ class BasketController extends ActionController
|
|||
$this->url()->with('action', 'restore'),
|
||||
null,
|
||||
['class' => 'icon-rewind']
|
||||
)
|
||||
),
|
||||
Link::create(
|
||||
$this->translate('Download'),
|
||||
$this->url()->with('action', 'download'),
|
||||
null,
|
||||
[
|
||||
'class' => 'icon-download',
|
||||
'target' => '_blank'
|
||||
]
|
||||
),
|
||||
]);
|
||||
|
||||
$properties = new NameValueTable();
|
||||
|
@ -251,7 +266,7 @@ class BasketController extends ActionController
|
|||
$type,
|
||||
$key,
|
||||
Link::create(
|
||||
substr(bin2hex( $snapshot->get('content_checksum')), 0, 7),
|
||||
substr(bin2hex($snapshot->get('content_checksum')), 0, 7),
|
||||
$snapshotUrl,
|
||||
null,
|
||||
['data-base-target' => '_next']
|
||||
|
|
|
@ -114,6 +114,10 @@ class BasketSnapshot extends DbObject
|
|||
$fields[$id] = DirectorDatafield::loadWithAutoIncId((int) $id, $connection)->export();
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->objects['Datafield'])) {
|
||||
unset($this->objects['Datafield']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addObjectsChosenByBasket(Basket $basket)
|
||||
|
@ -159,7 +163,32 @@ class BasketSnapshot extends DbObject
|
|||
*/
|
||||
public function restoreTo(Db $connection, $replace = true)
|
||||
{
|
||||
$all = Json::decode($this->getJsonDump());
|
||||
static::restoreJson(
|
||||
$this->getJsonDump(),
|
||||
$connection,
|
||||
$replace
|
||||
);
|
||||
}
|
||||
|
||||
public static function restoreJson($string, Db $connection, $replace = true)
|
||||
{
|
||||
$snapshot = new static();
|
||||
$snapshot->restoreObjects(
|
||||
Json::decode($string),
|
||||
$connection,
|
||||
$replace
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $all
|
||||
* @param Db $connection
|
||||
* @param bool $replace
|
||||
* @throws \Icinga\Module\Director\Exception\DuplicateKeyException
|
||||
* @throws \Zend_Db_Adapter_Exception
|
||||
*/
|
||||
protected function restoreObjects($all, Db $connection, $replace = true)
|
||||
{
|
||||
$db = $connection->getDbAdapter();
|
||||
$db->beginTransaction();
|
||||
$fieldMap = [];
|
||||
|
|
|
@ -183,7 +183,8 @@ abstract class ActionController extends Controller implements ControlsAndContent
|
|||
$viewRenderer = null;
|
||||
}
|
||||
|
||||
if ($this->getRequest()->isApiRequest()) {
|
||||
$cType = $this->getResponse()->getHeader('Content-Type', true);
|
||||
if ($this->getRequest()->isApiRequest() || ($cType !== null && $cType !== 'text/html')) {
|
||||
$this->_helper->layout()->disableLayout();
|
||||
if ($viewRenderer) {
|
||||
$viewRenderer->disable();
|
||||
|
|
Loading…
Reference in New Issue