-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_feed.php
More file actions
205 lines (168 loc) Β· 8.23 KB
/
check_feed.php
File metadata and controls
205 lines (168 loc) Β· 8.23 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
use Symfony\Component\Dotenv\Dotenv;
use SellingPartnerApi\Api\FeedsV20210630Api;
require __DIR__ . '/vendor/autoload.php';
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . '/.env');
// Feed ID to check
$feedId = $argv[1] ?? null;
$detailed = in_array('--detailed', $argv) || in_array('-d', $argv);
if (!$feedId) {
echo "β You must provide a Feed ID\n";
echo "Usage: php check_feed.php [feedId] [--detailed]\n";
echo "Example: php check_feed.php 558685020293\n";
echo "Example: php check_feed.php 558685020293 --detailed\n";
echo "\nOptions:\n";
echo " --detailed, -d Download and show detailed report results\n";
exit(1);
}
// Amazon Configuration
$amazonRefresh = $_ENV['AMAZON_REFRESH_TOKEN'];
$amazonClientId = $_ENV['AMAZON_CLIENT_ID'];
$amazonClientSecret = $_ENV['AMAZON_CLIENT_SECRET'];
$amazonAccessKey = $_ENV['AMAZON_ACCESS_KEY'];
$amazonSecretKey = $_ENV['AMAZON_SECRET_KEY'];
$amazonRoleArn = $_ENV['AMAZON_ROLE_ARN'];
$config = new SellingPartnerApi\Configuration([
'lwaClientId' => $amazonClientId,
'lwaClientSecret' => $amazonClientSecret,
'lwaRefreshToken' => $amazonRefresh,
'awsAccessKeyId' => $amazonAccessKey,
'awsSecretAccessKey' => $amazonSecretKey,
'endpoint' => SellingPartnerApi\Endpoint::EU,
'roleArn' => $amazonRoleArn,
]);
try {
$feedsApi = new FeedsV20210630Api($config);
echo "π Checking Feed ID: {$feedId}\n";
echo str_repeat("=", 60) . "\n";
// Get feed information
$feed = $feedsApi->getFeed($feedId);
$status = $feed->getProcessingStatus();
$feedType = $feed->getFeedType();
$createdTime = $feed->getCreatedTime();
$marketplaces = implode(', ', $feed->getMarketplaceIds());
echo "π Feed Type: {$feedType}\n";
echo "π
Created: {$createdTime}\n";
echo "π Marketplaces: {$marketplaces}\n";
echo "\n";
// Show status with emojis
switch ($status) {
case 'DONE':
echo "β
Status: COMPLETED SUCCESSFULLY\n";
if ($feed->getProcessingStartTime()) {
echo "β° Processing started: " . $feed->getProcessingStartTime() . "\n";
}
if ($feed->getProcessingEndTime()) {
echo "β° Processing ended: " . $feed->getProcessingEndTime() . "\n";
}
if ($feed->getResultFeedDocumentId()) {
echo "π Result document ID: " . $feed->getResultFeedDocumentId() . "\n";
}
echo "\nπ Your feed was processed successfully!\n";
// Handle detailed report if requested and available
if ($detailed && $feed->getResultFeedDocumentId()) {
echo "\n" . str_repeat("-", 50) . "\n";
echo "π Downloading detailed report...\n";
try {
$resultDocumentId = $feed->getResultFeedDocumentId();
$resultDocument = $feedsApi->getFeedDocument($resultDocumentId);
// Download report content
$document = new SellingPartnerApi\Document($resultDocument, ['contentType' => 'application/json']);
$reportContent = $document->download();
echo "\n=== DETAILED REPORT ===\n";
// Try to parse and format JSON
$reportData = json_decode($reportContent, true);
if ($reportData) {
echo "π Summary:\n";
if (isset($reportData['summary'])) {
$summary = $reportData['summary'];
echo " β’ Messages processed: " . ($summary['messagesProcessed'] ?? 'N/A') . "\n";
echo " β’ Messages accepted: " . ($summary['messagesAccepted'] ?? 'N/A') . "\n";
echo " β’ Messages invalid: " . ($summary['messagesInvalid'] ?? 'N/A') . "\n";
echo " β’ Errors: " . ($summary['errors'] ?? 'N/A') . "\n";
echo " β’ Warnings: " . ($summary['warnings'] ?? 'N/A') . "\n";
}
if (isset($reportData['issues']) && count($reportData['issues']) > 0) {
echo "\nβ οΈ Issues found:\n";
foreach ($reportData['issues'] as $issue) {
$code = $issue['code'] ?? 'Unknown';
$message = $issue['message'] ?? 'No message';
$severity = $issue['severity'] ?? 'Unknown';
$severityIcon = match($severity) {
'ERROR' => 'β',
'WARNING' => 'β οΈ',
'INFO' => 'βΉοΈ',
default => 'β'
};
echo " {$severityIcon} [{$severity}] {$code}: {$message}\n";
}
} else {
echo "\nβ
No issues found in the report.\n";
}
// Save report to file
$reportFileName = "feeds/feed_report_{$feedId}_" . date('Y-m-d_H-i-s') . ".json";
file_put_contents($reportFileName, json_encode($reportData, JSON_PRETTY_PRINT));
echo "\nπ Full report saved to: {$reportFileName}\n";
} else {
echo $reportContent . "\n";
}
} catch (Exception $e) {
echo "β Error downloading report: " . $e->getMessage() . "\n";
}
}
break;
case 'IN_QUEUE':
echo "β³ Status: IN QUEUE - Waiting for processing\n";
echo "π‘ Check again in a few minutes...\n";
break;
case 'IN_PROGRESS':
echo "βοΈ Status: IN PROGRESS\n";
if ($feed->getProcessingStartTime()) {
echo "β° Started: " . $feed->getProcessingStartTime() . "\n";
}
echo "π‘ Processing is in progress...\n";
break;
case 'FATAL':
echo "β Status: FATAL ERROR\n";
echo "β οΈ The feed failed during processing\n";
if ($feed->getResultFeedDocumentId()) {
echo "π Error report available: " . $feed->getResultFeedDocumentId() . "\n";
if ($detailed) {
echo "\n" . str_repeat("-", 50) . "\n";
echo "π Downloading error report...\n";
try {
$resultDocumentId = $feed->getResultFeedDocumentId();
$resultDocument = $feedsApi->getFeedDocument($resultDocumentId);
$document = new SellingPartnerApi\Document($resultDocument, ['contentType' => 'application/json']);
$reportContent = $document->download();
echo "\n=== ERROR REPORT ===\n";
echo $reportContent . "\n";
// Save error report
$errorFileName = "feeds/feed_error_{$feedId}_" . date('Y-m-d_H-i-s') . ".json";
file_put_contents($errorFileName, $reportContent);
echo "\nπ Error report saved to: {$errorFileName}\n";
} catch (Exception $e) {
echo "β Error downloading error report: " . $e->getMessage() . "\n";
}
}
}
break;
case 'CANCELLED':
echo "π« Status: CANCELLED\n";
break;
default:
echo "β Status: {$status}\n";
}
echo "\n" . str_repeat("=", 60) . "\n";
echo "π Possible statuses:\n";
echo "β’ IN_QUEUE: Waiting for processing\n";
echo "β’ IN_PROGRESS: Being processed\n";
echo "β’ DONE: Completed successfully\n";
echo "β’ CANCELLED: Cancelled\n";
echo "β’ FATAL: Fatal error during processing\n";
echo "\nπ‘ Use --detailed flag to download and view reports when available\n";
} catch (Exception $e) {
echo "β Error: " . $e->getMessage() . "\n";
echo "π File: " . $e->getFile() . " Line: " . $e->getLine() . "\n";
}