Fixes: - Extract folder/asset names from INER_NAME_GENERIC field (correct field ID) - Add fallback to 'name' field if metadata field not found - Fix debug_assets.php to maintain campaign_id in URL parameters - Add "Clear Workflow Data" button to reset cached session data - Improve error messages when files don't exist in storage - Allow status update even if downloads fail (test environment) Changes: - Update extractFolderName() to check INER_NAME_GENERIC first - Fix debug_assets.php folder and asset name extraction - Add clear_results action to workflow_v3.php - Show folder names correctly in debug interface - Display clear message about test environment file availability Working: ✅ OAuth2 authentication ✅ Campaign search by status ✅ Folder navigation ✅ Asset listing with correct IDs ✅ Metadata extraction ⚠️ Download fails - files don't exist in test environment storage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
281 lines
11 KiB
PHP
281 lines
11 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
require_once 'config_v3.php';
|
|
require_once 'src/TestRunner.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);
|
|
|
|
// Get campaign ID from URL or use default
|
|
$campaignId = $_GET['campaign_id'] ?? '9697ffb1cc07b7c90ca0ea44ac44d3f6b01efa96';
|
|
$folderResults = null;
|
|
$assetResults = null;
|
|
$error = null;
|
|
|
|
if ($_GET['action'] === 'get_folders') {
|
|
try {
|
|
$apiClient = new ApiClient();
|
|
$apiClient->setBaseUrl($configV3->getBaseUrl());
|
|
|
|
$oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler');
|
|
$oauth2Handler->setAccessible(true);
|
|
$oauth2HandlerInstance = $oauth2Handler->getValue($testRunner);
|
|
if ($oauth2HandlerInstance) {
|
|
$apiClient->setHeader('Authorization', $oauth2HandlerInstance->getAuthHeader());
|
|
}
|
|
|
|
// Get folders
|
|
$request = [
|
|
'method' => 'GET',
|
|
'url' => "/v6/folders/{$campaignId}/children?load_type=metadata"
|
|
];
|
|
|
|
$response = $apiClient->executeRequest($request);
|
|
|
|
if ($response['success']) {
|
|
$folderResults = json_decode($response['body'], true);
|
|
} else {
|
|
$error = "Failed to get folders: " . ($response['error'] ?? 'Unknown error');
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
if ($_GET['action'] === 'get_assets' && isset($_GET['folder_id'])) {
|
|
try {
|
|
$folderId = $_GET['folder_id'];
|
|
|
|
$apiClient = new ApiClient();
|
|
$apiClient->setBaseUrl($configV3->getBaseUrl());
|
|
|
|
$oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler');
|
|
$oauth2Handler->setAccessible(true);
|
|
$oauth2HandlerInstance = $oauth2Handler->getValue($testRunner);
|
|
if ($oauth2HandlerInstance) {
|
|
$apiClient->setHeader('Authorization', $oauth2HandlerInstance->getAuthHeader());
|
|
}
|
|
|
|
// Get assets from folder
|
|
$request = [
|
|
'method' => 'GET',
|
|
'url' => "/v6/folders/{$folderId}/children?load_type=metadata"
|
|
];
|
|
|
|
$response = $apiClient->executeRequest($request);
|
|
|
|
if ($response['success']) {
|
|
$assetResults = json_decode($response['body'], true);
|
|
} else {
|
|
$error = "Failed to get assets: " . ($response['error'] ?? 'Unknown error');
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$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 Asset IDs</title>
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
padding: 20px;
|
|
background: #f5f5f5;
|
|
}
|
|
.container {
|
|
max-width: 1400px;
|
|
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; }
|
|
.btn {
|
|
padding: 12px 24px;
|
|
background: #667eea;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
}
|
|
.btn:hover { background: #5568d3; }
|
|
pre {
|
|
background: #f8f9fa;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
overflow-x: auto;
|
|
max-height: 400px;
|
|
}
|
|
.section {
|
|
margin: 30px 0;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 8px;
|
|
}
|
|
.asset-card {
|
|
background: white;
|
|
padding: 15px;
|
|
margin: 10px 0;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
}
|
|
.asset-id {
|
|
font-family: monospace;
|
|
background: #e9ecef;
|
|
padding: 3px 8px;
|
|
border-radius: 3px;
|
|
font-size: 12px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🔍 Debug Asset IDs</h1>
|
|
<p><strong>Campaign Asset ID:</strong> <code><?= htmlspecialchars($campaignId) ?></code></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=get_folders&campaign_id=<?= urlencode($campaignId) ?>" class="btn">Step 1: Get Campaign Folders</a>
|
|
|
|
<?php if ($folderResults): ?>
|
|
<div class="section">
|
|
<h2>Campaign Folders</h2>
|
|
<?php
|
|
$folders = $folderResults['folder_children']['asset_list'] ?? [];
|
|
?>
|
|
<p>Found <?= count($folders) ?> folder(s)</p>
|
|
|
|
<?php foreach ($folders as $folder): ?>
|
|
<?php
|
|
$folderName = 'Unknown';
|
|
if (isset($folder['metadata']['metadata_element_list'])) {
|
|
foreach ($folder['metadata']['metadata_element_list'] as $category) {
|
|
if (isset($category['metadata_element_list'])) {
|
|
foreach ($category['metadata_element_list'] as $field) {
|
|
if (($field['id'] === 'INER_NAME_GENERIC' || $field['id'] === 'ARTESIA.FIELD.NAME')
|
|
&& isset($field['value']['value']['value'])) {
|
|
$folderName = $field['value']['value']['value'];
|
|
break 2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Fallback to name field
|
|
if ($folderName === 'Unknown' && isset($folder['name'])) {
|
|
$folderName = $folder['name'];
|
|
}
|
|
?>
|
|
<div class="asset-card">
|
|
<h3><?= htmlspecialchars($folderName) ?></h3>
|
|
<p><strong>Asset ID:</strong> <span class="asset-id"><?= htmlspecialchars($folder['asset_id']) ?></span></p>
|
|
<p><strong>Type:</strong> <?= htmlspecialchars($folder['data_type'] ?? 'N/A') ?></p>
|
|
<?php if (strpos($folderName, 'Master') !== false): ?>
|
|
<a href="?action=get_assets&folder_id=<?= urlencode($folder['asset_id']) ?>" class="btn">
|
|
Get Assets from This Folder
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<details style="margin-top: 20px;">
|
|
<summary><strong>Full Folder JSON</strong></summary>
|
|
<pre><?= htmlspecialchars(json_encode($folderResults, JSON_PRETTY_PRINT)) ?></pre>
|
|
</details>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($assetResults): ?>
|
|
<div class="section">
|
|
<h2>Assets in Folder</h2>
|
|
<?php
|
|
$assets = $assetResults['folder_children']['asset_list'] ?? [];
|
|
?>
|
|
<p>Found <?= count($assets) ?> asset(s)</p>
|
|
|
|
<?php foreach ($assets as $asset): ?>
|
|
<?php
|
|
$assetName = 'Unknown';
|
|
if (isset($asset['metadata']['metadata_element_list'])) {
|
|
foreach ($asset['metadata']['metadata_element_list'] as $category) {
|
|
if (isset($category['metadata_element_list'])) {
|
|
foreach ($category['metadata_element_list'] as $field) {
|
|
if (($field['id'] === 'ARTESIA.FIELD.NAME' || $field['id'] === 'INER_NAME_GENERIC')
|
|
&& isset($field['value']['value']['value'])) {
|
|
$assetName = $field['value']['value']['value'];
|
|
break 2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Fallback to name field
|
|
if ($assetName === 'Unknown' && isset($asset['name'])) {
|
|
$assetName = $asset['name'];
|
|
}
|
|
?>
|
|
<div class="asset-card">
|
|
<h4><?= htmlspecialchars($assetName) ?></h4>
|
|
<p><strong>✅ CORRECT Asset ID:</strong> <span class="asset-id"><?= htmlspecialchars($asset['asset_id']) ?></span></p>
|
|
<p><strong>Type:</strong> <?= htmlspecialchars($asset['data_type'] ?? 'N/A') ?></p>
|
|
<p><strong>MIME Type:</strong> <?= htmlspecialchars($asset['mime_type'] ?? 'N/A') ?></p>
|
|
<?php if (isset($asset['file_size'])): ?>
|
|
<p><strong>File Size:</strong> <?= number_format($asset['file_size']) ?> bytes</p>
|
|
<?php endif; ?>
|
|
|
|
<a href="test_asset_detail.php?action=get_asset&asset_id=<?= urlencode($asset['asset_id']) ?>"
|
|
class="btn" target="_blank">
|
|
Test Download This Asset
|
|
</a>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<details style="margin-top: 20px;">
|
|
<summary><strong>Full Assets JSON</strong></summary>
|
|
<pre><?= htmlspecialchars(json_encode($assetResults, JSON_PRETTY_PRINT)) ?></pre>
|
|
</details>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|