fix: add missing cost tracker methods + guard logger against null wpdb

- Add `would_exceed_budget(float)` to pre-check budget before API calls
- Add `log_image_generation()` for image pipeline cost logging
- Guard Logger::log() against null $wpdb in unit test environments
- Both methods called by image pipeline (commit 1b) but were missing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-16 16:57:21 +07:00
parent 2e41c3f2f6
commit f88d752a79
2 changed files with 64 additions and 0 deletions

View File

@@ -126,6 +126,11 @@ class PRAutoBlogger_Logger {
}
global $wpdb;
if ( null === $wpdb ) {
// No database available (unit test environment). PHP error_log
// was already called above for warnings/errors; silently skip DB write.
return;
}
$table = $wpdb->prefix . 'prautoblogger_event_log';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery