From e5f7633d1e9815e3734150d7e92118151c707d36 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Aug 2017 09:23:45 +0200 Subject: [PATCH] Automation: move and refactor related tables --- application/tables/ImportsourceTable.php | 63 -------------- application/tables/JobTable.php | 75 ----------------- application/tables/SyncruleTable.php | 63 -------------- .../Director/Web/Table/ImportsourceTable.php | 63 ++++++++++++++ library/Director/Web/Table/JobTable.php | 82 +++++++++++++++++++ library/Director/Web/Table/SyncruleTable.php | 67 +++++++++++++++ 6 files changed, 212 insertions(+), 201 deletions(-) delete mode 100644 application/tables/ImportsourceTable.php delete mode 100644 application/tables/JobTable.php delete mode 100644 application/tables/SyncruleTable.php create mode 100644 library/Director/Web/Table/ImportsourceTable.php create mode 100644 library/Director/Web/Table/JobTable.php create mode 100644 library/Director/Web/Table/SyncruleTable.php diff --git a/application/tables/ImportsourceTable.php b/application/tables/ImportsourceTable.php deleted file mode 100644 index 4f134d2f..00000000 --- a/application/tables/ImportsourceTable.php +++ /dev/null @@ -1,63 +0,0 @@ - 's.id', - 'source_name' => 's.source_name', - 'provider_class' => 's.provider_class', - 'import_state' => 's.import_state', - 'last_error_message' => 's.last_error_message', - 'description' => 'CASE WHEN s.description IS NULL THEN s.source_name' - . " ELSE s.source_name || ': ' || s.description END", - ); - } - - protected function getActionUrl($row) - { - return $this->url('director/importsource', array('id' => $row->id)); - } - - public function getTitles() - { - $view = $this->view(); - return array( - 'description' => $view->translate('Source name'), - ); - } - - protected function listTableClasses() - { - return array_merge(array('syncstate'), parent::listTableClasses()); - } - - protected function getRowClasses($row) - { - if ($row->import_state === 'failing' && $row->last_error_message) { - $row->source_name .= ' (' . $row->last_error_message . ')'; - } - - return $row->import_state; - } - - public function getBaseQuery() - { - return $this->db()->select()->from( - array('s' => 'import_source'), - array() - )->order('source_name ASC'); - } -} diff --git a/application/tables/JobTable.php b/application/tables/JobTable.php deleted file mode 100644 index edd9e827..00000000 --- a/application/tables/JobTable.php +++ /dev/null @@ -1,75 +0,0 @@ - 'j.id', - 'job_name' => 'j.job_name', - 'job_class' => 'j.job_class', - 'disabled' => 'j.disabled', - 'run_interval' => 'j.run_interval', - 'last_attempt_succeeded' => 'j.last_attempt_succeeded', - 'ts_last_attempt' => 'j.ts_last_attempt', - 'unixts_last_attempt' => 'UNIX_TIMESTAMP(j.ts_last_attempt)', - 'ts_last_error' => 'j.ts_last_error', - 'last_error_message' => 'j.last_error_message', - ); - } - - protected function getActionUrl($row) - { - return $this->url('director/job', array('id' => $row->id)); - } - - protected function listTableClasses() - { - return array_merge(array('jobs'), parent::listTableClasses()); - } - - protected function getRowClasses($row) - { - if ($row->unixts_last_attempt === null) { - return 'pending'; - } - - if ($row->last_attempt_succeeded === 'n' && $row->last_error_message) { - $row->job_name .= ' (' . $row->last_error_message . ')'; - } - - if ($row->unixts_last_attempt + $row->run_interval < time()) { - return 'pending'; - } - - if ($row->last_attempt_succeeded === 'y') { - return 'ok'; - } elseif ($row->last_attempt_succeeded === 'n') { - return 'critical'; - } else { - return 'unknown'; - } - } - - public function getTitles() - { - $view = $this->view(); - return array( - 'job_name' => $view->translate('Job name'), - ); - } - - public function getBaseQuery() - { - return $this->db()->select()->from( - array('j' => 'director_job'), - array() - )->order('job_name'); - } -} diff --git a/application/tables/SyncruleTable.php b/application/tables/SyncruleTable.php deleted file mode 100644 index d6c12234..00000000 --- a/application/tables/SyncruleTable.php +++ /dev/null @@ -1,63 +0,0 @@ - 's.id', - 'rule_name' => 's.rule_name', - 'sync_state' => 's.sync_state', - 'object_type' => 's.object_type', - 'update_policy' => 's.update_policy', - 'purge_existing' => 's.purge_existing', - 'filter_expression' => 's.filter_expression', - 'last_error_message' => 's.last_error_message', - 'description' => 'CASE WHEN s.description IS NULL THEN s.rule_name' - . " ELSE s.rule_name || ': ' || s.description END", - ); - } - - protected function getActionUrl($row) - { - return $this->url('director/syncrule', array('id' => $row->id)); - } - - protected function listTableClasses() - { - return array_merge(array('syncstate'), parent::listTableClasses()); - } - - protected function getRowClasses($row) - { - if ($row->sync_state === 'failing' && $row->last_error_message) { - $row->rule_name .= ' (' . $row->last_error_message . ')'; - } - - return $row->sync_state; - } - - public function getTitles() - { - $view = $this->view(); - return array( - 'description' => $view->translate('Rule name'), - 'object_type' => $view->translate('Object type'), - ); - } - - public function getBaseQuery() - { - return $this->db()->select()->from( - array('s' => 'sync_rule'), - array() - )->order('rule_name'); - } -} diff --git a/library/Director/Web/Table/ImportsourceTable.php b/library/Director/Web/Table/ImportsourceTable.php new file mode 100644 index 00000000..6763c253 --- /dev/null +++ b/library/Director/Web/Table/ImportsourceTable.php @@ -0,0 +1,63 @@ +translate('Source name'), + ]; + } + + protected function assemble() + { + $this->attributes()->add('class', 'syncstate'); + parent::assemble(); + } + + public function renderRow($row) + { + $caption = [Link::create( + $row->source_name, + 'director/importsource', + ['id' => $row->id] + )]; + if ($row->description !== null) { + $caption[] = ': ' . $row->description; + } + + if ($row->import_state === 'failing' && $row->last_error_message) { + $caption[] = ' (' . $row->last_error_message . ')'; + } + + $tr = $this::row([$caption]); + $tr->attributes()->add('class', $row->import_state); + + return $tr; + } + + public function prepareQuery() + { + return $this->db()->select()->from( + ['s' => 'import_source'], + [ + 'id' => 's.id', + 'source_name' => 's.source_name', + 'provider_class' => 's.provider_class', + 'import_state' => 's.import_state', + 'last_error_message' => 's.last_error_message', + 'description' => 's.description', + ] + )->order('source_name ASC'); + } +} diff --git a/library/Director/Web/Table/JobTable.php b/library/Director/Web/Table/JobTable.php new file mode 100644 index 00000000..26219304 --- /dev/null +++ b/library/Director/Web/Table/JobTable.php @@ -0,0 +1,82 @@ +attributes()->add('class', 'jobs'); + parent::assemble(); + } + + public function renderRow($row) + { + $caption = [Link::create( + $row->job_name, + 'director/job', + ['id' => $row->id] + )]; + + if ($row->last_attempt_succeeded === 'n' && $row->last_error_message) { + $caption[] = ' (' . $row->last_error_message . ')'; + } + + $tr = $this::row([$caption]); + $tr->attributes()->add('class', $this->getJobClasses($row)); + + return $tr; + } + + protected function getJobClasses($row) + { + if ($row->unixts_last_attempt === null) { + return 'pending'; + } + + if ($row->unixts_last_attempt + $row->run_interval < time()) { + return 'pending'; + } + + if ($row->last_attempt_succeeded === 'y') { + return 'ok'; + } elseif ($row->last_attempt_succeeded === 'n') { + return 'critical'; + } else { + return 'unknown'; + } + } + + public function getColumnsToBeRendered() + { + return [ + $this->translate('Job name'), + ]; + } + + public function prepareQuery() + { + return $this->db()->select()->from( + ['j' => 'director_job'], + [ + 'id' => 'j.id', + 'job_name' => 'j.job_name', + 'job_class' => 'j.job_class', + 'disabled' => 'j.disabled', + 'run_interval' => 'j.run_interval', + 'last_attempt_succeeded' => 'j.last_attempt_succeeded', + 'ts_last_attempt' => 'j.ts_last_attempt', + 'unixts_last_attempt' => 'UNIX_TIMESTAMP(j.ts_last_attempt)', + 'ts_last_error' => 'j.ts_last_error', + 'last_error_message' => 'j.last_error_message', + ] + )->order('job_name'); + } +} diff --git a/library/Director/Web/Table/SyncruleTable.php b/library/Director/Web/Table/SyncruleTable.php new file mode 100644 index 00000000..b36b3158 --- /dev/null +++ b/library/Director/Web/Table/SyncruleTable.php @@ -0,0 +1,67 @@ +attributes()->add('class', 'syncstate'); + parent::assemble(); + } + + public function renderRow($row) + { + $caption = [Link::create( + $row->rule_name, + 'director/syncrule', + ['id' => $row->id] + )]; + if ($row->description !== null) { + $caption[] = ': ' . $row->description; + } + + if ($row->sync_state === 'failing' && $row->last_error_message) { + $caption[] = ' (' . $row->last_error_message . ')'; + } + + $tr = $this::row([$caption, $row->object_type]); + $tr->attributes()->add('class', $row->sync_state); + + return $tr; + } + + public function getColumnsToBeRendered() + { + return [ + $this->translate('Rule name'), + $this->translate('Object type'), + ]; + } + + public function prepareQuery() + { + return $this->db()->select()->from( + ['s' => 'sync_rule'], + [ + 'id' => 's.id', + 'rule_name' => 's.rule_name', + 'sync_state' => 's.sync_state', + 'object_type' => 's.object_type', + 'update_policy' => 's.update_policy', + 'purge_existing' => 's.purge_existing', + 'filter_expression' => 's.filter_expression', + 'last_error_message' => 's.last_error_message', + 'description' => 's.description', + ] + )->order('rule_name'); + } +}