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