2021-02-20 14:03:54 +00:00
|
|
|
|
package shroom
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/history"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/user"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// DeleteHypha deletes hypha and makes a history record about that.
|
2021-10-01 17:12:16 +00:00
|
|
|
|
func DeleteHypha(u *user.User, h *hyphae.Hypha) (hop *history.Op, errtitle string) {
|
2021-02-20 14:03:54 +00:00
|
|
|
|
hop = history.Operation(history.TypeDeleteHypha)
|
|
|
|
|
|
2021-10-01 17:12:16 +00:00
|
|
|
|
if errtitle, err := CanDelete(u, h); errtitle != "" {
|
2021-02-26 16:43:45 +00:00
|
|
|
|
hop.WithErrAbort(err)
|
2021-02-20 14:03:54 +00:00
|
|
|
|
return hop, errtitle
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 19:28:12 +00:00
|
|
|
|
originalText, _ := FetchTextPart(h)
|
2021-02-20 14:03:54 +00:00
|
|
|
|
hop.
|
|
|
|
|
WithFilesRemoved(h.TextPath, h.BinaryPath).
|
|
|
|
|
WithMsg(fmt.Sprintf("Delete ‘%s’", h.Name)).
|
|
|
|
|
WithUser(u).
|
|
|
|
|
Apply()
|
|
|
|
|
if !hop.HasErrors() {
|
2021-08-31 19:28:12 +00:00
|
|
|
|
hyphae.BacklinksOnDelete(h, originalText)
|
2021-02-20 14:03:54 +00:00
|
|
|
|
h.Delete()
|
|
|
|
|
}
|
|
|
|
|
return hop, ""
|
|
|
|
|
}
|