mirror of https://github.com/jlelse/GoBlog
Trigger post instead of update hook when scheduled post get's published
This commit is contained in:
parent
2bb3f760a0
commit
4b9440443b
|
@ -180,7 +180,7 @@ func (a *goBlog) createOrReplacePost(p *post, o *postCreationOptions) error {
|
||||||
}
|
}
|
||||||
// Trigger hooks
|
// Trigger hooks
|
||||||
if p.Status == statusPublished && (p.Visibility == visibilityPublic || p.Visibility == visibilityUnlisted) {
|
if p.Status == statusPublished && (p.Visibility == visibilityPublic || p.Visibility == visibilityUnlisted) {
|
||||||
if o.new || (o.oldStatus != statusPublished && o.oldVisibility != visibilityPublic && o.oldVisibility != visibilityUnlisted) {
|
if o.new || o.oldStatus == statusScheduled || (o.oldStatus != statusPublished && o.oldVisibility != visibilityPublic && o.oldVisibility != visibilityUnlisted) {
|
||||||
defer a.postPostHooks(p)
|
defer a.postPostHooks(p)
|
||||||
} else {
|
} else {
|
||||||
defer a.postUpdateHooks(p)
|
defer a.postUpdateHooks(p)
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
|
|
||||||
func Test_postsScheduler(t *testing.T) {
|
func Test_postsScheduler(t *testing.T) {
|
||||||
|
|
||||||
|
updateHook, postHook := 0, 0
|
||||||
|
|
||||||
app := &goBlog{
|
app := &goBlog{
|
||||||
cfg: createDefaultTestConfig(t),
|
cfg: createDefaultTestConfig(t),
|
||||||
}
|
}
|
||||||
|
@ -21,6 +23,12 @@ func Test_postsScheduler(t *testing.T) {
|
||||||
Lang: "en",
|
Lang: "en",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
app.pPostHooks = append(app.pPostHooks, func(p *post) {
|
||||||
|
postHook++
|
||||||
|
})
|
||||||
|
app.pUpdateHooks = append(app.pUpdateHooks, func(p *post) {
|
||||||
|
updateHook++
|
||||||
|
})
|
||||||
|
|
||||||
_ = app.initConfig(false)
|
_ = app.initConfig(false)
|
||||||
_ = app.initCache()
|
_ = app.initCache()
|
||||||
|
@ -40,10 +48,16 @@ func Test_postsScheduler(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 1, count)
|
assert.Equal(t, 1, count)
|
||||||
|
|
||||||
|
assert.Equal(t, 0, postHook)
|
||||||
|
assert.Equal(t, 0, updateHook)
|
||||||
|
|
||||||
app.checkScheduledPosts()
|
app.checkScheduledPosts()
|
||||||
|
|
||||||
count, err = app.db.countPosts(&postsRequestConfig{status: []postStatus{statusScheduled}})
|
count, err = app.db.countPosts(&postsRequestConfig{status: []postStatus{statusScheduled}})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 0, count)
|
assert.Equal(t, 0, count)
|
||||||
|
|
||||||
|
assert.Equal(t, 1, postHook)
|
||||||
|
assert.Equal(t, 0, updateHook)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue