From 2d331584618fe07efe81fd429b1647cd1ad05779 Mon Sep 17 00:00:00 2001 From: Adam Franco Date: Thu, 19 Dec 2024 13:40:15 -0500 Subject: [PATCH] #47: Port the revision JSON view action. --- application/controllers/ExportController.php | 44 ------------------- .../views/scripts/export/viewjson.phtml | 10 ----- src/Controller/AdminExports.php | 18 +++----- templates/admin/export/revisionjson.html.twig | 6 +++ 4 files changed, 13 insertions(+), 65 deletions(-) delete mode 100644 application/controllers/ExportController.php delete mode 100644 application/views/scripts/export/viewjson.phtml create mode 100644 templates/admin/export/revisionjson.html.twig diff --git a/application/controllers/ExportController.php b/application/controllers/ExportController.php deleted file mode 100644 index 19ef57c7..00000000 --- a/application/controllers/ExportController.php +++ /dev/null @@ -1,44 +0,0 @@ -view->csrf_key = $this->_helper->csrfKey(); - - if (!$this->_helper->auth()->isAuthenticated()) { - $this->_helper->auth()->login(); - } - - $config = Zend_Registry::getInstance()->config; - if (!isset($config->admin->administrator_ids)) { - throw new PermissionDeniedException('No admins are defined for this application.'); - } - $admins = explode(',', $config->admin->administrator_ids); - if (!in_array($this->_helper->auth()->getUserId(), $admins)) { - throw new PermissionDeniedException('You are not authorized to administer this application.'.$admins[1]); - } - } -} diff --git a/application/views/scripts/export/viewjson.phtml b/application/views/scripts/export/viewjson.phtml deleted file mode 100644 index 826112fd..00000000 --- a/application/views/scripts/export/viewjson.phtml +++ /dev/null @@ -1,10 +0,0 @@ -headLink(array('rel' => 'stylesheet', 'href' => $this->baseUrl('/StyleSheets/midd/Export.css'), 'media' => 'all')); -?> - -revision) { - print "

Viewing revision: " . $this->revision['last_saved'] . "

"; - print "
" . $this->revision['json_data'] . "
"; - } - ?> diff --git a/src/Controller/AdminExports.php b/src/Controller/AdminExports.php index 22c7b604..d8fdba80 100644 --- a/src/Controller/AdminExports.php +++ b/src/Controller/AdminExports.php @@ -130,21 +130,17 @@ public function revisiondiffAction(int $rev1, int $rev2) * * @since 1/25/18 */ - #[Route('/admin/exports/revision/{revisionId}.json', name: 'admin_exports_config_revision_json')] + #[Route('/admin/exports/revision/{revisionId}/json', name: 'admin_exports_config_revision_json')] public function viewjsonAction(int $revisionId) { - $request = $this->getRequest(); - if (!$request->getParam('revision') || -1 === $request->getParam('revision')) { - header('HTTP/1.1 400 Bad Request'); - echo 'This route requires a revision ID'; - exit; - } - - $db = Zend_Registry::get('db'); + $db = $this->entityManager->getConnection(); $query = 'SELECT * FROM archive_configuration_revisions WHERE id = ?'; $stmt = $db->prepare($query); - $stmt->execute([filter_var($request->get('revision'), \FILTER_SANITIZE_NUMBER_INT)]); - $data['revision'] = $stmt->fetch(); + $stmt->bindValue(1, $revisionId); + $result = $stmt->executeQuery(); + $data['rev'] = $result->fetchAssociative(); + + return $this->render('admin/export/revisionjson.html.twig', $data); } /** diff --git a/templates/admin/export/revisionjson.html.twig b/templates/admin/export/revisionjson.html.twig new file mode 100644 index 00000000..444a8ffe --- /dev/null +++ b/templates/admin/export/revisionjson.html.twig @@ -0,0 +1,6 @@ +{% extends 'base.html.twig' %} + +{% block body %} +

Viewing revision #{{ rev.id }} ({{ rev.last_saved }})

+
{{ rev.json_data }}
+{% endblock %}