ferrero-opentext/config_v3.php
DJP 156f9ae51d Fix status updates and enhance workflow with proper error handling
Major improvements to workflow_v3.php and supporting classes:

**Status Updates (A1→A2, A2→A3, A5→A6):**
- Fix StatusManager to use correct PATCH endpoint: /v6/folders/{id}
- Add lock_strategy=optimistic parameter to prevent locking errors
- Update request body structure to use edited_folder format
- Status updates now working correctly

**Status Field Extraction:**
- Fix CampaignFormatter to extract CONTENT.SCALING.STATUS field
- Handle domain values with field_value.value path
- Now correctly filters campaigns by status (A1, A2, A5, etc.)

**Error Handling:**
- Extract and display actual API error messages
- Show HTTP status codes in all error messages
- Add expandable debug panels with full API responses
- Enhanced upload error reporting with detailed diagnostics

**Campaign Search:**
- Update to use Postman collection requests directly (avoids 503 errors)
- Fix URL encoding (rawurlencode instead of urlencode)
- Add comprehensive debug output showing OAuth status and API responses
- Search now attempts Postman request first, falls back to manual query

**Upload Improvements:**
- Rewrite AssetUploader to use native PHP CURLFile for multipart uploads
- Add support for additional file types: .mov, .mp4, .avi, .zip, .txt, .doc, .xlsx
- Increase max upload size to 100MB for video files
- Simplify asset_representation to minimal structure
- Add infrastructure to inherit metadata from master assets

**Testing Features:**
- Add "Reset to A1" button for testing workflow iterations
- Add debug mode to view all campaigns and their metadata
- Show Content Scaling Status on all campaign cards
- Display filtering debug info (total vs filtered counts)

**UI Improvements:**
- Rename buttons to clarify "Content Scaling Status" terminology
- Add status badges to campaign cards showing current status
- Better visual feedback for successful/failed operations

Current Status: Workflow A1→A2 fully working. Upload A2→A3 ready for testing
once DAM server recovers from HTTP 503 errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 16:43:09 -04:00

262 lines
7.6 KiB
PHP

<?php
/**
* Configuration for Content Scaling Workflow V3
* Supports multiple environments (test/production) with easy switching
*/
class ConfigV3
{
private $config;
private $activeEnvironment;
public function __construct($environment = null)
{
$this->loadConfig();
$this->activeEnvironment = $environment ?? $this->config['active_environment'];
}
private function loadConfig()
{
$this->config = [
// Environment configurations
'environments' => [
'test' => [
'baseUrl' => 'https://test.dam.ferrero.com/otmmapi',
'authUrl' => 'https://test.dam.ferrero.com/otdsws/oauth2/token',
'description' => 'Test Environment'
],
'production' => [
'baseUrl' => 'https://ppr.dam.ferrero.com/otmmapi',
'authUrl' => 'https://ppr.dam.ferrero.com/otdsws/oauth2/token',
'description' => 'Production Environment'
]
],
// Active environment (switch between 'test' and 'production')
'active_environment' => 'production',
// Postman collection file (using old working collection with OAuth2 configured)
'postman_collection' => 'Content Scaling Flow.postman_collection_Oliver(New).json',
// Credentials file
'credentials_file' => 'Creds.txt',
// Folder names (consistent across environments)
'folder_names' => [
'master_assets' => '01. Master Assets',
'final_assets' => '01. Final Assets',
'localized_assets' => 'Localized Assets'
],
// Status field configuration
'status_field' => [
'field_id' => 'CONTENT.SCALING.STATUS',
'field_name' => 'Content Scaling Status',
'values' => [
'A0' => 'Local Campaign Created',
'A1' => 'Local Campaign ready for localization',
'A2' => 'Selected Master Assets sent to Agency',
'A3' => 'Localized Asset received from Agency',
'A4' => 'Localization completed',
'A5' => 'Rework needed from agency',
'A6' => 'Assets to be reworked received by the Agency',
'B1' => 'Master campaign ready for re-mastering',
'B2' => 'Master campaign received from Agency'
]
],
// Download configuration
'downloads' => [
'base_path' => 'downloads',
'organize_by_campaign' => true,
'preserve_metadata' => true
],
// Upload configuration
'uploads' => [
'allowed_extensions' => ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'ai', 'psd', 'eps', 'tif', 'tiff', 'mov', 'mp4', 'avi', 'zip', 'txt', 'doc', 'docx', 'xls', 'xlsx'],
'max_file_size' => 100 * 1024 * 1024, // 100MB (for video files)
'preserve_filenames' => true
],
// API settings
'api' => [
'timeout' => 120,
'retry_attempts' => 3,
'retry_delay' => 2
],
// Logging
'logging' => [
'enabled' => true,
'log_dir' => 'logs',
'log_file' => 'workflow_v3.log',
'log_level' => 'INFO'
]
];
}
/**
* Get configuration value by key (supports dot notation)
*/
public function get($key = null)
{
if ($key === null) {
return $this->config;
}
$keys = explode('.', $key);
$value = $this->config;
foreach ($keys as $k) {
if (isset($value[$k])) {
$value = $value[$k];
} else {
return null;
}
}
return $value;
}
/**
* Get current environment configuration
*/
public function getEnvironment()
{
return $this->config['environments'][$this->activeEnvironment] ?? null;
}
/**
* Get base URL for current environment
*/
public function getBaseUrl()
{
$env = $this->getEnvironment();
return $env['baseUrl'] ?? '';
}
/**
* Get auth URL for current environment
*/
public function getAuthUrl()
{
$env = $this->getEnvironment();
return $env['authUrl'] ?? '';
}
/**
* Get active environment name
*/
public function getActiveEnvironment()
{
return $this->activeEnvironment;
}
/**
* Switch environment
*/
public function switchEnvironment($environment)
{
if (!isset($this->config['environments'][$environment])) {
throw new Exception("Invalid environment: {$environment}");
}
$this->activeEnvironment = $environment;
}
/**
* Get status description by code
*/
public function getStatusDescription($statusCode)
{
return $this->config['status_field']['values'][$statusCode] ?? 'Unknown Status';
}
/**
* Get all status codes
*/
public function getAllStatuses()
{
return $this->config['status_field']['values'];
}
/**
* Get folder name by type
*/
public function getFolderName($type)
{
return $this->config['folder_names'][$type] ?? null;
}
/**
* Get download path for campaign
*/
public function getDownloadPath($campaignId, $subFolder = '')
{
$basePath = $this->config['downloads']['base_path'];
if ($this->config['downloads']['organize_by_campaign']) {
$path = $basePath . '/' . $campaignId;
if ($subFolder) {
$path .= '/' . $subFolder;
}
return $path;
}
return $basePath;
}
/**
* Validate configuration
*/
public function validate()
{
$errors = [];
// Check if active environment exists
if (!isset($this->config['environments'][$this->activeEnvironment])) {
$errors[] = "Active environment '{$this->activeEnvironment}' not configured";
}
// Check if Postman collection exists
$collectionPath = $this->config['postman_collection'];
if (!file_exists($collectionPath)) {
$errors[] = "Postman collection not found: {$collectionPath}";
}
// Check if credentials file exists
$credsFile = $this->config['credentials_file'];
if (!file_exists($credsFile)) {
$errors[] = "Credentials file not found: {$credsFile}";
}
// Check download directory
$downloadPath = $this->config['downloads']['base_path'];
if (!is_dir($downloadPath) && !mkdir($downloadPath, 0755, true)) {
$errors[] = "Cannot create download directory: {$downloadPath}";
}
// Check log directory
$logDir = $this->config['logging']['log_dir'];
if (!is_dir($logDir) && !mkdir($logDir, 0755, true)) {
$errors[] = "Cannot create log directory: {$logDir}";
}
return $errors;
}
/**
* Get environment info for display
*/
public function getEnvironmentInfo()
{
$env = $this->getEnvironment();
return [
'name' => $this->activeEnvironment,
'description' => $env['description'] ?? '',
'baseUrl' => $env['baseUrl'] ?? '',
'authUrl' => $env['authUrl'] ?? ''
];
}
}