fix: fire RecordSaved for tags the post API creates by name
journal-tag is a content type, but tags created on the fly from names in a post write fired no event, so SEO and sitemap subscribers only heard of them from a later bulk job. Each created tag now fires a RecordSaved with Created inside the post write's transaction.
This commit is contained in:
@@ -227,13 +227,17 @@ func Store(app *backpack.App) http.HandlerFunc {
|
||||
if err := tx.Create(post).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := applyPostAssocs(ctx, tx, post, body); err != nil {
|
||||
tags, err := applyPostAssocs(ctx, tx, post, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := loadPostAssocs(tx, post); err != nil {
|
||||
return err
|
||||
}
|
||||
cabana.EmitRecordSaved(ctx, app, tx, postSavedEvent(ctx, tx, nil, post, body))
|
||||
for _, tag := range tags {
|
||||
cabana.EmitRecordSaved(ctx, app, tx, tagSavedEvent(ctx, &tag))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -291,13 +295,17 @@ func Update(app *backpack.App) http.HandlerFunc {
|
||||
if err := tx.Save(post).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := applyPostAssocs(ctx, tx, post, body); err != nil {
|
||||
tags, err := applyPostAssocs(ctx, tx, post, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := loadPostAssocs(tx, post); err != nil {
|
||||
return err
|
||||
}
|
||||
cabana.EmitRecordSaved(ctx, app, tx, postSavedEvent(ctx, tx, before, post, body))
|
||||
for _, tag := range tags {
|
||||
cabana.EmitRecordSaved(ctx, app, tx, tagSavedEvent(ctx, &tag))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user