debug_assets.php Changes:
1. Added Quick Asset Lookup by ID
- Form to search for specific asset ID
- Shows if asset exists in DAM
- Displays parent folder(s)
- Direct link to view folder
- Helps debug "where did my upload go" issues
2. Added delete debugging
- Log HTTP response code
- Log response body
- Check for both 200 and 204 status codes
- Better error messages with HTTP codes
3. Added direct asset display
- Shows complete asset details
- Lists all parent folders
- Full JSON preview
Usage:
- Enter asset ID 214817 in Quick Lookup
- Click "Check if Asset Exists"
- See which folder(s) it's in
- Verify upload worked
For Delete:
- Click delete button
- Check logs: tail -f /Applications/MAMP/logs/php_error.log | grep "DEBUG DELETE"
- See HTTP response and error details
🤖 Generated with Claude Code
444 lines
18 KiB
PHP
444 lines
18 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';
|
|
$currentFolderId = $_GET['folder_id'] ?? null;
|
|
$folderResults = null;
|
|
$assetResults = null;
|
|
$error = null;
|
|
$success = 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();
|
|
}
|
|
}
|
|
|
|
if ($_GET['action'] === 'delete_asset' && isset($_GET['asset_id'])) {
|
|
try {
|
|
$assetId = $_GET['asset_id'];
|
|
$returnFolder = $_GET['folder_id'] ?? null;
|
|
|
|
$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());
|
|
}
|
|
|
|
// Delete asset
|
|
$request = [
|
|
'method' => 'DELETE',
|
|
'url' => "/v6/assets/{$assetId}"
|
|
];
|
|
|
|
error_log("DEBUG DELETE: Deleting asset $assetId");
|
|
|
|
$response = $apiClient->executeRequest($request);
|
|
|
|
error_log("DEBUG DELETE: HTTP Code: " . ($response['http_code'] ?? 'N/A'));
|
|
error_log("DEBUG DELETE: Response: " . substr($response['body'] ?? '', 0, 500));
|
|
|
|
// Check for successful HTTP codes (200, 204 No Content are typical for DELETE)
|
|
if ($response['success'] && ($response['http_code'] == 200 || $response['http_code'] == 204)) {
|
|
$success = "✅ Asset deleted successfully: $assetId";
|
|
error_log("DEBUG DELETE: SUCCESS");
|
|
// Redirect back to folder view
|
|
if ($returnFolder) {
|
|
header("Location: ?action=get_assets&folder_id=" . urlencode($returnFolder) . "&deleted=1");
|
|
exit;
|
|
}
|
|
} else {
|
|
$errorDetail = $response['body'] ?? $response['error'] ?? 'Unknown error';
|
|
$error = "❌ Failed to delete asset (HTTP {$response['http_code']}): $errorDetail";
|
|
error_log("DEBUG DELETE: FAILED - $error");
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
if ($_GET['action'] === 'get_asset_direct' && isset($_GET['asset_id'])) {
|
|
try {
|
|
$assetId = $_GET['asset_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 specific asset
|
|
$request = [
|
|
'method' => 'GET',
|
|
'url' => "/v6/assets/{$assetId}?load_type=full"
|
|
];
|
|
|
|
$response = $apiClient->executeRequest($request);
|
|
|
|
error_log("DIRECT ASSET LOOKUP: Asset $assetId - HTTP " . $response['http_code']);
|
|
|
|
if ($response['success'] && $response['http_code'] == 200) {
|
|
$assetData = json_decode($response['body'], true);
|
|
$success = "✅ Asset found: $assetId";
|
|
// Store for display
|
|
$assetResults = ['direct_asset' => $assetData];
|
|
} else {
|
|
$error = "❌ Asset not found: $assetId (HTTP {$response['http_code']})";
|
|
error_log("DIRECT ASSET LOOKUP: Response: " . substr($response['body'] ?? '', 0, 500));
|
|
}
|
|
|
|
} 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; ?>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success">
|
|
<?= htmlspecialchars($success) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($_GET['deleted'])): ?>
|
|
<div class="alert alert-success">
|
|
✅ Asset deleted successfully
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div style="margin-bottom: 20px;">
|
|
<a href="?action=get_folders&campaign_id=<?= urlencode($campaignId) ?>" class="btn">Step 1: Get Campaign Folders</a>
|
|
</div>
|
|
|
|
<div style="margin: 20px 0; padding: 15px; background: #f8f9fa; border-radius: 6px;">
|
|
<h3>🔍 Quick Asset Lookup by ID</h3>
|
|
<form method="GET" style="display: flex; gap: 10px; margin-top: 10px;">
|
|
<input type="hidden" name="action" value="get_asset_direct">
|
|
<input type="text" name="asset_id" placeholder="Enter Asset ID (e.g., 214817)"
|
|
style="flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 4px;"
|
|
value="<?= htmlspecialchars($_GET['asset_id'] ?? '') ?>">
|
|
<button type="submit" class="btn">Check if Asset Exists</button>
|
|
</form>
|
|
<p style="font-size: 12px; color: #666; margin-top: 5px;">
|
|
Use this to verify if an asset ID exists in the DAM (helps debug upload issues)
|
|
</p>
|
|
</div>
|
|
|
|
<?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>
|
|
<a href="?action=get_assets&folder_id=<?= urlencode($folder['asset_id']) ?>&campaign_id=<?= urlencode($campaignId) ?>" class="btn">
|
|
📂 Get Assets from This Folder
|
|
</a>
|
|
</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 (isset($assetResults['direct_asset'])): ?>
|
|
<div class="section">
|
|
<h2>✅ Direct Asset Lookup Result</h2>
|
|
<?php
|
|
$asset = $assetResults['direct_asset']['asset_resource']['asset'] ?? $assetResults['direct_asset'];
|
|
$assetName = $asset['name'] ?? 'Unknown';
|
|
$assetId = $asset['asset_id'] ?? 'Unknown';
|
|
$parentFolders = $asset['parent_folder_ids'] ?? [];
|
|
?>
|
|
<div class="asset-card">
|
|
<h3><?= htmlspecialchars($assetName) ?></h3>
|
|
<p><strong>Asset ID:</strong> <span class="asset-id"><?= htmlspecialchars($assetId) ?></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; ?>
|
|
<?php if (!empty($parentFolders)): ?>
|
|
<p><strong>Parent Folder(s):</strong></p>
|
|
<ul>
|
|
<?php foreach ($parentFolders as $folderId): ?>
|
|
<li>
|
|
<code><?= htmlspecialchars($folderId) ?></code>
|
|
<a href="?action=get_assets&folder_id=<?= urlencode($folderId) ?>" style="margin-left: 10px;">
|
|
📂 View Folder
|
|
</a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<details style="margin-top: 20px;">
|
|
<summary><strong>Full Asset JSON</strong></summary>
|
|
<pre><?= htmlspecialchars(json_encode($assetResults['direct_asset'], JSON_PRETTY_PRINT)) ?></pre>
|
|
</details>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($assetResults && !isset($assetResults['direct_asset'])): ?>
|
|
<div class="section">
|
|
<h2>Assets in Folder</h2>
|
|
<?php
|
|
$assets = $assetResults['folder_children']['asset_list'] ?? [];
|
|
?>
|
|
<p>Found <?= count($assets) ?> asset(s) |
|
|
<a href="?action=get_assets&folder_id=<?= urlencode($currentFolderId) ?>" class="btn" style="font-size: 12px; padding: 6px 12px;">
|
|
🔄 Refresh
|
|
</a>
|
|
</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>
|
|
<a href="?action=delete_asset&asset_id=<?= urlencode($asset['asset_id']) ?>&folder_id=<?= urlencode($currentFolderId) ?>"
|
|
class="btn" style="background: #dc3545; margin-left: 10px;"
|
|
onclick="return confirm('Delete asset: <?= htmlspecialchars($assetName) ?>?')">
|
|
🗑️ Delete
|
|
</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>
|