2021-02-20 14:03:54 +00:00
|
|
|
|
package shroom
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2021-12-20 21:08:21 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae/backlinks"
|
2021-02-20 14:03:54 +00:00
|
|
|
|
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/history"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
2021-10-10 03:51:34 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/l18n"
|
2021-02-20 14:03:54 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/user"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// DeleteHypha deletes hypha and makes a history record about that.
|
2022-02-04 10:50:50 +00:00
|
|
|
|
func DeleteHypha(u *user.User, h hyphae.Hypher, lc *l18n.Localizer) (hop *history.Op, errtitle string) {
|
2021-02-20 14:03:54 +00:00
|
|
|
|
hop = history.Operation(history.TypeDeleteHypha)
|
|
|
|
|
|
2021-10-10 03:51:34 +00:00
|
|
|
|
if errtitle, err := CanDelete(u, h, lc); 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.
|
2022-02-04 17:06:37 +00:00
|
|
|
|
WithFilesRemoved(h.TextPartPath(), h.(*hyphae.NonEmptyHypha).BinaryPath()).
|
2022-02-03 22:29:01 +00:00
|
|
|
|
WithMsg(fmt.Sprintf("Delete ‘%s’", h.CanonicalName())).
|
2021-02-20 14:03:54 +00:00
|
|
|
|
WithUser(u).
|
|
|
|
|
Apply()
|
|
|
|
|
if !hop.HasErrors() {
|
2021-12-30 19:59:28 +00:00
|
|
|
|
backlinks.UpdateBacklinksAfterDelete(h, originalText)
|
2022-02-03 21:26:08 +00:00
|
|
|
|
hyphae.DeleteHypha(h)
|
2021-02-20 14:03:54 +00:00
|
|
|
|
}
|
|
|
|
|
return hop, ""
|
|
|
|
|
}
|