-
Notifications
You must be signed in to change notification settings - Fork 0
/
getUploadStatus.php
115 lines (64 loc) · 3 KB
/
getUploadStatus.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<a href="inc/productErrors.csv"><button>Error-File in Excel öffnen (Erst klicken, wenn Seite aufgehört hat zu "arbeiten"!)</button></a><br><br>
<a href="inc/productInformation.csv"><button>Info-File in Excel öffnen (Erst klicken, wenn Seite aufgehört hat zu "arbeiten"!)</button></a><br><br>
<?php
require_once 'inc/config.php';
$filepath = 'inc/uploadId.txt';
$csv = array("", "");
echo "<h1>Uploadstatus</h1>";
//Read upload ids from file
$handle = fopen($filepath, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$line = trim($line);
echo "<h2>Update task</h2>";
$utaskResult = getUpdateTasks($url, $accessToken, $line);
echo $utaskResult["state"] . " - " . $utaskResult["message"] . "<br>";
// FAILED
$utaskResult = getUpdateTasks($url, $accessToken, $line . '/failed');
$csv = logUpdateTasks("Failed", $csv, $utaskResult);
// SUCCEEDED
$utaskResult = getUpdateTasks($url, $accessToken, $line . '/succeeded');
$csv = logUpdateTasks("Succeeded", $csv, $utaskResult);
// UNCHANGED
$utaskResult = getUpdateTasks($url, $accessToken, $line . '/unchanged');
$csv = logUpdateTasks("Unchanged", $csv, $utaskResult);
}
$csv[0] = "Status;Variation" . PHP_EOL . $csv[0];
$csv[1] = "Variation;Error Code;Error Title;JSon Path" . PHP_EOL . $csv[1];
$file = 'inc/productInformation.csv';
$fileError = 'inc/productErrors.csv';
//Write upload id to file
file_put_contents($file, $csv[0]);
file_put_contents($fileError, $csv[1]);
fclose($handle);
} else {
echo "Fehler beim Lesen der Datei mit Upload-Ids...";
}
function getUpdateTasks($url, $accessToken, $task_url){
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
echo "<br>" . $url . $task_url . "<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $task_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Authorization: Bearer ' . $accessToken;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return json_decode($result, true);
}
function logUpdateTasks($type, $csv, $utaskResult){
foreach($utaskResult["results"] as &$value){
$csv[0] .= $type . ";" . $value["variation"] . PHP_EOL;
if(isset($value["errors"])){
$csvString = $value["variation"] . ';' . $value["errors"][0]["code"] . ';' . $value["errors"][0]["title"] . ';' . $value["errors"][0]["jsonPath"] . PHP_EOL;
$csv[1] .= $csvString;
echo "<br><br>" . nl2br($csvString);
}
}
return $csv;
}