![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/ |
# Additional Bugs Found - Similar to Title Saving Issues
## Summary
After fixing the title saving bugs, I audited for similar issues with other fields. Found several additional bugs where fields are not consistently extracted or saved across all callback formats.
---
## 🟡 Bug #1: Duration Not Extracted in `task_id` and `id` Callback Formats
**Location:** `callback.php` lines 311-422 and 448-482
**Issue:** Duration is only extracted in the `callbackType === 'complete'` handler (line 633), but not in:
- `task_id` format handler (line 311)
- `id` format handler (line 448)
**Current Code:**
```php
// task_id handler - NO duration extraction
updateMusicTrack($taskId, $status, $localAudioUrl ?: $audioUrl, $localVideoUrl ?: $videoUrl, $lyrics, $metadata, null, $title);
// id handler - NO duration extraction
updateMusicTrack($taskId, $status, $localAudioUrl ?: $audioUrl, $localVideoUrl ?: $videoUrl, null, $metadata, null, $title);
```
**Missing Logic:**
- Duration should be extracted from `$data['duration']` or `$data['data']['data'][0]['duration']`
- Duration should be passed to `updateMusicTrack` function
**Impact:** MEDIUM - Duration is important metadata but may be missing in some callback formats.
---
## 🟡 Bug #2: Tags Not Extracted in `task_id` and `id` Callback Formats
**Location:** `callback.php` lines 311-422 and 448-482
**Issue:** Tags are only extracted in the `callbackType === 'complete'` handler (line 638), but not in other formats.
**Current Code:**
```php
// task_id handler - NO tags extraction
// id handler - NO tags extraction
```
**Missing Logic:**
- Tags should be extracted from `$data['tags']` or `$data['data']['data'][0]['tags']`
- Tags should be saved to the database (either as direct field or in metadata)
**Impact:** LOW-MEDIUM - Tags are stored in metadata, but not as a direct searchable field in some cases.
---
## 🟡 Bug #3: Model Name Not Saved as Direct Field
**Location:** `callback.php` throughout
**Issue:** `model_name` is extracted in metadata (line 209) but never saved as a direct database field. It's only stored in the JSON metadata blob.
**Current Code:**
```php
// In extractComprehensiveMetadata:
'model_name' => $data['model_name'] ?? null,
```
**Missing Logic:**
- `model_name` should be extracted from API response
- Should be saved to `model_version` or similar direct database field
- `updateMusicTrack` function doesn't handle model_name
**Impact:** LOW - Model name is in metadata but not easily queryable.
---
## 🟡 Bug #4: Duration Not Extracted in Early Callbacks (text, first)
**Location:** `callback.php` lines 794-807
**Issue:** When `callbackType` is 'text' or 'first', duration is not extracted even though it might be available in the response.
**Current Code:**
```php
// Other callback types (text, first, etc.) - extract title and update metadata
updateMusicTrack($taskId, 'processing', null, null, null, $metadata, null, $title);
// NO duration extraction
```
**Impact:** LOW - Early callbacks may not have duration, but if they do, it should be saved.
---
## 🟡 Bug #5: Inconsistent Field Extraction Pattern
**Issue:** Different callback handlers extract different fields:
- `task_id` handler: extracts lyrics, title
- `id` handler: extracts title only
- `callbackType === 'complete'`: extracts title, duration, tags
- Other `callbackType` handlers: extracts title only
**Impact:** MEDIUM - Inconsistent data extraction leads to missing fields depending on which callback format is received.
---
## 📋 Recommended Fixes
### Fix #1: Create Helper Functions for Common Fields
```php
// Extract duration from various API response formats
function extractDurationFromCallback($data) {
if (isset($data['duration']) && !empty($data['duration'])) {
return floatval($data['duration']);
}
if (isset($data['data']['duration']) && !empty($data['data']['duration'])) {
return floatval($data['data']['duration']);
}
if (isset($data['data']['data']) && is_array($data['data']['data'])) {
foreach ($data['data']['data'] as $item) {
if (isset($item['duration']) && !empty($item['duration'])) {
return floatval($item['duration']);
}
}
}
return null;
}
// Extract tags from various API response formats
function extractTagsFromCallback($data) {
if (isset($data['tags']) && !empty($data['tags'])) {
return is_array($data['tags']) ? $data['tags'] : [$data['tags']];
}
if (isset($data['data']['tags']) && !empty($data['data']['tags'])) {
return is_array($data['data']['tags']) ? $data['data']['tags'] : [$data['data']['tags']];
}
if (isset($data['data']['data']) && is_array($data['data']['data'])) {
foreach ($data['data']['data'] as $item) {
if (isset($item['tags']) && !empty($item['tags'])) {
return is_array($item['tags']) ? $item['tags'] : [$item['tags']];
}
}
}
return null;
}
// Extract model_name from various API response formats
function extractModelNameFromCallback($data) {
if (isset($data['model_name']) && !empty($data['model_name'])) {
return sanitizeDOMText($data['model_name']);
}
if (isset($data['data']['model_name']) && !empty($data['data']['model_name'])) {
return sanitizeDOMText($data['data']['model_name']);
}
if (isset($data['data']['data']) && is_array($data['data']['data'])) {
foreach ($data['data']['data'] as $item) {
if (isset($item['model_name']) && !empty($item['model_name'])) {
return sanitizeDOMText($item['model_name']);
}
}
}
return null;
}
```
### Fix #2: Update All Callback Handlers
Add consistent field extraction to ALL callback handlers:
- Extract duration in all handlers
- Extract tags in all handlers
- Extract model_name in all handlers
- Pass all extracted fields to `updateMusicTrack`
### Fix #3: Enhance `updateMusicTrack` Function
Add parameters for commonly extracted fields:
```php
function updateMusicTrack($taskId, $status, $audioUrl = null, $videoUrl = null, $lyrics = null, $metadata = null, $duration = null, $title = null, $tags = null, $modelName = null)
```
---
## 🎯 Priority
1. **MEDIUM:** Fix duration extraction in `task_id` and `id` handlers
2. **LOW-MEDIUM:** Fix tags extraction in all handlers
3. **LOW:** Extract and save model_name as direct field
4. **LOW:** Extract duration in early callbacks if available
---
## 📝 Files Affected
- `callback.php` - All callback handlers need consistent field extraction
- `config/database.php` - `updateMusicTrack` function may need additional parameters
---
## 🔗 Related Code References
- Duration extraction (working): `callback.php:633`
- Tags extraction (working): `callback.php:638`
- Model name in metadata: `callback.php:209`
- Title extraction helper: `callback.php:82-111` (newly added)