silverstripe-australia/advancedworkflow — pull request #81 by sminnee (2013-01-31 05:14:52+00:00)
Title: Don't create bad QueuedJobs when saving new records

See #80 for context.

Basically, QueuedJobs can't be created unless we have the page ID. So if you try and create one in onBeforeWrite, you can't do so for the first write of an object.

This fix is a simple if block and an adjustment to the test that notes the limitation: you have to write the object twice, if you set PublishOnDate and UnPublishOnDate on a brand new object.

In practise, I don't think the CMS will ever let users set PublishOnDate on an object fresh to the DB - it's quite trigger-happy on writes. So I think this should be okay. But it would be good to get @nyeholt to confirm that.