mirror of
https://github.com/foomo/gocontentful.git
synced 2025-10-16 12:25:39 +00:00
DeleteAsset and improved DeleteEntry
This commit is contained in:
parent
1053d88a5d
commit
bb4ad90ccb
@ -402,6 +402,24 @@ func ToAssetReference(asset *contentful.Asset) (refSys ContentTypeSys) {
|
||||
return
|
||||
}
|
||||
|
||||
func (cc *ContentfulClient) DeleteAsset(asset *contentful.Asset) error {
|
||||
if cc.Client == nil {
|
||||
return errors.New("DeleteAsset: No client available")
|
||||
}
|
||||
if cc.clientMode != ClientModeCMA {
|
||||
return errors.New("DeleteAsset: Only available in ClientModeCMA")
|
||||
}
|
||||
errUnpublish := cc.Client.Assets.Unpublish(cc.SpaceID, asset)
|
||||
if errUnpublish != nil && !strings.Contains(errUnpublish.Error(), "Not published") {
|
||||
return errUnpublish
|
||||
}
|
||||
errDelete := cc.Client.Assets.Delete(cc.SpaceID, asset)
|
||||
if errDelete != nil {
|
||||
return errDelete
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RichText utils
|
||||
|
||||
func HtmlToRichText(htmlSrc string) *RichTextNode {
|
||||
|
||||
@ -613,7 +613,7 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) DeleteEntry() (err error) {
|
||||
}
|
||||
if cfEntry.Sys.PublishedCounter > 0 {
|
||||
errUnpublish := vo.CC.Client.Entries.Unpublish(vo.CC.SpaceID, cfEntry)
|
||||
if errUnpublish != nil {
|
||||
if errUnpublish != nil && !strings.Contains(errUnpublish.Error(), "Not published") {
|
||||
return fmt.Errorf("Cf{{ firstCap $contentType.Sys.ID }} DeleteEntry: Unpublish entry failed: %w", errUnpublish)
|
||||
}
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
golang.org/x/mod v0.4.2 // indirect
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d // indirect
|
||||
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 // indirect
|
||||
golang.org/x/tools v0.1.0
|
||||
moul.io/http2curl v1.0.0 // indirect
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@ -38,6 +38,8 @@ golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e h1:XNp2Flc/1eWQGk5BLzqTAN7fQ
|
||||
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d h1:jbzgAvDZn8aEnytae+4ou0J0GwFZoHR0hOrTg4qH8GA=
|
||||
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 h1:64ChN/hjER/taL4YJuA+gpLfIMT+/NFherRZixbxOhg=
|
||||
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
||||
Loading…
Reference in New Issue
Block a user