forked from ndlibersa/usage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsushiSchedule.php
88 lines (61 loc) · 2.63 KB
/
sushiSchedule.php
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
<?php
/*
**************************************************************************************************************************
** CORAL Usage Statistics v. 1.1
**
** Copyright (c) 2010 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
**
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/
session_start();
include_once 'directory.php';
$util = new Utility();
$config = new Configuration();
// find sushi services which need to be run today
$day = date("j");
$sushiServices = new SushiService();
$sushiServicesArray = $sushiServices->getByDayOfMonth($day);
$emailLog = "<h2>" . count($sushiServicesArray) . " SUSHI runs found for day: " . $day . "</h2>";
foreach ($sushiServicesArray as $sushiService){
$sushiService->setImportDates();
$emailLog .= "<h3>" . $sushiService->getServiceProvider() . "</h3>";
//try to run!
try {
$emailLog .= nl2br($sushiService->runAll($_POST['overwritePlatform']));
} catch (Exception $e) {
$emailLog .= nl2br($e->getMessage());
}
}
//if more than one run, send email
if (count($sushiServicesArray) > 0) {
$emailLog .= "<br /><br />Log in to <a href='" . $util->getPageURL() . "sushi.php'>Sushi Administration</a> for more information.";
//send email to email addresses listed in DB
$logEmailAddress = new LogEmailAddress();
$emailAddresses = array();
foreach ($logEmailAddress->allAsArray() as $emailAddress){
$emailAddresses[] = $emailAddress['emailAddress'];
}
if (count($emailAddresses) > 0){
$email = new Email();
$email->to = implode(", ", $emailAddresses);
$email->subject = "SUSHI Scheduled run log for " . format_date(date) . " - " . count($sushiServicesArray) . " runs";
$email->message = $emailLog;
if ($email->send()) {
echo "Run complete. Log has been emailed to " . implode(", ", $emailAddresses);
}else{
echo "Email to " . implode(", ", $emailAddresses) . " Failed!";
}
}
}else{
echo "Nothing to see here! (no sushi scheduled today)";
}
echo "<br /><br />" . $emailLog;
?>