Fix CREATIVEX extraction - detect at category level not field level
Issue: CREATIVEX fields still not appearing Root Cause: FERRERO.FIELD.CREATIX is a CATEGORY, not a field within a category Fix: - Check category ID/name for 'CREATIX' or 'CreativeX' - When CREATIVEX category found, extract ALL items within it - Handle both tables and direct fields in CREATIVEX category - Show fields even if empty (displays structure) Structure: Category: FERRERO.FIELD.CREATIX (name: CreativeX) ├─ Table: FERRERO.TABULAR.FIELD.CREATIVEX (Confidence) │ └─ Field: FERRERO.TAB.FIELD.CREATIVEX (Platform > Rating %) └─ Field: FERRERO.FIELD.CREATIVEX LINK (CreativeX Hyperlink) Test Results: ✅ Extracted 2 CREATIVEX fields ✅ Platform > Rating (%): (empty) ✅ CreativeX Hyperlink: (empty) Now purple CREATIVEX section will appear in metadata viewer! 🤖 Generated with Claude Code
This commit is contained in:
parent
70d4f1be71
commit
b273fdafee
3 changed files with 118 additions and 14 deletions
Binary file not shown.
|
|
@ -96,17 +96,85 @@ class MetadataExtractor
|
|||
$metadata['creativex_fields'] = [];
|
||||
if (isset($asset['metadata']['metadata_element_list'])) {
|
||||
foreach ($asset['metadata']['metadata_element_list'] as $category) {
|
||||
$categoryId = $category['id'] ?? '';
|
||||
$categoryName = $category['name'] ?? '';
|
||||
|
||||
// Check if THIS CATEGORY is the CREATIVEX category
|
||||
if (stripos($categoryId, 'CREATIX') !== false ||
|
||||
stripos($categoryId, 'CREATIVEX') !== false ||
|
||||
stripos($categoryName, 'CreativeX') !== false) {
|
||||
|
||||
// This whole category is CREATIVEX - extract all its fields
|
||||
if (isset($category['metadata_element_list'])) {
|
||||
foreach ($category['metadata_element_list'] as $creativexItem) {
|
||||
$itemId = $creativexItem['id'] ?? '';
|
||||
$itemName = $creativexItem['name'] ?? $itemId;
|
||||
|
||||
// Check if it's a table or direct field
|
||||
if (isset($creativexItem['metadata_element_list'])) {
|
||||
// It's a table with fields
|
||||
foreach ($creativexItem['metadata_element_list'] as $tableField) {
|
||||
$tableFieldId = $tableField['id'] ?? '';
|
||||
$tableFieldName = $tableField['name'] ?? $tableFieldId;
|
||||
|
||||
// Extract value
|
||||
$fieldValue = '(empty)';
|
||||
if (isset($tableField['values']) && !empty($tableField['values'])) {
|
||||
$tabularValues = [];
|
||||
foreach ($tableField['values'] as $value) {
|
||||
if (isset($value['value']['value'])) {
|
||||
$tabularValues[] = $value['value']['value'];
|
||||
} elseif (isset($value['value']['display_value'])) {
|
||||
$tabularValues[] = $value['value']['display_value'];
|
||||
}
|
||||
}
|
||||
if (!empty($tabularValues)) {
|
||||
$fieldValue = $tabularValues;
|
||||
}
|
||||
}
|
||||
|
||||
$metadata['creativex_fields'][$tableFieldName] = [
|
||||
'id' => $tableFieldId,
|
||||
'value' => $fieldValue
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// Direct field
|
||||
$fieldValue = null;
|
||||
if (isset($creativexItem['value']['value']['value'])) {
|
||||
$fieldValue = $creativexItem['value']['value']['value'];
|
||||
} elseif (isset($creativexItem['value']['value']['field_value']['value'])) {
|
||||
$fieldValue = $creativexItem['value']['value']['field_value']['value'];
|
||||
}
|
||||
|
||||
$metadata['creativex_fields'][$itemName] = [
|
||||
'id' => $itemId,
|
||||
'value' => $fieldValue ?? '(empty)'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Found CREATIVEX category, no need to check other categories
|
||||
continue;
|
||||
}
|
||||
|
||||
// Also check individual fields within other categories
|
||||
if (isset($category['metadata_element_list'])) {
|
||||
foreach ($category['metadata_element_list'] as $field) {
|
||||
$fieldId = $field['id'] ?? '';
|
||||
$fieldName = $field['name'] ?? $fieldId;
|
||||
|
||||
// Check if this is a CREATIVEX/CREATIX field
|
||||
if (stripos($fieldId, 'CREATIVEX') !== false || stripos($fieldId, 'CREATIX') !== false) {
|
||||
// Check if this individual field is a CREATIVEX field
|
||||
if (stripos($fieldId, 'CREATIVEX') !== false ||
|
||||
stripos($fieldId, 'CREATIX') !== false) {
|
||||
// This might be a parent field with nested tables
|
||||
if (isset($field['metadata_element_list'])) {
|
||||
// It's a parent CREATIX field with nested tables
|
||||
foreach ($field['metadata_element_list'] as $nestedTable) {
|
||||
$nestedTableId = $nestedTable['id'] ?? '';
|
||||
$nestedTableName = $nestedTable['name'] ?? '';
|
||||
|
||||
if (isset($nestedTable['metadata_element_list'])) {
|
||||
// Nested table fields
|
||||
foreach ($nestedTable['metadata_element_list'] as $nestedField) {
|
||||
|
|
@ -126,17 +194,19 @@ class MetadataExtractor
|
|||
}
|
||||
if (!empty($tabularValues)) {
|
||||
$fieldValue = $tabularValues;
|
||||
} else {
|
||||
// Values array exists but is empty
|
||||
$fieldValue = '(empty)';
|
||||
}
|
||||
} elseif (isset($nestedField['value']['value']['value'])) {
|
||||
$fieldValue = $nestedField['value']['value']['value'];
|
||||
}
|
||||
|
||||
if ($fieldValue !== null) {
|
||||
$metadata['creativex_fields'][$nestedFieldName] = [
|
||||
'id' => $nestedFieldId,
|
||||
'value' => $fieldValue
|
||||
];
|
||||
}
|
||||
// Add ALL CREATIVEX fields, even if empty (shows what fields exist)
|
||||
$metadata['creativex_fields'][$nestedFieldName] = [
|
||||
'id' => $nestedFieldId,
|
||||
'value' => $fieldValue ?? '(not set)'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -152,12 +222,11 @@ class MetadataExtractor
|
|||
$fieldValue = $field['value']['value']['field_value']['value'];
|
||||
}
|
||||
|
||||
if ($fieldValue !== null) {
|
||||
$metadata['creativex_fields'][$fieldName] = [
|
||||
'id' => $fieldId,
|
||||
'value' => $fieldValue
|
||||
];
|
||||
}
|
||||
// Add field even if value is null/empty (shows structure exists)
|
||||
$metadata['creativex_fields'][$fieldName] = [
|
||||
'id' => $fieldId,
|
||||
'value' => $fieldValue ?? '(empty)'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
test_creativex.php
Normal file
35
test_creativex.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
require_once 'src/MetadataExtractor.php';
|
||||
|
||||
$assetJson = file_get_contents('downloads/06_RAFFAELLO_MAESTRO_SD_metadata.json');
|
||||
$asset = json_decode($assetJson, true);
|
||||
|
||||
// Find CREATIX/CREATIVEX in metadata
|
||||
echo "Searching for CREATIVEX fields..." . PHP_EOL . PHP_EOL;
|
||||
|
||||
if (isset($asset['metadata']['metadata_element_list'])) {
|
||||
foreach ($asset['metadata']['metadata_element_list'] as $catIndex => $category) {
|
||||
$catId = $category['id'] ?? 'no-id';
|
||||
$catName = $category['name'] ?? 'no-name';
|
||||
|
||||
if (stripos($catId, 'CREATIX') !== false || stripos($catId, 'CREATIVEX') !== false ||
|
||||
stripos($catName, 'CreativeX') !== false) {
|
||||
echo "Found Category #{$catIndex}:" . PHP_EOL;
|
||||
echo " ID: {$catId}" . PHP_EOL;
|
||||
echo " Name: {$catName}" . PHP_EOL;
|
||||
echo " Structure:" . PHP_EOL;
|
||||
echo json_encode($category, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test extraction
|
||||
$metadata = MetadataExtractor::extractAllMetadata($asset);
|
||||
echo "Extracted CREATIVEX fields: " . count($metadata['creativex_fields']) . PHP_EOL;
|
||||
|
||||
if (!empty($metadata['creativex_fields'])) {
|
||||
foreach ($metadata['creativex_fields'] as $name => $data) {
|
||||
$val = is_array($data['value']) ? implode(', ', $data['value']) : $data['value'];
|
||||
echo " - {$name}: {$val}" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue