2021-02-20 14:03:54 +00:00
|
|
|
|
package shroom
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2022-04-02 16:58:57 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/backlinks"
|
2021-02-20 14:03:54 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/history"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/user"
|
|
|
|
|
)
|
|
|
|
|
|
2022-02-20 09:27:30 +00:00
|
|
|
|
// Delete deletes the hypha and makes a history record about that.
|
|
|
|
|
func Delete(u *user.User, h hyphae.ExistingHypha) error {
|
2022-02-19 16:42:32 +00:00
|
|
|
|
hop := history.
|
2022-02-19 08:26:38 +00:00
|
|
|
|
Operation(history.TypeDeleteHypha).
|
|
|
|
|
WithMsg(fmt.Sprintf("Delete ‘%s’", h.CanonicalName())).
|
|
|
|
|
WithUser(u)
|
2021-02-20 14:03:54 +00:00
|
|
|
|
|
2022-02-20 09:27:30 +00:00
|
|
|
|
originalText, _ := FetchTextFile(h)
|
2022-02-19 08:26:38 +00:00
|
|
|
|
switch h := h.(type) {
|
|
|
|
|
case *hyphae.MediaHypha:
|
|
|
|
|
hop.WithFilesRemoved(h.MediaFilePath(), h.TextFilePath())
|
|
|
|
|
case *hyphae.TextualHypha:
|
|
|
|
|
hop.WithFilesRemoved(h.TextFilePath())
|
|
|
|
|
}
|
2022-02-20 09:27:30 +00:00
|
|
|
|
if hop.Apply().HasErrors() {
|
|
|
|
|
return hop.Errs[0]
|
2021-02-20 14:03:54 +00:00
|
|
|
|
}
|
2022-02-20 09:27:30 +00:00
|
|
|
|
backlinks.UpdateBacklinksAfterDelete(h, originalText)
|
|
|
|
|
hyphae.DeleteHypha(h)
|
2022-02-19 16:42:32 +00:00
|
|
|
|
return nil
|
2021-02-20 14:03:54 +00:00
|
|
|
|
}
|