delete comments and media files

This commit is contained in:
nek0 2014-12-07 07:55:03 +01:00
parent 5c01dbf185
commit 1d5925af56
3 changed files with 23 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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