![]() 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/public_html/ |
# API.Box Create Music - Title Saving Bugs Audit
## Executive Summary
This audit identifies critical bugs where titles (and potentially other metadata) from API.Box callbacks are not being saved to the database. The issue affects multiple callback format handlers in `callback.php`.
---
## 🔴 Critical Bug #1: Title Not Saved in `task_id` Callback Format
**Location:** `callback.php` lines 279-408
**Issue:** When the callback uses `task_id` format, the title is never extracted or saved, even if it exists in the API response.
**Current Code:**
```php
if (isset($data['task_id'])) {
$taskId = $data['task_id'];
$status = $data['status'] ?? 'unknown';
// ... extracts lyrics but NOT title ...
// Updates track but title is never extracted or saved
updateMusicTrack($taskId, $status, $localAudioUrl ?: $audioUrl, $localVideoUrl ?: $videoUrl, $lyrics, $metadata);
}
```
**Missing Logic:**
- No extraction of `title` from `$data['title']` or `$data['data']['data'][0]['title']`
- No database update for title field
- Title from API response is completely ignored
**Impact:** HIGH - This is a common callback format and titles are lost.
---
## 🔴 Critical Bug #2: Title Not Saved in `id` Callback Format
**Location:** `callback.php` lines 410-462
**Issue:** When the callback uses `id` format (alternative format), the title is never extracted or saved.
**Current Code:**
```php
} elseif (isset($data['id'])) {
$taskId = $data['id'];
$status = $data['status'] ?? 'unknown';
// ... no title extraction ...
// Updates track but title is never extracted or saved
updateMusicTrack($taskId, $status, $localAudioUrl ?: $audioUrl, $localVideoUrl ?: $videoUrl, null, $metadata);
}
```
**Missing Logic:**
- No extraction of `title` from any location in the response
- No database update for title field
**Impact:** HIGH - Alternative callback format, titles are lost.
---
## 🟡 Bug #3: Title Only Saved in One Specific Callback Format
**Location:** `callback.php` lines 565-606
**Issue:** Title extraction and saving ONLY happens in the `callbackType === 'complete'` branch with `code == 200`. Other callback types ('text', 'first', etc.) don't save titles.
**Current Code:**
```php
if ($callbackType === 'complete' && !empty($audioData)) {
// ... title extraction happens here ...
if ($title) {
$stmt = $pdo->prepare("UPDATE music_tracks SET title = ? WHERE task_id = ?");
$stmt->execute([$title, $taskId]);
}
} else {
// Other callback types (text, first, etc.) - just update metadata
// NO TITLE EXTRACTION OR SAVING
updateMusicTrack($taskId, 'processing', null, null, null, $metadata);
}
```
**Missing Logic:**
- Title extraction should happen for ALL callback types, not just 'complete'
- Early callbacks ('text', 'first') may contain titles that should be saved immediately
**Impact:** MEDIUM - Titles might be available in early callbacks but are ignored.
---
## 🟡 Bug #4: Incomplete Title Extraction Logic
**Location:** `callback.php` lines 579-595
**Issue:** Title extraction only checks `$audio['title']` from the first audio item in the array. Titles might exist in other locations in the API response.
**Current Code:**
```php
foreach ($audioData as $audio) {
$audioUrl = $audio['audio_url'] ?? $audio['source_audio_url'] ?? $audio['stream_audio_url'] ?? null;
if (!empty($audioUrl)) {
$duration = $audio['duration'] ?? null;
$title = $audio['title'] ?? null; // Only checks one location
// ... breaks after first audio URL found ...
}
}
```
**Missing Logic:**
- Should also check: `$data['title']`, `$data['data']['title']`, `$data['data']['data'][0]['title']`
- Should check all audio items, not just the first one with a URL
- Should have fallback extraction similar to lyrics extraction (lines 286-335)
**Impact:** MEDIUM - Some titles might be in different response locations.
---
## 🟡 Bug #5: `updateMusicTrack` Function Doesn't Accept Title Parameter
**Location:** `config/database.php` lines 681-836
**Issue:** The `updateMusicTrack` function signature doesn't include a `$title` parameter, so titles cannot be passed through this centralized function.
**Current Function Signature:**
```php
function updateMusicTrack($taskId, $status, $audioUrl = null, $videoUrl = null, $lyrics = null, $metadata = null, $duration = null)
```
**Missing:**
- `$title = null` parameter
- Logic to update title field in the database
- Title extraction from metadata if provided
**Impact:** MEDIUM - Forces title updates to be done separately, increasing code duplication and potential for errors.
---
## 🟠 Bug #6: Similar Issues with Other Fields
**Location:** Multiple locations in `callback.php`
**Issue:** Similar to titles, other fields might not be extracted or saved consistently:
1. **Tags:** Only extracted in `callbackType === 'complete'` branch (line 586), not in other formats
2. **Duration:** Extracted but might not be saved in all callback formats
3. **Model Name:** Not extracted from API response at all
4. **Genre/Style:** Only saved via metadata, not as direct fields
**Impact:** LOW-MEDIUM - Metadata is saved, but individual fields might be missing.
---
## 📋 Recommended Fixes
### Fix #1: Add Title Extraction Helper Function
Create a reusable function to extract titles from various API response formats:
```php
function extractTitleFromCallback($data) {
// Check multiple possible locations
if (isset($data['title']) && !empty($data['title'])) {
return sanitizeDOMText($data['title']);
}
if (isset($data['data']['title']) && !empty($data['data']['title'])) {
return sanitizeDOMText($data['data']['title']);
}
if (isset($data['data']['data']) && is_array($data['data']['data'])) {
foreach ($data['data']['data'] as $item) {
if (isset($item['title']) && !empty($item['title'])) {
return sanitizeDOMText($item['title']);
}
}
}
return null;
}
```
### Fix #2: Update All Callback Handlers
Add title extraction and saving to ALL callback format handlers:
- `task_id` format handler (line 279)
- `id` format handler (line 410)
- All `callbackType` handlers (line 513+)
### Fix #3: Enhance `updateMusicTrack` Function
Add `$title = null` parameter and update logic:
```php
function updateMusicTrack($taskId, $status, $audioUrl = null, $videoUrl = null, $lyrics = null, $metadata = null, $duration = null, $title = null) {
// ... existing code ...
if ($title !== null) {
$updates[] = 'title = ?';
$params[] = $title;
}
// ... rest of function ...
}
```
### Fix #4: Extract Title Early and Save Immediately
Extract and save titles as soon as they're available in ANY callback, not just 'complete' callbacks.
---
## 🔍 Testing Checklist
- [ ] Test callback with `task_id` format - verify title is saved
- [ ] Test callback with `id` format - verify title is saved
- [ ] Test callback with `callbackType: 'text'` - verify title is saved if present
- [ ] Test callback with `callbackType: 'first'` - verify title is saved if present
- [ ] Test callback with `callbackType: 'complete'` - verify title is saved (already works)
- [ ] Test with title in `data.title` location
- [ ] Test with title in `data.data[0].title` location
- [ ] Test with title in `data.data.data[0].title` location
- [ ] Verify existing titles are not overwritten with empty/null values
- [ ] Test with special characters in titles (apostrophes, quotes, etc.)
---
## 📊 Similar Bugs to Check
Based on the title bug pattern, also audit:
1. **Tags extraction** - Only in one callback format?
2. **Duration extraction** - Consistent across all formats?
3. **Model name extraction** - Is it extracted at all?
4. **Genre/Style extraction** - Are they saved as direct fields?
5. **Image URL extraction** - Is it saved for variations?
6. **Source audio URL** - Is it saved for cover/extend operations?
---
## 🎯 Priority
1. **HIGH:** Fix title extraction in `task_id` and `id` callback formats
2. **MEDIUM:** Add title parameter to `updateMusicTrack` function
3. **MEDIUM:** Improve title extraction to check all possible locations
4. **LOW:** Audit and fix similar issues with other fields (tags, duration, etc.)
---
## 📝 Files Affected
- `callback.php` - Multiple callback handlers need title extraction
- `config/database.php` - `updateMusicTrack` function needs title parameter
- Potentially: Any file that calls `updateMusicTrack` and should pass titles
---
## 🔗 Related Code References
- Title extraction (working): `callback.php:579-606`
- Lyrics extraction (good example): `callback.php:286-335`
- `updateMusicTrack` function: `config/database.php:681-836`
- Track creation with title: `create_music.php:206-210`