From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Web/Table/ConfigFileDiffTable.php | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 library/Director/Web/Table/ConfigFileDiffTable.php (limited to 'library/Director/Web/Table/ConfigFileDiffTable.php') diff --git a/library/Director/Web/Table/ConfigFileDiffTable.php b/library/Director/Web/Table/ConfigFileDiffTable.php new file mode 100644 index 0000000..1d14d5e --- /dev/null +++ b/library/Director/Web/Table/ConfigFileDiffTable.php @@ -0,0 +1,140 @@ +getAttributes()->add('class', 'config-diff'); + return $table->setLeftChecksum($leftSum) + ->setRightChecksum($rightSum); + } + + public function renderRow($row) + { + $tr = $this::row([ + $this->getFileFiffLink($row), + $row->file_path, + ]); + + $tr->getAttributes()->add('class', 'file-' . $row->file_action); + return $tr; + } + + protected function getFileFiffLink($row) + { + $params = array('file_path' => $row->file_path); + + if ($row->file_checksum_left === $row->file_checksum_right) { + $params['config_checksum'] = $row->config_checksum_right; + } elseif ($row->file_checksum_left === null) { + $params['config_checksum'] = $row->config_checksum_right; + } elseif ($row->file_checksum_right === null) { + $params['config_checksum'] = $row->config_checksum_left; + } else { + $params['left'] = $row->config_checksum_left; + $params['right'] = $row->config_checksum_right; + return Link::create( + $row->file_action, + 'director/config/filediff', + $params + ); + } + + return Link::create($row->file_action, 'director/config/file', $params); + } + + public function setLeftChecksum($checksum) + { + $this->leftChecksum = $checksum; + return $this; + } + + public function setRightChecksum($checksum) + { + $this->rightChecksum = $checksum; + return $this; + } + + public function getTitles() + { + return array( + $this->translate('Action'), + $this->translate('File'), + ); + } + + public function prepareQuery() + { + $db = $this->db(); + + $left = $db->select() + ->from( + array('cfl' => 'director_generated_config_file'), + array( + 'file_path' => 'COALESCE(cfl.file_path, cfr.file_path)', + 'config_checksum_left' => $this->dbHexFunc('cfl.config_checksum'), + 'config_checksum_right' => $this->dbHexFunc('cfr.config_checksum'), + 'file_checksum_left' => $this->dbHexFunc('cfl.file_checksum'), + 'file_checksum_right' => $this->dbHexFunc('cfr.file_checksum'), + 'file_action' => '(CASE WHEN cfr.config_checksum IS NULL' + . " THEN 'removed' WHEN cfl.file_checksum = cfr.file_checksum" + . " THEN 'unmodified' ELSE 'modified' END)", + ) + )->joinLeft( + array('cfr' => 'director_generated_config_file'), + $db->quoteInto( + 'cfl.file_path = cfr.file_path AND cfr.config_checksum = ?', + $this->quoteBinary(hex2bin($this->rightChecksum)) + ), + array() + )->where( + 'cfl.config_checksum = ?', + $this->quoteBinary(hex2bin($this->leftChecksum)) + ); + + $right = $db->select() + ->from( + array('cfl' => 'director_generated_config_file'), + array( + 'file_path' => 'COALESCE(cfr.file_path, cfl.file_path)', + 'config_checksum_left' => $this->dbHexFunc('cfl.config_checksum'), + 'config_checksum_right' => $this->dbHexFunc('cfr.config_checksum'), + 'file_checksum_left' => $this->dbHexFunc('cfl.file_checksum'), + 'file_checksum_right' => $this->dbHexFunc('cfr.file_checksum'), + 'file_action' => "('created')", + ) + )->joinRight( + array('cfr' => 'director_generated_config_file'), + $db->quoteInto( + 'cfl.file_path = cfr.file_path AND cfl.config_checksum = ?', + $this->quoteBinary(hex2bin($this->leftChecksum)) + ), + array() + )->where( + 'cfr.config_checksum = ?', + $this->quoteBinary(hex2bin($this->rightChecksum)) + )->where('cfl.file_checksum IS NULL'); + + return $db->select()->union(array($left, $right))->order('file_path'); + } +} -- cgit v1.2.3