-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatchevent.php
More file actions
125 lines (121 loc) · 3.4 KB
/
batchevent.php
File metadata and controls
125 lines (121 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
//Run this daily after midnight using chron
//Processes out of office and seasonal events
//connect to DB
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lulashop";
// Connect to the database
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
die();
}
$today = date_create(null, new DateTimeZone('UTC'));
//seasonal
//Check if a season starts today and make matching patterns visible
$sql = "SELECT `sku`
FROM `event`,`inventory`
WHERE `event`.`memberID`=`inventory`.`memberID`
AND `event`.`category`='season'
AND `event`.`start` LIKE CONCAT(CURRENT_DATE,'%')
AND `inventory`.`pattern` LIKE CONCAT('%',`event`.`season`,'%')";
try {
$pdo = $conn->query($sql);
} catch(PDOException $e) {
echo "find seasonal event statement failed: " . $e->getMessage();
die();
}
// TODO: change to prepared statement
while ($seasonal = $pdo->fetchColumn()){
$sql = "
UPDATE `inventory`
SET `visible`=1
WHERE `sku`=$seasonal";
try {
$conn->exec($sql);
} catch(PDOException $e) {
echo "season make visible statement failed: " . $e->getMessage();
die();
}
}
echo "season make visible statement succeded\n";
//Check if a season ends today and hide matching patterns
$sql = "SELECT `sku`
FROM `event`,`inventory`
WHERE `event`.`memberID`=`inventory`.`memberID`
AND `event`.`category`='season'
AND `event`.`end` LIKE CONCAT(CURRENT_DATE,'%')
AND `inventory`.`pattern` LIKE CONCAT('%',`event`.`season`,'%')";
try {
$pdo = $conn->query($sql);
} catch(PDOException $e) {
echo "find seasonal event statement failed: " . $e->getMessage();
die();
}
while ($seasonal = $pdo->fetchColumn()){
$sql = "
UPDATE `inventory`
SET `visible`=0
WHERE `sku`=$seasonal";
try {
$conn->exec($sql);
} catch(PDOException $e) {
echo "season make visible statement failed: " . $e->getMessage();
die();
}
}
echo "season hide statement succeded\n";
// Check if an out of office event starts today and hide all inventory
$sql =
"SELECT `sku`
FROM `inventory`,`event`
WHERE `event`.`start` LIKE CONCAT(CURRENT_DATE,'%')
AND `event`.`category`='outofoffice'
AND `inventory`.`memberID`=`event`.`memberID`";
try {
$pdo = $conn->query($sql);
} catch(PDOException $e) {
echo "find seasonal event statement failed: " . $e->getMessage();
die();
}
while($outofoffice = $pdo->fetchColumn()){
$sql =
"UPDATE `inventory`
SET `visible`=0
WHERE `sku`=$outofoffice";
try {
$conn->exec($sql);
} catch(PDOException $e) {
echo "out of office hide statement failed: " . $e->getMessage();
die();
}
}
echo "out of office hide statement succeded\n";
// Check if an out of office event ends today and make visible all inventory that is not still hidden by a season event
$sql ="SELECT * FROM `outofoffice_show`";
try {
$pdo = $conn->query($sql);
} catch(PDOException $e) {
echo "find out of office statement failed: " . $e->getMessage();
die();
}
while($outofoffice = $pdo->fetchColumn()){
$sql =
"UPDATE `inventory`
SET `visible`=1
WHERE `sku`=$outofoffice";
try {
$conn->exec($sql);
} catch(PDOException $e) {
echo "out of office make visible statement failed: " . $e->getMessage();
die();
}
}
echo "out of office make visible statement succeded\n";
$conn = null;
?>