Initial cron support and fixes
This commit is contained in:
parent
613590e80d
commit
48531c01ab
|
@ -19,19 +19,21 @@ set_error_handler('customErrorHandler');
|
|||
|
||||
list($cronJobDay, $cronJobTime) = explode(";", $database->get_option("cron_job_time"));
|
||||
|
||||
$execDateTime = new stdClass();
|
||||
$execDateTime->day = date('d');
|
||||
$execDateTime->month = date('m');
|
||||
$execDateTime->year = date("Y");
|
||||
$execDateTime->hour = date('H');
|
||||
$execDateTime->minutes = date('i');
|
||||
$execDateTime = [
|
||||
"day" => date("d"),
|
||||
"month" => date("m"),
|
||||
"year" => date("Y"),
|
||||
"hour" => date("H"),
|
||||
"minutes" => date("i")
|
||||
];
|
||||
|
||||
$cronJobDateTime = new stdClass();
|
||||
$cronJobDateTime->day = $cronJobDay;
|
||||
$cronJobDateTime->month = date('m');
|
||||
$cronJobDateTime->year = date("Y");
|
||||
$cronJobDateTime->hour = explode(":", $cronJobTime)[0];
|
||||
$cronJobDateTime->minutes = explode(":", $cronJobTime)[1];
|
||||
$cronJobDateTime = [
|
||||
"day" => $cronJobDay,
|
||||
"month" => date("m"),
|
||||
"year" => date("Y"),
|
||||
"hour" => explode(":", $cronJobTime)[0],
|
||||
"minutes" => explode(":", $cronJobTime)[1]
|
||||
];
|
||||
|
||||
$start = $database->get_option("cron_job_enabled") && ((isset($_POST['cron']) && $_POST['cron'] == "cron_job-".$database->get_option("cron_job_code")) || (isset($_SERVER['HTTP_CRON']) && $_SERVER['HTTP_CRON'] == "cron_job-".$database->get_option("cron_job_code")));
|
||||
$start_reset = $execDateTime == $cronJobDateTime;
|
||||
|
@ -47,7 +49,7 @@ if($start) {
|
|||
foreach($profiles as $profile){
|
||||
$list[] = [$profile["id"] => $profile["availability_minutes"]];
|
||||
}
|
||||
$database->exec("INSERT INTO `%PREFIX%_minutes` (`id`, `month`, `year`, `list`) VALUES (NULL, :month, :year, :list)", false, [":month" => $execDateTime->month,":year" => $execDateTime->year,":list"=>json_encode($list)]);
|
||||
$database->exec("INSERT INTO `%PREFIX%_minutes` (`id`, `month`, `year`, `list`) VALUES (NULL, :month, :year, :list)", false, [":month" => $execDateTime["month"],":year" => $execDateTime["year"],":list"=>json_encode($list)]);
|
||||
$database->exec("UPDATE %PREFIX%_profiles SET availability_minutes = 0");
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +76,57 @@ if($start) {
|
|||
$output = ["profiles array empty"];
|
||||
$output_status = "ok";
|
||||
}
|
||||
|
||||
$result = $database->exec("SELECT * FROM `%PREFIX%_schedules`;", true);
|
||||
$schedules_check = [];
|
||||
$schedules_check["schedules"] = [];
|
||||
if(!empty($result)){
|
||||
foreach ($result as $key => $value) {
|
||||
$result[$key]["schedules"] = json_decode($result[$key]["schedules"]);
|
||||
}
|
||||
$schedules_check["table"] = $result;
|
||||
foreach ($result as $key => $row) {
|
||||
$last_exec = $row["last_exec"];
|
||||
$last_exec = [
|
||||
"day" => (int) explode(";",$row["last_exec"])[0],
|
||||
"hour" => (int) explode(":",explode(";",$row["last_exec"])[1])[0],
|
||||
"minutes" => (int) explode(":",$row["last_exec"])[1]
|
||||
];
|
||||
$id = $row["id"];
|
||||
$user_id = $row["user"];
|
||||
foreach ($row["schedules"] as $key => $value) {
|
||||
$schedule = [
|
||||
"day" => (int) $value[0]+1,
|
||||
"hour" => (int) explode(":",$value[1])[0],
|
||||
"minutes" => (int) explode(":",$value[1])[1]
|
||||
];
|
||||
$now = [
|
||||
"day" => (int) date("N"),
|
||||
"hour" => (int) date("H"),
|
||||
"minutes" => (int) date("i")
|
||||
];
|
||||
|
||||
if(
|
||||
$schedule["day"] == $now["day"] &&
|
||||
$schedule["hour"] == $now["hour"] &&
|
||||
$schedule["minutes"] <= $now["minutes"] &&
|
||||
$now["minutes"] - $schedule["minutes"] <= 30 &&
|
||||
$schedule["minutes"] !== $last_exec["minutes"]
|
||||
){
|
||||
$last_exec_new = $schedule["day"].";".sprintf("%02d", $schedule["hour"]).":".sprintf("%02d", $schedule["minutes"]);
|
||||
$database->exec("UPDATE `%PREFIX%_schedules` SET `last_exec` = :last_exec WHERE `id` = :id;", false, [":id" => $id, ":last_exec" => $last_exec_new]);
|
||||
$database->exec("UPDATE `%PREFIX%_profiles` SET `available` = '1' WHERE `id` = :user_id;", false, [":user_id" => $user_id]);
|
||||
$schedules_check["schedules"][] = [
|
||||
"schedule" => $schedule,
|
||||
"now" => $now,
|
||||
"exec" => $last_exec,
|
||||
"last_exec_new" => $last_exec_new,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo(json_encode(
|
||||
|
@ -83,6 +136,7 @@ echo(json_encode(
|
|||
"execDateTime" => $execDateTime,
|
||||
"cronJobDateTime" => $cronJobDateTime,
|
||||
"action" => $action,
|
||||
"schedules_check" => $schedules_check,
|
||||
"output" => [
|
||||
"status" => $output_status,
|
||||
"message" => $output
|
||||
|
|
|
@ -423,8 +423,8 @@ CREATE TABLE `".$prefix."_schedules` (
|
|||
`user` INT NOT NULL,
|
||||
`profile_name` VARCHAR(500) NOT NULL DEFAULT 'default',
|
||||
`schedules` VARCHAR(1000) NULL DEFAULT NULL,
|
||||
`last_exec` VARCHAR(5) NULL DEFAULT NULL,
|
||||
`last_update` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`last_exec` VARCHAR(7) NULL DEFAULT NULL,
|
||||
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
) ENGINE = InnoDB;
|
||||
INSERT INTO `".$prefix."_dbversion` (`version`, `timestamp`) VALUES('1', current_timestamp());"
|
||||
|
|
|
@ -207,6 +207,7 @@ function extractSelections(){
|
|||
$("#scheduler_body td.highlighted").each((key, value) => {
|
||||
let day = value.classList[1].replace("day-","");
|
||||
let hour = value.classList[2].replace("hour-","").replace("-",":");
|
||||
if(hour.length < 5) hour = "0" + hour;
|
||||
console.log(day,hour,value);
|
||||
hours_list.push([day,hour]);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue