forked from forceworkbench/forceworkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncStatus.php
More file actions
162 lines (137 loc) · 7.71 KB
/
Copy pathasyncStatus.php
File metadata and controls
162 lines (137 loc) · 7.71 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
require_once 'session.php';
require_once 'shared.php';
require_once 'header.php';
print "<p/>";
if (!isset($_GET['jobId']) || $_GET['jobId'] == "") {
displayInfo("Parameter 'jobId' must be specified.",false,false);
print "<p/>" .
"<form action='' method='GET'>" .
"Job Id: <input type='text' name='jobId'/> " .
"<input type='submit' value='Get Status'/>".
"</form>";
include_once 'footer.php';
exit;
}
$_GET['jobId'] = htmlspecialchars(trim($_GET['jobId']));
try {
$asyncConnection = WorkbenchContext::get()->getAsyncBulkConnection();
$jobInfo = $asyncConnection->getJobInfo($_GET['jobId']);
$batchInfos = $asyncConnection->getBatchInfos($_GET['jobId']);
} catch (Exception $e) {
displayError($e->getMessage(), false, false);
if (stripos($e->getMessage(), 'InvalidVersion') > -1) {
print "<p/><em>Quick Fix: <a href='sessionInfo.php' target='_blank'>Change API Version</a></em>";
}
include_once 'footer.php';
exit;
}
print "<p class='instructions'>A job has been uploaded to Salesforce via the Bulk API and is being processed asynchronously as resources are available. " .
"Refresh this page periodically to view the latest status. Results can be downloaded when batches are complete.</p><p/>";
foreach ($batchInfos as $batchInfo) {
if ($batchInfo->getState() == "Queued" || $batchInfo->getState() == "InProgress") {
printAsyncRefreshBlock();
break;
}
}
print "<h3>Job: " . $jobInfo->getId() . "</h3>";
if ($jobInfo->getStateMessage() != "") {
displayInfo($jobInfo->getStateMessage());
print "<p/>";
}
$timeOnlyFormat = "h:i:s A";
print "<table width='100%' cellpadding='5' class='lightlyBoxed'>";
print "<tr>" .
"<td class='dataLabel'>Status</td><td class='dataValue'>" . $jobInfo->getState() . "</td>" .
"<td class='dataLabel'>Records Processed</td><td class='dataValue'>" . $jobInfo->getNumberRecordsProcessed() . "</td>" .
"<td class='dataLabel'>Batches Queued</td><td class='dataValue'>" . $jobInfo->getNumberBatchesQueued() . "</td>" .
"</tr>";
print "<tr>" .
"<td class='dataLabel'>Object</td><td class='dataValue'>" . $jobInfo->getObject() . "</td>" .
(WorkbenchContext::get()->isApiVersionAtLeast(19.0)
? "<td class='dataLabel'>Records Failed</td><td class='dataValue'>" . $jobInfo->getNumberRecordsFailed() . "</td>"
: "<td class='dataLabel'>Content Type</td><td class='dataValue'>" . $jobInfo->getContentType() . "</td>"
) .
"<td class='dataLabel'>Batches In Progress</td><td class='dataValue'>" . $jobInfo->getNumberBatchesInProgress() . "</td>" .
"</tr>";
print "<tr>" .
"<td class='dataLabel'>Operation</td><td class='dataValue'>" . ucwords($jobInfo->getOpertion()). "</td>" .
"<td class='dataLabel'>Concurrency Mode</td><td class='dataValue'>" . $jobInfo->getConcurrencyMode() . "</td>" .
"<td class='dataLabel'>Batches Completed</td><td class='dataValue'>" . $jobInfo->getNumberBatchesCompleted() . "</td>" .
"</tr>";
print "<tr>" .
"<td class='dataLabel'>External Id</td><td class='dataValue'>" . $jobInfo->getExternalIdFieldName(). "</td>" .
"<td class='dataLabel'>API Version</td><td class='dataValue'>" . $jobInfo->getApiVersion() . "</td>" .
"<td class='dataLabel'>Batches Failed</td><td class='dataValue'>" . $jobInfo->getNumberBatchesFailed() . "</td>" .
"</tr>";
if (WorkbenchContext::get()->isApiVersionAtLeast(19.0)) {
print "<tr>" .
"<td class='dataLabel'>API Processing</td><td class='dataValue'>" . $jobInfo->getApiActiveProcessingTime(). " ms</td>" .
"<td class='dataLabel'>Apex Processing</td><td class='dataValue'>" . $jobInfo->getApexProcessingTime() . " ms</td>" .
"<td class='dataLabel'>Total Processing</td><td class='dataValue'>" . $jobInfo->getTotalProcessingTime() . " ms</td>" .
"</tr>";
}
print "<tr>" .
"<td class='dataLabel'>Created</td><td class='dataValue'>" . localizeDateTimes($jobInfo->getCreatedDate(),$timeOnlyFormat) . "</td>" .
"<td class='dataLabel'>Last Modified</td><td class='dataValue'>" . localizeDateTimes($jobInfo->getSystemModstamp(),$timeOnlyFormat) . "</td>" .
"<td class='dataLabel'>Retries</td><td class='dataValue'>" . $jobInfo->getNumberRetries() . "</td>" .
"</tr>";
print "</table>";
print "<p> </p>";
if (count($batchInfos) > 0) {
print "<h3>Batches</h3>";
print "<table cellpadding='4' width='100%' class='lightlyBoxed'>";
print "<tr>" .
"<th> </th>" .
"<th>Id</th>" .
"<th>Status</th>" .
"<th>Processed</th>" .
(WorkbenchContext::get()->isApiVersionAtLeast(19.0) ? "<th>Failed</th>" : "") .
"<th>Created</th>" .
"<th>Last Modified</th>" .
"</tr>";
foreach ($batchInfos as $batchInfo) {
print "<tr><td class='dataValue'>";
if ($batchInfo->getState() == "Completed" || $batchInfo->getState() == "Failed") {
$batchResultList = array(null); // default to an array of one null
if ($jobInfo->getOpertion() == 'query' && $batchInfo->getState() == "Completed") {
$batchResultList = $asyncConnection->getBatchResultList($jobInfo->getId(), $batchInfo->getId());
}
foreach($batchResultList as $resultId) {
print "<a href='downloadAsyncBatch.php?op=result&jobId=" . $jobInfo->getId() . "&batchId=" . $batchInfo->getId() . "&resultId=" . $resultId . "'>" .
"<img src='" . getPathToStaticResource('/images/downloadIcon' . $batchInfo->getState() . '.gif') . "' border='0' onmouseover=\"Tip('Download " . $batchInfo->getState() . " Batch Results')\"/>" .
"</a><br/>";
}
} else {
print " ";
}
print "</td>";
$processingTimeDetails = "API Processing: " . $batchInfo->getApiActiveProcessingTime() . " ms<br/>" .
"Apex Processing: " . $batchInfo->getApexProcessingTime() . " ms<br/>" .
"Total Processing: " . $batchInfo->getTotalProcessingTime() . " ms<br/>";
print "<td class='dataValue'>" .
(WorkbenchContext::get()->isApiVersionAtLeast(19.0)
? "<a href='downloadAsyncBatch.php?op=request&jobId=" . $jobInfo->getId() . "&batchId=" . $batchInfo->getId() .
"' onmouseover=\"Tip('Download Batch Request')\"/>" . $batchInfo->getId() . "</a>"
: $batchInfo->getId()) .
"</td>" .
"<td class='dataValue'>" . $batchInfo->getState() . (($batchInfo->getStateMessage() != "") ? (": " . $batchInfo->getStateMessage()) : "") . "</td>" .
(WorkbenchContext::get()->isApiVersionAtLeast(19.0)
? "<td class='dataValue pseudoLink' style='cursor: default' onmouseover=\"Tip('$processingTimeDetails')\"/>"
: "<td class='dataValue'>") .
$batchInfo->getNumberRecordsProcessed() . ($batchInfo->getNumberRecordsProcessed() == "1" ? " record" : " records") .
"</td>" .
(WorkbenchContext::get()->isApiVersionAtLeast(19.0)
? "<td class='dataValue'>" . $batchInfo->getNumberRecordsFailed() .
($batchInfo->getNumberRecordsFailed() == "1"
? " record"
: " records") . "</td>"
: "").
"<td class='dataValue'>" . localizeDateTimes($batchInfo->getCreatedDate(),$timeOnlyFormat) . "</td>" .
"<td class='dataValue'>" . localizeDateTimes($batchInfo->getSystemModstamp(),$timeOnlyFormat) . "</td>";
print "</tr>";
}
print "</table>";
}
include_once 'footer.php';
?>