Fixes: - Metadata button now works (fixed JavaScript and element IDs) - Display full metadata as JSON when clicked - Detect and show proper error when files don't exist in storage - Show detailed download error messages (HTTP 500, file not found) - Display download success/failure with file size and path - Use old working Postman collection with OAuth2 configured - Update StatusManager to use working search pattern + status filter Changes: - Switch to Content Scaling Flow.postman_collection_Oliver(New).json - Fix downloadAsset to detect JSON error responses - Improve metadata display with toggle functionality - Show clear error messages for missing files in DAM storage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
389 lines
15 KiB
PHP
389 lines
15 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
require_once 'config_v3.php';
|
|
require_once 'src/TestRunner.php';
|
|
require_once 'src/MetadataExtractor.php';
|
|
|
|
$configV3 = new ConfigV3();
|
|
$config = [
|
|
'baseUrl' => $configV3->getBaseUrl(),
|
|
'timeout' => $configV3->get('api.timeout'),
|
|
'headers' => [
|
|
'Content-Type' => 'application/json',
|
|
'Accept' => 'application/json'
|
|
]
|
|
];
|
|
|
|
$collectionPath = __DIR__ . '/' . $configV3->get('postman_collection');
|
|
$testRunner = new TestRunner($collectionPath, $config);
|
|
|
|
$campaigns = [];
|
|
$error = null;
|
|
|
|
// Load ALL localized campaigns (no status filter)
|
|
if ($_GET['action'] === 'load_all' || !isset($_GET['action'])) {
|
|
try {
|
|
$requests = $testRunner->getAvailableRequests();
|
|
|
|
foreach ($requests as $index => $request) {
|
|
if (strpos($request['name'], 'Retrieve Localized Campaign') !== false) {
|
|
// Modify the request to remove status filter
|
|
$modifiedRequest = $request;
|
|
$url = is_array($request['request']['url']) ? $request['request']['url']['raw'] : $request['request']['url'];
|
|
|
|
// Decode the search condition to remove status filter
|
|
$searchCondition = [
|
|
'search_condition_list' => [
|
|
'search_condition' => [
|
|
[
|
|
'display_value' => 'L7+ - CAMPAIGN',
|
|
'left_paren' => '(',
|
|
'metadata_field_id' => 'ARTESIA.FIELD.CONTAINER TYPE NAME',
|
|
'relational_operator_id' => 'ARTESIA.OPERATOR.CHAR.CONTAINS',
|
|
'right_paren' => ')',
|
|
'type' => 'com.artesia.search.SearchScalarCondition',
|
|
'value' => 'GLOBALCAMPAING'
|
|
],
|
|
[
|
|
'metadata_field_id' => 'FERRERO.FIELD.CAMPAIGN TYPE',
|
|
'relational_operator' => 'and',
|
|
'relational_operator_id' => 'ARTESIA.OPERATOR.CHAR.IS',
|
|
'type' => 'com.artesia.search.SearchScalarCondition',
|
|
'value' => 'Local adaptation of global comm'
|
|
]
|
|
// Removed status filter to get ALL campaigns
|
|
]
|
|
]
|
|
];
|
|
|
|
$searchEncoded = urlencode(json_encode($searchCondition));
|
|
$baseUrl = $configV3->getBaseUrl();
|
|
$newUrl = "{$baseUrl}/v6/search/text?load_type=metadata&search_config_id=18&search_condition_list={$searchEncoded}";
|
|
|
|
if (is_array($modifiedRequest['request']['url'])) {
|
|
$modifiedRequest['request']['url']['raw'] = $newUrl;
|
|
} else {
|
|
$modifiedRequest['request']['url'] = $newUrl;
|
|
}
|
|
|
|
$result = $testRunner->runSingleTest($modifiedRequest, $index);
|
|
|
|
if ($result['status'] === 'PASS') {
|
|
$data = json_decode($result['response']['body'], true);
|
|
$assetList = $data['asset_list']['asset'] ?? [];
|
|
|
|
// Extract campaign info with status
|
|
foreach ($assetList as $asset) {
|
|
$campaignInfo = extractCampaignWithStatus($asset);
|
|
$campaigns[] = $campaignInfo;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
function extractCampaignWithStatus($asset)
|
|
{
|
|
$info = [
|
|
'asset_id' => $asset['asset_id'] ?? 'Unknown',
|
|
'campaign_name' => 'Unknown',
|
|
'campaign_id' => 'Unknown',
|
|
'brand' => 'Unknown',
|
|
'market' => 'Unknown',
|
|
'status' => 'NOT FOUND',
|
|
'status_field_found' => false,
|
|
'all_metadata_fields' => []
|
|
];
|
|
|
|
if (!isset($asset['metadata']['metadata_element_list'])) {
|
|
return $info;
|
|
}
|
|
|
|
// Traverse metadata to find fields
|
|
foreach ($asset['metadata']['metadata_element_list'] as $category) {
|
|
if (!isset($category['metadata_element_list'])) continue;
|
|
|
|
foreach ($category['metadata_element_list'] as $field) {
|
|
$fieldId = $field['id'] ?? '';
|
|
$fieldValue = $field['value']['value']['value'] ?? null;
|
|
|
|
// Store all field IDs we find
|
|
$info['all_metadata_fields'][] = $fieldId;
|
|
|
|
// Extract specific fields
|
|
switch ($fieldId) {
|
|
case 'FERRERO.FIELD.CAMPAIGN_NAME':
|
|
$info['campaign_name'] = $fieldValue;
|
|
break;
|
|
case 'FERRERO.FIELD.CAMPAIGN_ID':
|
|
$info['campaign_id'] = $fieldValue;
|
|
break;
|
|
case 'FERRERO.FIELD.BRAND':
|
|
$info['brand'] = $fieldValue;
|
|
break;
|
|
case 'FERRERO.FIELD.MARKET':
|
|
$info['market'] = $fieldValue;
|
|
break;
|
|
case 'CONTENT.SCALING.STATUS':
|
|
$info['status'] = $fieldValue ?? 'EMPTY';
|
|
$info['status_field_found'] = true;
|
|
break;
|
|
case 'FERRERO.FIELD.CONTENT.SCALING.STATUS':
|
|
$info['status'] = $fieldValue ?? 'EMPTY';
|
|
$info['status_field_found'] = true;
|
|
$info['status_field_alternate'] = 'FERRERO.FIELD.CONTENT.SCALING.STATUS';
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $info;
|
|
}
|
|
|
|
$oauth2Status = $testRunner->getOAuth2Status();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Debug Status Field</title>
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
padding: 20px;
|
|
background: #f5f5f5;
|
|
}
|
|
.container {
|
|
max-width: 1600px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
padding: 30px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
.alert {
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
margin: 15px 0;
|
|
}
|
|
.alert-success { background: #d4edda; color: #155724; }
|
|
.alert-error { background: #f8d7da; color: #721c24; }
|
|
.alert-info { background: #d1ecf1; color: #0c5460; }
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 20px 0;
|
|
}
|
|
th, td {
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
th {
|
|
background: #667eea;
|
|
color: white;
|
|
font-weight: 600;
|
|
}
|
|
tr:hover {
|
|
background: #f8f9fa;
|
|
}
|
|
.status-badge {
|
|
display: inline-block;
|
|
padding: 4px 12px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
}
|
|
.status-found { background: #d4edda; color: #155724; }
|
|
.status-not-found { background: #f8d7da; color: #721c24; }
|
|
.status-empty { background: #fff3cd; color: #856404; }
|
|
.btn {
|
|
padding: 12px 24px;
|
|
background: #667eea;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
}
|
|
.btn:hover { background: #5568d3; }
|
|
details {
|
|
margin: 10px 0;
|
|
padding: 10px;
|
|
background: #f8f9fa;
|
|
border-radius: 4px;
|
|
}
|
|
summary {
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
padding: 5px;
|
|
}
|
|
summary:hover {
|
|
background: #e9ecef;
|
|
}
|
|
.field-list {
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
background: white;
|
|
padding: 10px;
|
|
border-radius: 4px;
|
|
margin-top: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🔍 Debug: Status Field Analysis</h1>
|
|
<p style="color: #666; margin-bottom: 20px;">
|
|
This page loads ALL localized campaigns and shows where the status field is located in the metadata
|
|
</p>
|
|
|
|
<?php if ($oauth2Status && $oauth2Status['enabled']): ?>
|
|
<div class="alert alert-<?= ($oauth2Status['has_token'] ?? false) ? 'success' : 'error' ?>">
|
|
<?= ($oauth2Status['has_token'] ?? false) ? '✅ OAuth2 Token Active' : '❌ OAuth2 Token Issue' ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-error">
|
|
<strong>Error:</strong> <?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<a href="?action=load_all">
|
|
<button class="btn">🔄 Load All Localized Campaigns</button>
|
|
</a>
|
|
|
|
<?php if (!empty($campaigns)): ?>
|
|
<div class="alert alert-success">
|
|
Found <?= count($campaigns) ?> localized campaign(s)
|
|
</div>
|
|
|
|
<h2>Campaign Status Summary</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Campaign Name</th>
|
|
<th>Campaign ID</th>
|
|
<th>Brand</th>
|
|
<th>Market</th>
|
|
<th>Status Value</th>
|
|
<th>Status Field Found?</th>
|
|
<th>Asset ID</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($campaigns as $campaign): ?>
|
|
<tr>
|
|
<td><strong><?= htmlspecialchars($campaign['campaign_name']) ?></strong></td>
|
|
<td><?= htmlspecialchars($campaign['campaign_id']) ?></td>
|
|
<td><?= htmlspecialchars($campaign['brand']) ?></td>
|
|
<td><?= htmlspecialchars($campaign['market']) ?></td>
|
|
<td>
|
|
<span class="status-badge <?= $campaign['status_field_found'] ? 'status-found' : 'status-not-found' ?>">
|
|
<?= htmlspecialchars($campaign['status']) ?>
|
|
</span>
|
|
<?php if (isset($campaign['status_field_alternate'])): ?>
|
|
<br><small>Alt Field: <?= htmlspecialchars($campaign['status_field_alternate']) ?></small>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?php if ($campaign['status_field_found']): ?>
|
|
<span class="status-badge status-found">✅ YES</span>
|
|
<?php else: ?>
|
|
<span class="status-badge status-not-found">❌ NO</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><code style="font-size: 11px;"><?= htmlspecialchars($campaign['asset_id']) ?></code></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h2>Metadata Field Analysis</h2>
|
|
<?php
|
|
$statusCounts = [];
|
|
$fieldIdCounts = [];
|
|
foreach ($campaigns as $campaign) {
|
|
$status = $campaign['status'];
|
|
$statusCounts[$status] = ($statusCounts[$status] ?? 0) + 1;
|
|
|
|
foreach ($campaign['all_metadata_fields'] as $fieldId) {
|
|
$fieldIdCounts[$fieldId] = ($fieldIdCounts[$fieldId] ?? 0) + 1;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;">
|
|
<div style="background: #f8f9fa; padding: 20px; border-radius: 8px;">
|
|
<h3>Status Distribution</h3>
|
|
<table style="margin: 0;">
|
|
<thead>
|
|
<tr>
|
|
<th>Status Value</th>
|
|
<th>Count</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($statusCounts as $status => $count): ?>
|
|
<tr>
|
|
<td><strong><?= htmlspecialchars($status) ?></strong></td>
|
|
<td><?= $count ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div style="background: #f8f9fa; padding: 20px; border-radius: 8px;">
|
|
<h3>Status-Related Fields Found</h3>
|
|
<?php
|
|
$statusFields = array_filter(array_keys($fieldIdCounts), function($field) {
|
|
return stripos($field, 'STATUS') !== false || stripos($field, 'SCALING') !== false;
|
|
});
|
|
?>
|
|
<?php if (!empty($statusFields)): ?>
|
|
<ul>
|
|
<?php foreach ($statusFields as $field): ?>
|
|
<li>
|
|
<code><?= htmlspecialchars($field) ?></code>
|
|
(in <?= $fieldIdCounts[$field] ?> campaigns)
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else: ?>
|
|
<p style="color: #dc3545;">❌ No status-related fields found!</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<details>
|
|
<summary>🔍 View All Metadata Field IDs Found (<?= count($fieldIdCounts) ?> unique fields)</summary>
|
|
<div class="field-list">
|
|
<?php
|
|
ksort($fieldIdCounts);
|
|
foreach ($fieldIdCounts as $fieldId => $count):
|
|
?>
|
|
<div><?= htmlspecialchars($fieldId) ?> <em>(<?= $count ?>)</em></div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</details>
|
|
|
|
<?php elseif (isset($_GET['action'])): ?>
|
|
<div class="alert alert-info">
|
|
No campaigns found. Click the button above to load campaigns.
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|