diff --git a/Handler/AlbumSettings.hs b/Handler/AlbumSettings.hs index 324fb0e..21fd4f0 100644 --- a/Handler/AlbumSettings.hs +++ b/Handler/AlbumSettings.hs @@ -162,8 +162,17 @@ postAlbumDeleteR 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 + runDB $ delete a + ) (albumContent album) -- delete album runDB $ delete albumId -- delete files diff --git a/Handler/MediumSettings.hs b/Handler/MediumSettings.hs index 6384a27..4387307 100644 --- a/Handler/MediumSettings.hs +++ b/Handler/MediumSettings.hs @@ -129,6 +129,9 @@ postMediumDeleteR mediumId = do confirm <- lookupPostParam "confirm" case confirm of Just "confirm" -> do + -- delete comments + commEnts <- runDB $ selectList [CommentOrigin ==. mediumId] [] + mapM (\ent -> runDB $ delete $ entityKey ent) commEnts -- delete references first albumId <- return $ mediumAlbum medium album <- runDB $ getJust albumId diff --git a/Handler/ProfileDelete.hs b/Handler/ProfileDelete.hs index 52d0116..a5ad09a 100644 --- a/Handler/ProfileDelete.hs +++ b/Handler/ProfileDelete.hs @@ -3,6 +3,7 @@ module Handler.ProfileDelete where import Import import qualified Data.Text as T import Data.Maybe +import qualified Data.List as L import System.Directory import System.FilePath @@ -50,7 +51,14 @@ postProfileDeleteR userId = do mapM (\albumId -> do album <- runDB $ getJust albumId mediaList <- return $ albumContent album - mapM (\med -> runDB $ delete med) mediaList + mapM (\med -> do + commEnts <- runDB $ selectList [CommentOrigin ==. med] [] + mapM (\ent -> runDB $ delete $ entityKey ent) commEnts + medium <- runDB $ getJust med + liftIO $ removeFile (normalise $ L.tail $ mediumPath medium) + liftIO $ removeFile (normalise $ L.tail $ mediumThumb medium) + runDB $ delete med + ) mediaList runDB $ delete albumId ) albumList runDB $ delete userId