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 Import
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.List as L
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
|
||||||
|
@ -149,8 +150,18 @@ getAdminAlbumDeleteR albumId = do
|
||||||
albumList <- return $ userAlbums owner
|
albumList <- return $ userAlbums owner
|
||||||
newAlbumList <- return $ removeItem albumId albumList
|
newAlbumList <- return $ removeItem albumId albumList
|
||||||
runDB $ update ownerId [UserAlbums =. newAlbumList]
|
runDB $ update ownerId [UserAlbums =. newAlbumList]
|
||||||
-- delete album content
|
-- delete album content and its comments
|
||||||
mapM (\a -> runDB $ delete a) (albumContent album)
|
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
|
-- delete album
|
||||||
runDB $ delete albumId
|
runDB $ delete albumId
|
||||||
-- delete files
|
-- delete files
|
||||||
|
|
|
@ -116,9 +116,13 @@ getAdminMediumDeleteR mediumId = do
|
||||||
mediaList <- return $ albumContent album
|
mediaList <- return $ albumContent album
|
||||||
newMediaList <- return $ removeItem mediumId mediaList
|
newMediaList <- return $ removeItem mediumId mediaList
|
||||||
runDB $ update albumId [AlbumContent =. newMediaList]
|
runDB $ update albumId [AlbumContent =. newMediaList]
|
||||||
|
-- delete comments
|
||||||
|
commEnts <- runDB $ selectList [CommentOrigin ==. mediumId] []
|
||||||
|
mapM (\ent -> runDB $ delete $ entityKey ent) commEnts
|
||||||
-- delete medium
|
-- delete medium
|
||||||
runDB $ delete mediumId
|
runDB $ delete mediumId
|
||||||
-- delete file
|
-- delete files
|
||||||
|
liftIO $ removeFile (normalise $ tail $ mediumPath medium)
|
||||||
liftIO $ removeFile (normalise $ tail $ mediumPath medium)
|
liftIO $ removeFile (normalise $ tail $ mediumPath medium)
|
||||||
-- outro
|
-- outro
|
||||||
setMessage "Medium deleted successfully"
|
setMessage "Medium deleted successfully"
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Handler.AdminProfileSettings where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.List as L
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
|
||||||
|
@ -167,7 +168,17 @@ getAdminProfileDeleteR ownerId = do
|
||||||
mapM (\albumId -> do
|
mapM (\albumId -> do
|
||||||
album <- runDB $ getJust albumId
|
album <- runDB $ getJust albumId
|
||||||
mediaList <- return $ albumContent album
|
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
|
runDB $ delete albumId
|
||||||
) albumList
|
) albumList
|
||||||
runDB $ delete ownerId
|
runDB $ delete ownerId
|
||||||
|
|
Loading…
Reference in a new issue