From 3c8f3a7adeb32f99bf28dd591fdc7bed9cce9c5c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 30 Jul 2015 15:08:55 +0200 Subject: [PATCH] config/schema: add controller and view script --- application/controllers/SchemaController.php | 62 +++++++++++++++++++ application/forms/ConfigForm.php | 4 +- application/views/scripts/schema/schema.phtml | 10 +++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 application/controllers/SchemaController.php create mode 100644 application/views/scripts/schema/schema.phtml diff --git a/application/controllers/SchemaController.php b/application/controllers/SchemaController.php new file mode 100644 index 00000000..e216cfce --- /dev/null +++ b/application/controllers/SchemaController.php @@ -0,0 +1,62 @@ +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'); + } + } +} diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php index a5941548..4c9be27c 100644 --- a/application/forms/ConfigForm.php +++ b/application/forms/ConfigForm.php @@ -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(); diff --git a/application/views/scripts/schema/schema.phtml b/application/views/scripts/schema/schema.phtml new file mode 100644 index 00000000..1f900f5e --- /dev/null +++ b/application/views/scripts/schema/schema.phtml @@ -0,0 +1,10 @@ +
+ +

escape($title) ?>

+icon('download') ?>Download +
+ +
+
escape($schema) ?>
+
+