From 5ca959fa688255a8de61f89fe2751eb4d24a6912 Mon Sep 17 00:00:00 2001
From: Florian Schaal <florian@schaal-24.de>
Date: Tue, 22 Mar 2016 09:22:07 -0400
Subject: [PATCH] fixed typo

---
 server/lib/classes/cronjob.inc.php |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/server/lib/classes/cronjob.inc.php b/server/lib/classes/cronjob.inc.php
index 7fe90c2..02f4f46 100644
--- a/server/lib/classes/cronjob.inc.php
+++ b/server/lib/classes/cronjob.inc.php
@@ -47,7 +47,30 @@
 
 
 	public function getSchedule() {
-		return $this->_schedule;
+		global $app, $conf;
+		
+		$class = get_class($this);
+		
+		switch ($class) {
+			case 'cronjob_backup':
+				$app->uses('ini_parser,getconf');
+				$server_id = $conf['server_id'];
+				$server_conf = $app->getconf->get_server_config($server_id, 'server');
+				if(isset($server_conf['backup_time']) && $server_conf['backup_time'] != ''){
+					list($hour, $minute) = explode(':', $server_conf['backup_time']);
+					$schedule = $minute.' '.$hour.' * * *';
+				} else {
+					$schedule = '0 0 * * *';
+				}
+				break;
+			/*case 'cronjob_backup_mail':
+				$schedule = '1 0 * * *';
+				break;*/
+			default:
+				$schedule = $this->_schedule;
+		}
+		
+		return $schedule;
 	}
 
 
@@ -56,7 +79,7 @@
 	public function run() {
 
 		print "Called run() for class " . get_class($this) . "\n";
-		print "Job has schedule: " . $this->_schedule . "\n";
+		print "Job has schedule: " . $this->getSchedule() . "\n";
 		$this->onPrepare();
 		$run_it = $this->onBeforeRun();
 		if($run_it == true) {
@@ -76,7 +99,7 @@
 		// check the run time and values for this job
 
 		// get previous run data
-		$data = $app->db->queryOneRecord("SELECT `last_run`, `next_run`, `running` FROM `sys_cron` WHERE `name` = '" . $app->db->quote(get_class($this)) . "'");
+		$data = $app->db->queryOneRecord("SELECT `last_run`, `next_run`, `running` FROM `sys_cron` WHERE `name` = ?", get_class($this));
 		if($data) {
 			if($data['last_run']) $this->_last_run = $data['last_run'];
 			if($data['next_run']) $this->_next_run = $data['next_run'];
@@ -86,11 +109,11 @@
 			if($this->_run_at_new == true) {
 				$this->_next_run = ISPConfigDateTime::dbtime(); // run now.
 			} else {
-				$app->cron->parseCronLine($this->_schedule);
+				$app->cron->parseCronLine($this->getSchedule());
 				$next_run = $app->cron->getNextRun(ISPConfigDateTime::dbtime());
 				$this->_next_run = $next_run;
 
-				$app->db->query("REPLACE INTO `sys_cron` (`name`, `last_run`, `next_run`, `running`) VALUES ('" . $app->db->quote(get_class($this)) . "', " . ($this->_last_run ? "'" . $app->db->quote($this->_last_run) . "'" : "NULL") . ", " . ($next_run === false ? "NULL" : "'" . $app->db->quote($next_run) . "'") . ", " . ($this->_running == true ? "1" : "0") . ")");
+				$app->db->query("REPLACE INTO `sys_cron` (`name`, `last_run`, `next_run`, `running`) VALUES (?, ?, ?, ?)", get_class($this), ($this->_last_run ? $this->_last_run : "#NULL#"), ($next_run === false ? "#NULL#" : $next_run . "'"), ($this->_running == true ? "1" : "0"));
 			}
 		}
 	}
@@ -116,7 +139,7 @@
 		// next_run time reached (reached === 0 or -1)
 
 		// calculare next run time based on last_run or current time
-		$app->cron->parseCronLine($this->_schedule);
+		$app->cron->parseCronLine($this->getSchedule());
 		if($this->_no_skip == true) {
 			// we need to calculare the next run based on the previous next_run, as we may not skip one.
 			$next_run = $app->cron->getNextRun($this->_next_run);
@@ -131,7 +154,7 @@
 
 		print "Jobs next run is now " . $next_run . "\n";
 
-		$app->db->query("REPLACE INTO `sys_cron` (`name`, `last_run`, `next_run`, `running`) VALUES ('" . $app->db->quote(get_class($this)) . "', NOW(), " . ($next_run === false ? "NULL" : "'" . $app->db->quote($next_run) . "'") . ", 1)");
+		$app->db->query("REPLACE INTO `sys_cron` (`name`, `last_run`, `next_run`, `running`) VALUES (?, NOW(), ?, 1)", get_class($this), ($next_run === false ? "#NULL#" : $next_run));
 		return true;
 	}
 
@@ -154,7 +177,7 @@
 		global $app;
 
 		print "Called onCompleted() for class " . get_class($this) . "\n";
-		$app->db->query("UPDATE `sys_cron` SET `running` = 0 WHERE `name` = '" . $app->db->quote(get_class($this)) . "'");
+		$app->db->query("UPDATE `sys_cron` SET `running` = 0 WHERE `name` = ?", get_class($this));
 	}
 
 }

--
Gitblit v1.9.1