Wed, 21 Aug 2019 16:34:07 +0200
Updated README.design
257
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | <?php |
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | |
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | require_once('config.php'); |
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
5 | $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
6 | $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
7 | |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
8 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
9 | if (! $connect) { |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
10 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
11 | } |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
12 | mysqli_set_charset($connect, "utf8" ); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
13 | syslog(LOG_NOTICE, "crontasks.php started"); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
14 | |
356
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
15 | |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
16 | |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
17 | /* |
419
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
18 | * Upgrade package values. |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
19 | */ |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
20 | $query = "UPDATE products SET package_volume = bottle_amount + keg_amount WHERE package_volume='0';"; |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
21 | $result = mysqli_query($connect, $query); |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
22 | $changed = mysqli_affected_rows($connect); |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
23 | if ($changed > 0) { |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
24 | syslog(LOG_NOTICE, "Updated ".$changed." products to new package_volume value"); |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
25 | } |
422
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
26 | $query = "UPDATE products SET bottle_priming_water = bottle_amount * bottle_priming_amount / 500 WHERE bottle_priming_water = 0;"; |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
27 | $result = mysqli_query($connect, $query); |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
28 | $changed = mysqli_affected_rows($connect); |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
29 | if ($changed > 0) { |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
30 | syslog(LOG_NOTICE, "Updated ".$changed." products to new package_volume value"); |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
31 | } |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
32 | $query = "UPDATE products SET keg_priming_water = keg_amount * keg_priming_amount / 500 WHERE keg_priming_water = 0;"; |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
33 | $result = mysqli_query($connect, $query); |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
34 | $changed = mysqli_affected_rows($connect); |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
35 | if ($changed > 0) { |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
36 | syslog(LOG_NOTICE, "Updated ".$changed." products to new package_volume value"); |
7943afc0fcde
Added cron upgrade tasks to initialize the priming_water amounts. Fixed these to be a float instead of integer.
Michiel Broek <mbroek@mbse.eu>
parents:
419
diff
changeset
|
37 | } |
419
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
38 | |
99a7f2a6976e
Added packaging volume and add water or liquer to the beer after fermentation. Auto divide changing volumes between bottles and fusts. Upgrade the database in the crontask. Added these fields to the packaging tab screen.
Michiel Broek <mbroek@mbse.eu>
parents:
393
diff
changeset
|
39 | /* |
356
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
40 | * Upgrade inventory_reduced value from old boolean to tiny integer value. |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
41 | */ |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
42 | $query = "UPDATE products SET inventory_reduced=stage WHERE inventory_reduced = 1"; |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
43 | $result = mysqli_query($connect, $query); |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
44 | $changed = mysqli_affected_rows($connect); |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
45 | if ($changed > 0) { |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
46 | syslog(LOG_NOTICE, "Updated ".$changed." products to new inventory_reduced value"); |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
47 | } |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
48 | |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
49 | |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
50 | |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
51 | /* |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
52 | * Update stages after packaging depending on the age. |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
53 | */ |
257
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | $query = "UPDATE products SET stage=7 WHERE stage = 6 AND DATEDIFF(CURDATE(), package_date) > 0"; |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
55 | $result = mysqli_query($connect, $query); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
56 | $changed = mysqli_affected_rows($connect); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
57 | if ($changed > 0) { |
354
2e372eeba04b
Better log messages in crontasks.php
Michiel Broek <mbroek@mbse.eu>
parents:
294
diff
changeset
|
58 | syslog(LOG_NOTICE, "Updated ".$changed." products to stage 7 (Carbonation)"); |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
59 | } |
257
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | |
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | $query = "UPDATE products SET stage=8 WHERE stage = 7 AND DATEDIFF(CURDATE(), package_date) > 13"; |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
62 | $result = mysqli_query($connect, $query); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
63 | $changed = mysqli_affected_rows($connect); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
64 | if ($changed > 0) { |
354
2e372eeba04b
Better log messages in crontasks.php
Michiel Broek <mbroek@mbse.eu>
parents:
294
diff
changeset
|
65 | syslog(LOG_NOTICE, "Updated ".$changed." products to stage 8 (Mature)"); |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
66 | } |
257
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | |
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | $query = "UPDATE products SET stage=9 WHERE stage = 8 AND DATEDIFF(CURDATE(), package_date) > 41"; |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
69 | $result = mysqli_query($connect, $query); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
70 | $changed = mysqli_affected_rows($connect); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
71 | if ($changed > 0) { |
354
2e372eeba04b
Better log messages in crontasks.php
Michiel Broek <mbroek@mbse.eu>
parents:
294
diff
changeset
|
72 | syslog(LOG_NOTICE, "Updated ".$changed." products to stage 9 (Taste)"); |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
73 | } |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
74 | |
257
62e294ab94f5
Version 0.0.6. Added a crontask that adjusts the stage of packaged beer depending on the days passed packaging
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | |
356
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
76 | /* |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
77 | * Check fementation logs. |
36c72e368948
Reduce inventory is now done in a cron job at moments when there are ingredients used. So the inventory should be uptodate at all times.
Michiel Broek <mbroek@mbse.eu>
parents:
354
diff
changeset
|
78 | */ |
294
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
79 | $query = "SELECT record,code,name,log_brew,log_fermentation FROM products;"; |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
80 | $result = mysqli_query($connect, $query); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
81 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
82 | $logfile = "log/fermentation/" . $row['code'] . " " . $row['name'] . ".log"; |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
83 | if (file_exists($logfile)) |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
84 | $ok = 1; |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
85 | else |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
86 | $ok = 0; |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
87 | if ($ok != $row['log_fermentation']) { |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
88 | $query = "UPDATE products SET log_fermentation='" . $ok . "' WHERE record='" . $row['record'] . "';"; |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
89 | syslog(LOG_NOTICE, $query); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
90 | $result1 = mysqli_query($connect, $query); |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
91 | } |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
92 | } |
1e09d1d102a8
Updated crontask to check for fermentation logs and update the products. Added initial brew log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
257
diff
changeset
|
93 |