From b2189fd8a17d28184d639347296f30757f52a9a0 Mon Sep 17 00:00:00 2001 From: Franzz Date: Fri, 10 Apr 2020 09:14:59 +0200 Subject: [PATCH] Generate Cron File --- .gitignore | 1 + inc/feed.php | 9 +++++++-- inc/spot.php | 10 +++++++++- index.php | 3 +++ script/spot.js | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 840062d..43d98e4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /files/**/*.mov /files/**/*.MOV /geo/*.geojson +/spot_cron.sh diff --git a/inc/feed.php b/inc/feed.php index 9b45bcd..567256f 100644 --- a/inc/feed.php +++ b/inc/feed.php @@ -101,8 +101,13 @@ class Feed extends PhpObject { } public function checkUpdateFeed($sProjectMode) { - //Feed updated once every hour in Blog Mode - if($sProjectMode == Project::MODE_BLOG && date('Y-m-d-H', $this->iLastUpdate) != date('Y-m-d-H')) $this->updateFeed(); + //Feed updated once every hour in Blog Mode (no need for timezone when substracting 2 dates) + if($sProjectMode == Project::MODE_BLOG) { + $oLastUpdate = new DateTime('@'.$this->iLastUpdate); + $oNow = new DateTime('now'); + + if(intval($oNow->diff($oLastUpdate)->format('%H')) > 0) $this->updateFeed(); + } } private function updateFeed() { diff --git a/inc/spot.php b/inc/spot.php index e31f2be..4d0b39f 100755 --- a/inc/spot.php +++ b/inc/spot.php @@ -140,7 +140,9 @@ class Spot extends Main ), 'consts' => array( 'geo_server' => Settings::GEO_SERVER, - 'modes' => Project::MODES ) + 'modes' => Project::MODES, + 'default_timezone' => Settings::TIMEZONE + ) ), 'index', array( @@ -169,6 +171,12 @@ class Spot extends Main } } + public function genCronFile() { + //$bResult = (file_put_contents('spot_cron.sh', '#!/bin/bash'."\n".'cd '.dirname($_SERVER['SCRIPT_FILENAME'])."\n".'php -f index.php a=update_feed')!==false); + $bResult = (file_put_contents('spot_cron.sh', '#!/bin/bash'."\n".'wget -qO- '.$this->asContext['serv_name'].'index.php?a=dummy > /dev/null')!==false); + return $bResult?self::SUCCESS:self::ERROR; + } + public function getMarkers() { $asMessages = $this->getSpotMessages(); diff --git a/index.php b/index.php index 9e17a7f..497b7de 100755 --- a/index.php +++ b/index.php @@ -75,6 +75,9 @@ if($sAction!='') case 'unsubscribe_email': $sResult = $oSpot->unsubscribeFromEmail($iId); break; + case 'generate_cron': + $sResult = $oSpot->genCronFile(); + break; default: $sResult = Main::getJsonResult(false, Main::NOT_FOUND); } diff --git a/script/spot.js b/script/spot.js index bc00735..e535da3 100755 --- a/script/spot.js +++ b/script/spot.js @@ -5,7 +5,7 @@ function Spot(asGlobals) this.consts.hash_sep = '-'; this.consts.title = 'Spotty'; this.consts.default_page = 'project'; - this.consts.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + this.consts.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || this.consts.default_timezone; /* Initialization */