feat(automations): add run-now test endpoint and sends log table
Enable immediate automation test runs without waiting for the scheduled hour, expose send history for debugging, and return all SuperAdmin overlay keys on refresh instead of only enable_automation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Automation;
|
||||
use App\Models\AutomationSend;
|
||||
use App\Services\Automation\AutomationCatalog;
|
||||
use App\Services\Automation\AutomationEngine;
|
||||
use App\Services\Automation\AutomationFingerprint;
|
||||
@@ -89,6 +90,49 @@ class AutomationController extends Controller
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
/** اجرای فوری برای تست — بدون انتظار ساعت cron */
|
||||
public function runNow(Request $request, $id)
|
||||
{
|
||||
$this->assertFeatureEnabled();
|
||||
$row = Automation::query()->findOrFail($id);
|
||||
$force = $request->boolean('force', true);
|
||||
$stats = app(AutomationEngine::class)->runNow($row, $force);
|
||||
|
||||
return response()->json([
|
||||
'message' => sprintf(
|
||||
'مخاطب %d — ارسال موفق %d، ناموفق %d، ردشده %d',
|
||||
$stats['audience'],
|
||||
$stats['sent'],
|
||||
$stats['failed'],
|
||||
$stats['skipped']
|
||||
),
|
||||
...$stats,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendsTable(Request $request, $id)
|
||||
{
|
||||
$this->assertFeatureEnabled();
|
||||
Automation::query()->findOrFail($id);
|
||||
|
||||
$query = AutomationSend::query()
|
||||
->where('automation_id', (int) $id)
|
||||
->leftJoin('customers', 'customers.id', '=', 'automation_sends.customer_id')
|
||||
->select([
|
||||
'automation_sends.*',
|
||||
'customers.name as customer_name',
|
||||
'customers.mobile as customer_mobile',
|
||||
])
|
||||
->orderByDesc('automation_sends.id');
|
||||
|
||||
TableEngine::create($query, $request->all())
|
||||
->initSearch(['customers.name', 'customers.mobile', 'automation_sends.status', 'automation_sends.error'])
|
||||
->select(['automation_sends.*', 'customers.name as customer_name', 'customers.mobile as customer_mobile'])
|
||||
->export($query);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function assertFeatureEnabled(): void
|
||||
{
|
||||
if (! app(ConfigService::class)->isAutomationEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user