diff --git a/src/Controller/AdminExportConfig.php b/src/Controller/AdminExportConfig.php index f7daa881..faed537d 100644 --- a/src/Controller/AdminExportConfig.php +++ b/src/Controller/AdminExportConfig.php @@ -40,6 +40,69 @@ public function listExportConfigs(?int $exportId = null) return $this->render('admin/export/config_form.html.twig', $data); } + /** + * Provide interface for creating a new archive configuration. + */ + #[Route('/admin/exports/create', name: 'export_config_create_form', methods: ['GET'])] + public function createFormAction() + { + $data['catalogs'] = []; + $lookupSession = $this->osidRuntime->getCourseManager()->getCourseCatalogLookupSession(); + $catalogs = $lookupSession->getCourseCatalogs(); + while ($catalogs->hasNext()) { + $data['catalogs'][] = $catalogs->getNextCourseCatalog(); + } + + return $this->render('admin/export/create_config.html.twig', $data); + } + + /** + * Insert a new archive configuration into the database. + */ + #[Route('/admin/exports/create', name: 'export_config_create', methods: ['POST'])] + public function createAction(Request $request) + { + $label = filter_var($request->get('label'), \FILTER_SANITIZE_SPECIAL_CHARS); + $catalogId = filter_var($request->get('catalog_id'), \FILTER_SANITIZE_SPECIAL_CHARS); + + $db = $this->entityManager->getConnection(); + $query = 'INSERT INTO archive_configurations (id, label, catalog_id) VALUES (NULL,:label,:catalogId)'; + $stmt = $db->prepare($query); + $stmt->bindValue('label', $label); + $stmt->bindValue('catalogId', $catalogId); + $stmt->execute(); + + return $this->redirectToRoute('export_config_form', [ + 'exportId' => $db->lastInsertId(), + ]); + } + + /** + * Delete an archive configuration. + */ + #[Route('/admin/exports/{exportId}/delete', name: 'export_config_delete', methods: ['POST'])] + public function deleteconfigAction($exportId) + { + $db = $this->entityManager->getConnection(); + + // Delete revisions that depend on this config. + $query = 'DELETE FROM archive_configuration_revisions WHERE arch_conf_id = ?'; + $stmt = $db->prepare($query); + $stmt->bindValue(1, $exportId); + $stmt->executeQuery(); + + // Delete this config. + $query = 'DELETE FROM archive_configurations WHERE id = ?'; + $stmt = $db->prepare($query); + $stmt->bindValue(1, $exportId); + $stmt->executeQuery(); + + $response = new Response('Success'); + $response->headers->set('Content-Type', 'text/plain; charset=utf-8'); + + return $response; + } + /** * Echo JSON data of latest revision for a particular archive configuration. */ @@ -104,91 +167,34 @@ public function revisionhistoryAction(int $exportId) } /** - * Display diff between two revisions. - * - * @return void - * - * @since 1/25/18 - */ - #[Route('/admin/exports/revisiondiff/{rev1}/{rev2}', name: 'export_config_revision_diff')] - public function revisiondiffAction(int $rev1, int $rev2) - { - $db = $this->entityManager->getConnection(); - $query = 'SELECT * FROM archive_configuration_revisions WHERE id = ?'; - $stmt = $db->prepare($query); - $stmt->bindValue(1, $rev1); - $result = $stmt->executeQuery(); - $data['rev1'] = $result->fetchAssociative(); - - $stmt->bindValue(1, $rev2); - $result = $stmt->executeQuery(); - $data['rev2'] = $result->fetchAssociative(); - - return $this->render('admin/export/revisiondiff.html.twig', $data); - } - - /** - * Display revision JSON data. - * - * @return void - * - * @since 1/25/18 - */ - #[Route('/admin/exports/revision/{revisionId}/json', name: 'export_config_revision_json')] - public function viewjsonAction(int $revisionId) - { - $db = $this->entityManager->getConnection(); - $query = 'SELECT * FROM archive_configuration_revisions WHERE id = ?'; - $stmt = $db->prepare($query); - $stmt->bindValue(1, $revisionId); - $result = $stmt->executeQuery(); - $data['rev'] = $result->fetchAssociative(); - - return $this->render('admin/export/revisionjson.html.twig', $data); - } - - /** - * Provide interface for creating a new archive configuration. - * - * @return void - * - * @since 1/23/18 + * Insert new archive configuration revision to the DB. */ - #[Route('/admin/exports/create', name: 'export_config_create')] - public function newconfigAction() + #[Route('/admin/exports/{exportId}/insertrevision', name: 'export_config_insert_revision', methods: ['POST'])] + public function insertrevisionAction(Request $request, int $exportId) { - $data['catalogs'] = []; - $lookupSession = $this->osidRuntime->getCourseManager()->getCourseCatalogLookupSession(); - $catalogs = $lookupSession->getCourseCatalogs(); - while ($catalogs->hasNext()) { - $data['catalogs'][] = $catalogs->getNextCourseCatalog(); + $safeNote = filter_var($request->get('note'), \FILTER_SANITIZE_SPECIAL_CHARS); + $jsonArray = json_decode($request->get('jsonData')); + foreach ($jsonArray as $key => $value) { + $value = filter_var($value, \FILTER_SANITIZE_SPECIAL_CHARS); } + $safeJsonData = json_encode($jsonArray, \JSON_PRETTY_PRINT); - return $this->render('admin/export/create_config.html.twig', $data); - } - - /** - * Delete an archive configuration. - * - * @return void - * - * @since 1/23/18 - */ - #[Route('/admin/exports/{exportId}/delete', name: 'export_config_delete_config', methods: ['POST'])] - public function deleteconfigAction($exportId) - { $db = $this->entityManager->getConnection(); - - // Delete revisions that depend on this config. - $query = 'DELETE FROM archive_configuration_revisions WHERE arch_conf_id = ?'; - $stmt = $db->prepare($query); - $stmt->bindValue(1, $exportId); - $stmt->executeQuery(); - - // Delete this config. - $query = 'DELETE FROM archive_configurations WHERE id = ?'; + $query = + 'INSERT INTO archive_configuration_revisions (`arch_conf_id`, `note`, `last_saved`, `user_id`, `user_disp_name`, `json_data`) + VALUES ( + :configId, + :note, + CURRENT_TIMESTAMP, + :userId, + :userDN, + :jsonData)'; $stmt = $db->prepare($query); - $stmt->bindValue(1, $exportId); + $stmt->bindValue('configId', $exportId); + $stmt->bindValue('note', $safeNote); + $stmt->bindValue('userId', $this->getUser()->getUserIdentifier()); + $stmt->bindValue('userDN', $this->getUser()->getName()); + $stmt->bindValue('jsonData', $safeJsonData); $stmt->executeQuery(); $response = new Response('Success'); @@ -197,45 +203,6 @@ public function deleteconfigAction($exportId) return $response; } - /** - * Insert a new archive configuration into the database. - */ - #[Route('/admin/exports/insert', name: 'export_config_insert_config', methods: ['POST'])] - public function insertconfigAction(Request $request) - { - $label = filter_var($request->get('label'), \FILTER_SANITIZE_SPECIAL_CHARS); - $catalogId = filter_var($request->get('catalog_id'), \FILTER_SANITIZE_SPECIAL_CHARS); - - $db = $this->entityManager->getConnection(); - $query = 'INSERT INTO archive_configurations (id, label, catalog_id) VALUES (NULL,:label,:catalogId)'; - $stmt = $db->prepare($query); - $stmt->bindValue('label', $label); - $stmt->bindValue('catalogId', $catalogId); - $stmt->execute(); - - return $this->redirectToRoute('export_config_form', [ - 'exportId' => $db->lastInsertId(), - ]); - } - - /** - * Echo JSON data of all archive configuration revisions. - * - * @return void - * - * @since 1/23/18 - */ - public function listrevisionsAction() - { - $this->_helper->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); - - $db = Zend_Registry::get('db'); - $revisions = $db->query('SELECT * FROM archive_configuration_revisions ORDER BY last_saved DESC')->fetchAll(); - - echo json_encode($revisions); - } - /** * Revert to an older revision by re-inserting it with new timestamp. * @@ -280,40 +247,57 @@ public function reverttorevisionAction(Request $request) } /** - * Insert new archive configuration revision to the DB. + * Display diff between two revisions. */ - #[Route('/admin/exports/{exportId}/insertrevision', name: 'export_config_insert_revision', methods: ['POST'])] - public function insertrevisionAction(Request $request, int $exportId) + #[Route('/admin/exports/revisiondiff/{rev1}/{rev2}', name: 'export_config_revision_diff')] + public function revisiondiffAction(int $rev1, int $rev2) { - $safeNote = filter_var($request->get('note'), \FILTER_SANITIZE_SPECIAL_CHARS); - $jsonArray = json_decode($request->get('jsonData')); - foreach ($jsonArray as $key => $value) { - $value = filter_var($value, \FILTER_SANITIZE_SPECIAL_CHARS); - } - $safeJsonData = json_encode($jsonArray, \JSON_PRETTY_PRINT); + $db = $this->entityManager->getConnection(); + $query = 'SELECT * FROM archive_configuration_revisions WHERE id = ?'; + $stmt = $db->prepare($query); + $stmt->bindValue(1, $rev1); + $result = $stmt->executeQuery(); + $data['rev1'] = $result->fetchAssociative(); + + $stmt->bindValue(1, $rev2); + $result = $stmt->executeQuery(); + $data['rev2'] = $result->fetchAssociative(); + return $this->render('admin/export/revisiondiff.html.twig', $data); + } + + /** + * Display revision JSON data. + */ + #[Route('/admin/exports/revision/{revisionId}/json', name: 'export_config_revision_json')] + public function viewjsonAction(int $revisionId) + { $db = $this->entityManager->getConnection(); - $query = - 'INSERT INTO archive_configuration_revisions (`arch_conf_id`, `note`, `last_saved`, `user_id`, `user_disp_name`, `json_data`) - VALUES ( - :configId, - :note, - CURRENT_TIMESTAMP, - :userId, - :userDN, - :jsonData)'; + $query = 'SELECT * FROM archive_configuration_revisions WHERE id = ?'; $stmt = $db->prepare($query); - $stmt->bindValue('configId', $exportId); - $stmt->bindValue('note', $safeNote); - $stmt->bindValue('userId', $this->getUser()->getUserIdentifier()); - $stmt->bindValue('userDN', $this->getUser()->getName()); - $stmt->bindValue('jsonData', $safeJsonData); - $stmt->executeQuery(); + $stmt->bindValue(1, $revisionId); + $result = $stmt->executeQuery(); + $data['rev'] = $result->fetchAssociative(); - $response = new Response('Success'); - $response->headers->set('Content-Type', 'text/plain; charset=utf-8'); + return $this->render('admin/export/revisionjson.html.twig', $data); + } - return $response; + /** + * Echo JSON data of all archive configuration revisions. + * + * @return void + * + * @since 1/23/18 + */ + public function listrevisionsAction() + { + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $db = Zend_Registry::get('db'); + $revisions = $db->query('SELECT * FROM archive_configuration_revisions ORDER BY last_saved DESC')->fetchAll(); + + echo json_encode($revisions); } /** diff --git a/src/Controller/AdminExportScheduling.php b/src/Controller/AdminExportScheduling.php index a0cb3e54..a70124f2 100644 --- a/src/Controller/AdminExportScheduling.php +++ b/src/Controller/AdminExportScheduling.php @@ -5,9 +5,6 @@ use App\Service\Osid\Runtime; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class AdminExportScheduling extends AbstractController diff --git a/templates/admin/export/config_form.html.twig b/templates/admin/export/config_form.html.twig index 873c629d..83d2ce6d 100644 --- a/templates/admin/export/config_form.html.twig +++ b/templates/admin/export/config_form.html.twig @@ -20,10 +20,10 @@ {% endfor %} -
- or - Create a new configuration
+- or - Create a new configuration
-