www/crontasks.php

Sat, 25 Sep 2021 10:42:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 25 Sep 2021 10:42:54 +0200
changeset 778
e64fd38c469c
parent 615
9034e65b0d7a
permissions
-rw-r--r--

If during styles import the CATEGORY_NUMBER is empty, insert 0 in the database instead.

<?php

require_once('config.php');

$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");

$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
if (! $connect) {
	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
mysqli_set_charset($connect, "utf8" );
syslog(LOG_NOTICE, "crontasks.php started");



/*
 * Upgrade package values.
 */
$query = "UPDATE products SET package_volume = bottle_amount + keg_amount WHERE package_volume='0';";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
        syslog(LOG_NOTICE, "Updated ".$changed." products to new package_volume value");
}
$query = "UPDATE products SET bottle_priming_water = bottle_amount * bottle_priming_amount / 500 WHERE bottle_priming_water = 0;";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
        syslog(LOG_NOTICE, "Updated ".$changed." products to new package_volume value");
}
$query = "UPDATE products SET keg_priming_water = keg_amount * keg_priming_amount / 500 WHERE keg_priming_water = 0;";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
        syslog(LOG_NOTICE, "Updated ".$changed." products to new package_volume value");
}

/*
 * Upgrade inventory_reduced value from old boolean to tiny integer value.
 */
$query = "UPDATE products SET inventory_reduced=stage WHERE inventory_reduced = 1";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
        syslog(LOG_NOTICE, "Updated ".$changed." products to new inventory_reduced value");
}



/*
 * Update stages after packaging depending on the age.
 */
$query = "UPDATE products SET stage=7 WHERE stage = 6 AND DATEDIFF(CURDATE(), package_date) > 0";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
	syslog(LOG_NOTICE, "Updated ".$changed." products to stage 7 (Carbonation)");
}

$query = "UPDATE products SET stage=8 WHERE stage = 7 AND DATEDIFF(CURDATE(), package_date) > 13";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
	syslog(LOG_NOTICE, "Updated ".$changed." products to stage 8 (Mature)");
}

$query = "UPDATE products SET stage=9 WHERE stage = 8 AND DATEDIFF(CURDATE(), package_date) > 41";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
	syslog(LOG_NOTICE, "Updated ".$changed." products to stage 9 (Taste)");
}


/*
 * Check several logs.
 */
$query = "SELECT record,code,name,log_brew,log_fermentation,log_ispindel,log_co2pressure FROM products;";
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
	$logfile = "log/fermentation/" . $row['code'] . " " . $row['name'] . ".log";
	if (file_exists($logfile))
		$ok = 1;
	else
		$ok = 0;
	if ($ok != $row['log_fermentation']) {
		$query = "UPDATE products SET log_fermentation='" . $ok . "' WHERE record='" . $row['record'] . "';";
		syslog(LOG_NOTICE, $query);
		$result1 = mysqli_query($connect, $query);
	}
	$logfile = "log/ispindel/" . $row['code'] . " " . $row['name'] . ".log";
	if (file_exists($logfile))
                $ok = 1;
        else
                $ok = 0;
        if ($ok != $row['log_ispindel']) {
                $query = "UPDATE products SET log_ispindel='" . $ok . "' WHERE record='" . $row['record'] . "';";
                syslog(LOG_NOTICE, $query);
                $result1 = mysqli_query($connect, $query);
        }
	$logfile = "log/co2pressure/" . $row['code'] . " " . $row['name'] . ".log";
        if (file_exists($logfile))
                $ok = 1;
        else
                $ok = 0;
        if ($ok != $row['log_co2pressure']) {
                $query = "UPDATE products SET log_co2pressure='" . $ok . "' WHERE record='" . $row['record'] . "';";
                syslog(LOG_NOTICE, $query);
                $result1 = mysqli_query($connect, $query);
        }
}


/*
 * Check and update secondary_end_sg
 */
$query = "UPDATE products SET secondary_end_sg=fg WHERE stage > 5 AND secondary_end_sg='0';";
$result = mysqli_query($connect, $query);
$changed = mysqli_affected_rows($connect);
if ($changed > 0) {
        syslog(LOG_NOTICE, "Updated ".$changed." products with new secondary_end_sg value");
}

mercurial