debug_assets.php Changes:
- Added delete_asset action handler
- DELETE /v6/assets/{id} API call
- 🗑️ Delete button for each asset
- Confirmation dialog before delete
- Auto-refresh folder after delete
- 🔄 Refresh button to reload folder assets
- Success/deleted message display
workflow_v3.php Changes:
- Show upload folder ID in success message
- Add 🔍 View in Final Assets Folder link
- Direct link to debug_assets.php with folder ID
- Pass upload_folder and master_asset_id in response
Features:
✅ Delete test assets easily
✅ Refresh folder to see latest uploads
✅ Direct link to view uploaded assets in folder
✅ Confirmation before delete
✅ Auto-redirect after delete
Usage:
1. Upload asset → Click 🔍 View in Final Assets Folder link
2. See all assets in that folder
3. Click 🗑️ Delete to remove test assets
4. Click 🔄 Refresh to reload after upload
🤖 Generated with Claude Code
341 lines
13 KiB
PHP
341 lines
13 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}"
|
|
];
|
|
|
|
$response = $apiClient->executeRequest($request);
|
|
|
|
if ($response['success']) {
|
|
$success = "✅ Asset deleted successfully: $assetId";
|
|
// Redirect back to folder view
|
|
if ($returnFolder) {
|
|
header("Location: ?action=get_assets&folder_id=" . urlencode($returnFolder) . "&deleted=1");
|
|
exit;
|
|
}
|
|
} else {
|
|
$error = "❌ Failed to delete asset: " . ($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; ?>
|
|
|
|
<?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; ?>
|
|
|
|
<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>
|
|
<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 ($assetResults): ?>
|
|
<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>
|