33 lines
914 B
Go
33 lines
914 B
Go
package seo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// listen subscribes to the framework's record events (D-92): a deleted
|
|
// record of a content type loses its SEO entries (kept in history), and a
|
|
// created one gets its address snapshot. Listener errors are logged by the
|
|
// bus and never fail the write that fired them.
|
|
func (p *Plugin) listen(app *backpack.App) {
|
|
if app == nil || app.Events == nil {
|
|
return
|
|
}
|
|
app.Events.Listen("golem15.seo", func(ctx context.Context, ev *pact.RecordDeleted) error {
|
|
svc := p.Service()
|
|
if svc == nil {
|
|
return nil
|
|
}
|
|
return svc.RecordDeleted(ctx, ev)
|
|
})
|
|
app.Events.Listen("golem15.seo", func(ctx context.Context, ev *pact.RecordSaved) error {
|
|
svc := p.Service()
|
|
if svc == nil || ev == nil || !ev.Created {
|
|
return nil
|
|
}
|
|
return svc.RecordCreated(ctx, ev)
|
|
})
|
|
}
|