config/schema: add controller and view script

This commit is contained in:
Thomas Gelf 2015-07-30 15:08:55 +02:00
parent 91ebe4ce32
commit 3c8f3a7ade
3 changed files with 75 additions and 1 deletions

View 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');
}
}
}

View File

@ -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();

View 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>