From eaa5973d1816747ca43c651a8d50144d19b10aa9 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 21 Dec 2014 21:55:23 +0100 Subject: [PATCH] updated delete routines in admin section --- Handler/AdminAlbumSettings.hs | 15 +++++++++++++-- Handler/AdminMediumSettings.hs | 6 +++++- Handler/AdminProfileSettings.hs | 13 ++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Handler/AdminAlbumSettings.hs b/Handler/AdminAlbumSettings.hs index 65d3387..6f2f621 100644 --- a/Handler/AdminAlbumSettings.hs +++ b/Handler/AdminAlbumSettings.hs @@ -2,6 +2,7 @@ module Handler.AdminAlbumSettings where import Import import qualified Data.Text as T +import qualified Data.List as L import System.FilePath import System.Directory @@ -149,8 +150,18 @@ getAdminAlbumDeleteR albumId = do albumList <- return $ userAlbums owner newAlbumList <- return $ removeItem albumId albumList runDB $ update ownerId [UserAlbums =. newAlbumList] - -- delete album content - mapM (\a -> runDB $ delete a) (albumContent album) + -- delete album content and its comments + mapM (\a -> do + -- delete files + medium <- runDB $ getJust a + liftIO $ removeFile (normalise $ L.tail $ mediumPath medium) + liftIO $ removeFile (normalise $ L.tail $ mediumThumb medium) + -- delete comments + commEnts <- runDB $ selectList [CommentOrigin ==. a] [] + mapM (\ent -> runDB $ delete $ entityKey ent) commEnts + -- delete album database entry + runDB $ delete a + ) (albumContent album) -- delete album runDB $ delete albumId -- delete files diff --git a/Handler/AdminMediumSettings.hs b/Handler/AdminMediumSettings.hs index 730a344..afc5d82 100644 --- a/Handler/AdminMediumSettings.hs +++ b/Handler/AdminMediumSettings.hs @@ -116,9 +116,13 @@ getAdminMediumDeleteR mediumId = do mediaList <- return $ albumContent album newMediaList <- return $ removeItem mediumId mediaList runDB $ update albumId [AlbumContent =. newMediaList] + -- delete comments + commEnts <- runDB $ selectList [CommentOrigin ==. mediumId] [] + mapM (\ent -> runDB $ delete $ entityKey ent) commEnts -- delete medium runDB $ delete mediumId - -- delete file + -- delete files + liftIO $ removeFile (normalise $ tail $ mediumPath medium) liftIO $ removeFile (normalise $ tail $ mediumPath medium) -- outro setMessage "Medium deleted successfully" diff --git a/Handler/AdminProfileSettings.hs b/Handler/AdminProfileSettings.hs index 04432f4..0e6f061 100644 --- a/Handler/AdminProfileSettings.hs +++ b/Handler/AdminProfileSettings.hs @@ -2,6 +2,7 @@ module Handler.AdminProfileSettings where import Import import qualified Data.Text as T +import qualified Data.List as L import System.Directory import System.FilePath @@ -167,7 +168,17 @@ getAdminProfileDeleteR ownerId = do mapM (\albumId -> do album <- runDB $ getJust albumId mediaList <- return $ albumContent album - mapM (\med -> runDB $ delete med) mediaList + mapM (\med -> do + -- delete comments + commEnts <- runDB $ selectList [CommentOrigin ==. med] [] + mapM (\ent -> runDB $ delete $ entityKey ent) commEnts + -- delete media files + medium <- runDB $ getJust med + liftIO $ removeFile (normalise $ L.tail $ mediumPath medium) + liftIO $ removeFile (normalise $ L.tail $ mediumThumb medium) + -- delete medium database entry + runDB $ delete med + ) mediaList runDB $ delete albumId ) albumList runDB $ delete ownerId