mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-22 13:24:25 +02:00
config/schema: add controller and view script
This commit is contained in:
parent
91ebe4ce32
commit
3c8f3a7ade
62
application/controllers/SchemaController.php
Normal file
62
application/controllers/SchemaController.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
|
||||
class Director_SchemaController extends ActionController
|
||||
{
|
||||
protected $schema;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->schemas = array(
|
||||
'mysql' => $this->translate('MySQL schema'),
|
||||
'pgsql' => $this->translate('PostgreSQL schema'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function tabs()
|
||||
{
|
||||
$tabs = $this->getTabs();
|
||||
foreach ($this->schemas as $type => $title) {
|
||||
$tabs->add($type, array(
|
||||
'url' => 'director/schema/' . $type,
|
||||
'label' => $title,
|
||||
));
|
||||
}
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public function mysqlAction()
|
||||
{
|
||||
$this->serveSchema('mysql');
|
||||
}
|
||||
|
||||
public function pgsqlAction()
|
||||
{
|
||||
$this->serveSchema('pgsql');
|
||||
}
|
||||
|
||||
protected function serveSchema($type)
|
||||
{
|
||||
$schema = file_get_contents(
|
||||
sprintf(
|
||||
'%s/schema/%s.sql',
|
||||
$this->Module()->getBasedir(),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->params->get('format') === 'sql') {
|
||||
header('Content-type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename=' . $type . '.sql');
|
||||
echo $schema;
|
||||
exit;
|
||||
// TODO: Shutdown
|
||||
} else {
|
||||
$this->tabs()->activate($type);
|
||||
$this->view->title = $this->schemas[$type];
|
||||
$this->view->schema = $schema;
|
||||
$this->render('schema');
|
||||
}
|
||||
}
|
||||
}
|
@ -88,7 +88,9 @@ class ConfigForm extends QuickForm
|
||||
);
|
||||
$link = $this->getView()->qlink(
|
||||
$this->translate('database schema'),
|
||||
'director/schema/' . $resource->getDbType()
|
||||
'director/schema/' . $resource->getDbType(),
|
||||
null,
|
||||
array('data-base-target' => '_next')
|
||||
);
|
||||
$this->addHtmlHint(sprintf($hint, $link));
|
||||
$this->moveSubmitToBottom();
|
||||
|
10
application/views/scripts/schema/schema.phtml
Normal file
10
application/views/scripts/schema/schema.phtml
Normal file
@ -0,0 +1,10 @@
|
||||
<div class="controls">
|
||||
<?= $tabs ?>
|
||||
<h1><?= $this->escape($title) ?></h1>
|
||||
<a href="<?= $this->url()->with('format', 'sql') ?>" target="_blank"><?= $this->icon('download') ?>Download</a>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<pre><?= $this->escape($schema) ?></pre>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user