From 738a690c43b942df0fe90edea6ba9422cc5d52b6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 15 Dec 2015 19:02:58 +0100 Subject: [PATCH] config/files: new controller action and table --- application/controllers/ConfigController.php | 30 +++++++++ .../tables/GeneratedConfigFileTable.php | 65 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 application/tables/GeneratedConfigFileTable.php diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index cd706de5..beb7c479 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -29,6 +29,36 @@ class ConfigController extends ActionController } } + // Show all files for a given config + public function filesAction() + { + $tabs = $this->getTabs(); + + if ($deploymentId = $this->params->get('deployment_id')) { + $tabs->add('deployment', array( + 'label' => $this->translate('Deployment'), + 'url' => 'director/deployment/show', + 'urlParams' => array( + 'id' => $deploymentId + ) + )); + } + + $tabs->add('config', array( + 'label' => $this->translate('Config'), + 'url' => $this->getRequest()->getUrl(), + ))->activate('config'); + + $checksum = $this->params->get('checksum'); + + $this->view->table = $this + ->loadTable('GeneratedConfigFile') + ->setConnection($this->db()) + ->setConfigChecksum($checksum); + + $this->render('objects/table', null, true); + } + public function showAction() { $tabs = $this->getTabs(); diff --git a/application/tables/GeneratedConfigFileTable.php b/application/tables/GeneratedConfigFileTable.php new file mode 100644 index 00000000..776055c4 --- /dev/null +++ b/application/tables/GeneratedConfigFileTable.php @@ -0,0 +1,65 @@ + 'cf.file_path', + 'size' => 'LENGTH(f.content)', + 'cnt_object' => 'f.cnt_object', + 'cnt_template' => 'f.cnt_template', + 'checksum' => 'LOWER(HEX(f.checksum))', + 'config_checksum' => 'LOWER(HEX(cf.config_checksum))', + ); + + if ($this->connection->getDbType() === 'pgsql') { + $columns['checksum'] = "LOWER(ENCODE(f.checksum, 'hex'))"; + $columns['config_checksum'] = "LOWER(ENCODE(cf.config_checksum, 'hex'))"; + } + + return $columns; + } + + protected function getActionUrl($row) + { + return $this->url('director/config/file', array('checksum' => $row->checksum)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'file_path' => $view->translate('File'), + 'cnt_object' => $view->translate('Objects'), + 'cnt_template' => $view->translate('Templates'), + 'size' => $view->translate('Size'), + ); + } + + public function setConfigChecksum($checksum) + { + $this->enforceFilter('config_checksum', $checksum); + return $this; + } + + public function getBaseQuery() + { + $db = $this->connection()->getConnection(); + + $query = $db->select()->from( + array('cf' => 'director_generated_config_file'), + array() + )->join( + array('f' => 'director_generated_file'), + 'cf.file_checksum = f.checksum', + array() + )->order('cf.file_path ASC'); + + return $query; + } +}