updated delete routines in admin section
This commit is contained in:
parent
86af6fb1bc
commit
eaa5973d18
3 changed files with 30 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue