From 16daff6abd1a60159e6b56d3c18ec398ad5debc5 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Mon, 8 May 2017 22:20:53 +0200 Subject: [PATCH] improves on dbpages --- bl-kernel/dbpages.class.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index c52ca8fa..c24f3c1d 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -353,6 +353,39 @@ class dbPages extends dbJSON return $count - 1; } + // Return TRUE if there are new pages published, FALSE otherwise. + public function scheduler() + { + // Get current date + $currentDate = Date::current(DB_DATE_FORMAT); + $saveDatabase = false; + + foreach($this->db as $postKey=>$values) { + if($values['status']=='scheduled') { + if($values['date']<=$currentDate) { + $this->db[$postKey]['status'] = 'published'; + $saveDatabase = true; + } + } + elseif($values['status']=='published') { + break; + } + } + + if($saveDatabase) { + if( $this->save() === false ) { + Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.'); + return false; + } + + Log::set(__METHOD__.LOG_SEP.'New posts published from the scheduler.'); + return true; + } + + return false; + } + +// --- OLD public function cliMode() { // LOG