From 74a65079028e0bb41e18770e14e60a9881435cb8 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 22 Oct 2022 18:59:29 +0100 Subject: [PATCH] implement the 're-populate search DB' functionality (web.lisp). This feature is part of the 'danger zone' section in the site's settings. This feature clears the Meilisearch database (with this site's Archive Entries) and re-populates it with the data from this website's (nera) database. --- src/web.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/web.lisp b/src/web.lisp index 2e36db3..3ad1f47 100644 --- a/src/web.lisp +++ b/src/web.lisp @@ -1485,6 +1485,26 @@ (format nil "~a" (mito.dao.mixin:object-updated-at item)))))))))) +(defroute ("/danger/repopulate-search-db" :method :POST) () + (destructuring-bind + (&key authenticity-token &allow-other-keys) + (utils:request-params (lack.request:request-body-parameters ningle:*request*)) + (cond ((not (string= authenticity-token (auth:csrf-token))) + `(,+forbidden+ (:content-type "text/plain") ("Denied"))) + (t (hermetic:auth + (:administrator) + ;; Authorised + (progn + (search:repopulate-database (nera:get-all-archive-entries)) + (utils:set-alert + "Search database re-populated. Great Success!" "success") + (redirect "/site-settings")) + ;; Not Authorised + (progn (utils:set-alert + "You are not authorised to use this feature." + "error") + (redirect "/login"))))))) + ;; ;; Error pages