From 65301b91dc2f0bbba3ec060b3090106a1daa445c Mon Sep 17 00:00:00 2001 From: James Cocker Date: Thu, 12 Jun 2014 18:55:40 +0100 Subject: [PATCH 1/2] Update the PublishDate on first Publish If the PublishDate hasn't been set to the future. --- model/BlogPost.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/model/BlogPost.php b/model/BlogPost.php index 0b82fa1..bed684f 100755 --- a/model/BlogPost.php +++ b/model/BlogPost.php @@ -106,6 +106,18 @@ class BlogPost extends Page { + /** + * Update the PublishDate to now, if being published for the first time, and the date hasn't been set to the future. + **/ + public function onBeforePublish() { + if ($this->owner->obj('PublishDate')->InPast() && !$this->owner->isPublished()) { + $this->owner->setCastedField("PublishDate", time()); + $this->owner->write(); + } + } + + + /** * Checks the publish date to see if the blog post has actually been published. * From c7541e2d17bfac3ac7b788aad30e800e05e28d55 Mon Sep 17 00:00:00 2001 From: James Cocker Date: Fri, 13 Jun 2014 11:45:28 +0100 Subject: [PATCH 2/2] BlogPost: onBeforePublish: Removed owner + added 'dbObject' --- model/BlogPost.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/model/BlogPost.php b/model/BlogPost.php index bed684f..3328324 100755 --- a/model/BlogPost.php +++ b/model/BlogPost.php @@ -110,9 +110,9 @@ class BlogPost extends Page { * Update the PublishDate to now, if being published for the first time, and the date hasn't been set to the future. **/ public function onBeforePublish() { - if ($this->owner->obj('PublishDate')->InPast() && !$this->owner->isPublished()) { - $this->owner->setCastedField("PublishDate", time()); - $this->owner->write(); + if ($this->dbObject('PublishDate')->InPast() && !$this->isPublished()) { + $this->setCastedField("PublishDate", time()); + $this->write(); } }