forked from artursudnik/webpagetest-monitor
/
updateJob.php
96 lines (88 loc) · 2.94 KB
/
updateJob.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
85
86
87
88
89
90
91
92
93
94
95
96
<?php
require("login/login.php");
include 'monitor.inc';
$userId = getCurrentUserId();
$id = $_REQUEST['id'];
if ($id){
$folderId = getFolderIdFor($id, 'WPTJob');
} else {
$folderId = $_REQUEST['folderId'];
}
if ($_REQUEST['active']) {
$active = 1;
} else {
$active = 0;
}
$label = $_REQUEST['label'];
$description = $_REQUEST['description'];
$location = $_REQUEST['location'];
$script = $_REQUEST['script'];
$alerts = $_REQUEST['alerts'];
// Extract host and location from $location field
$hostloc = explode(" ", $location);
$host = $hostloc[0];
$location = $hostloc[1];
$frequency = $_REQUEST['frequency'];
$maxDownloadAttempts = $_REQUEST['maxdownloadattempts'];
$numberOfRuns = $_REQUEST['numberofruns'];
$runToUserForAverage = $_REQUEST['runtouseforaverage'];
if ($runToUserForAverage > $numberOfRuns) {
$smarty->assign('errorMessage', "Run to use for average must be equal to or less than number of runs.");
$smarty->display('error.tpl');
exit;
}
$video = $_REQUEST['video'];
$firstviewonly = $_REQUEST['firstviewonly'];
$downloadresultxml = $_REQUEST['downloadresultxml'];
$downloaddetails = $_REQUEST['downloaddetails'];
try
{
if ($id) {
$q = Doctrine_Query::create()->from('WPTJob j')->where('j.Id= ?', $id);
$wptJob = $q->fetchOne();
$q->free(true);
} else {
$wptJob = new WPTJob();
$wptJob['UserId'] = $userId;
}
$wptJob['Active'] = $active;
$wptJob['WPTJobFolderId'] = $folderId;
$wptJob['Label'] = $label;
$wptJob['Host'] = $host;
$wptJob['Location'] = $location;
$wptJob['Description'] = $description;
$wptJob['WPTScriptId'] = $script;
$wptJob['FirstViewOnly'] = $firstviewonly;
$wptJob['Video'] = $video;
$wptJob['DownloadResultXml'] = $downloadresultxml;
$wptJob['DownloadDetails'] = $downloaddetails;
$wptJob['MaxDownloadAttempts'] = $maxDownloadAttempts;
$wptJob['Runs'] = $numberOfRuns;
$wptJob['RunToUseForAverage'] = $runToUserForAverage;
$wptJob['Frequency'] = $frequency;
$wptJob['WPTBandwidthDown'] = $_REQUEST['bandwidthDown'];
$wptJob['WPTBandwidthUp'] = $_REQUEST['bandwidthUp'];
$wptJob['WPTBandwidthLatency'] = $_REQUEST['bandwidthLatency'];
$wptJob['WPTBandwidthPacketLoss'] = $_REQUEST['bandwidthPacketLoss'];
$wptJob->save();
// Update Alerts
// Remove old links
$q = Doctrine_Query::create()->delete('WPTJob_Alert a')->where('a.WPTJobId= ?', $id);
$jobAlerts = $q->execute();
$q->free(true);
// Add update links
if ($alerts) {
foreach ($alerts as $alert) {
echo "id: ".$id." alert: ".$alert;
$link = new WPTJob_Alert();
$link['WPTJobId'] = $id;
$link['AlertId'] = $alert;
$link->save();
}
}
} catch (Exception $e) {
error_log("[WPTMonitor] Failed while updating job: for " . $userId . " message: " . $e->getMessage());
}
header("Location: listJobs.php");
exit;
?>