- posts: FormAfterCreate/Update purge after the content_html translations, new FormAfterDelete; categories: FormAfterCreate and FormAfterDelete - NewSiteCachePurger refuses half configuration, non-http(s) URLs, user info, fragments, http to a non-loopback host and tokens under 32 chars; Boot logs the endpoint host and path once - TestPostsAdminPurgesSiteCache smoke test - README: Configuration section (keys, contract, timing, scope), API rows
34 lines
884 B
Go
34 lines
884 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.golem15.com/golem15/sm-journal-plugin/classes"
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/cabana"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// siteCachePurger returns the published *classes.SiteCachePurger and the
|
|
// save transaction of ctx, for classes.PurgeSiteCacheAfterCommit. Without a
|
|
// purger (no purge configured) or outside a save transaction it returns a
|
|
// nil purger, which PurgeSiteCacheAfterCommit ignores.
|
|
func siteCachePurger(ctx context.Context, app func() *backpack.App) (*classes.SiteCachePurger, *gorm.DB) {
|
|
if app == nil {
|
|
return nil, nil
|
|
}
|
|
a := app()
|
|
if a == nil {
|
|
return nil, nil
|
|
}
|
|
purger, ok := a.Lookup[*classes.SiteCachePurger]()
|
|
if !ok || purger == nil {
|
|
return nil, nil
|
|
}
|
|
tx, ok := cabana.TxFromContext(ctx)
|
|
if !ok {
|
|
return nil, nil
|
|
}
|
|
return purger, tx
|
|
}
|