{"action":"opened","issue":{"url":"https://api.github.com/repos/formmailer/SchedulePages/issues/10","repository_url":"https://api.github.com/repos/formmailer/SchedulePages","labels_url":"https://api.github.com/repos/formmailer/SchedulePages/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/formmailer/SchedulePages/issues/10/comments","events_url":"https://api.github.com/repos/formmailer/SchedulePages/issues/10/events","html_url":"https://github.com/formmailer/SchedulePages/issues/10","id":142325672,"number":10,"title":"Issue with clicking \"Publish\" when the publish_from is filled","user":{"login":"somatonic","id":370148,"avatar_url":"https://avatars.githubusercontent.com/u/370148?v=3","gravatar_id":"","url":"https://api.github.com/users/somatonic","html_url":"https://github.com/somatonic","followers_url":"https://api.github.com/users/somatonic/followers","following_url":"https://api.github.com/users/somatonic/following{/other_user}","gists_url":"https://api.github.com/users/somatonic/gists{/gist_id}","starred_url":"https://api.github.com/users/somatonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/somatonic/subscriptions","organizations_url":"https://api.github.com/users/somatonic/orgs","repos_url":"https://api.github.com/users/somatonic/repos","events_url":"https://api.github.com/users/somatonic/events{/privacy}","received_events_url":"https://api.github.com/users/somatonic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-21T11:53:58Z","updated_at":"2016-03-21T11:53:58Z","closed_at":null,"body":"The latest pull request with the beforeSave hook to clear publish_from clearing when unpublishing is buggy. If I fill in the date and hit \"Publish\" it also clears the publish from field and shows 2 error message which makes no sense.\r\n\r\nA quick debug shows that the beforeSave hook from Michael is getting called 2 times, cause you already have a afterSave hook that changes the page to unpublished and saves the page, thus the beforeSave hook gets called again, which results in the wrong behaviour.\r\n\r\nWhen I add a flag to skip any further saves from the beforeSave hook it works again as it should and the published_from field doesn't get cleared.\r\n\r\nMy change:\r\n\r\n```\r\npublic function beforeSave($event) {\r\n\t\t$page = $event->arguments[0];\r\n\r\n\t\t// Clear the publish_from field automatically when the page is manually\r\n\t\t// unpublished. This prevents the page from being unintentionally\r\n\t\t// re-published on the next cron run.\r\n\t\t\r\n\t\t// prevent this hook being run two times\r\n\t\tif($page->schedulerSkip) return;\r\n\t\t\r\n\t\t// wire(\"log\")->save(\"scheduler-debug\", \"status: $page->status\"); // debug to see\r\n\r\n\t\tif ($page->isChanged('status') && $page->is(Page::statusUnpublished) && $page->publish_from) {\r\n\t\t\t$this->session->error($this->_(\"“Publish From Date” field was cleared to prevent the page from being unintentionally re-published on the next Lazy Cron run.\"));\r\n\t\t\t$page->publish_from = null;\r\n\t\t\t$page->save('publish_from');\r\n\t\t}\r\n\t\t\r\n\t\t// set flag to prevent multiple runs\r\n\t\t$page->schedulerSkip = true;\r\n\t}\r\n````\r\n"}}