- admin/quickTasks: list, create, save, delete - admin/scheduledTasks: list, save, delete, toggle, run, runDue - cron: expireStaleChats, expireTabs - receipt: public order receipt page (no auth, UUID-secured) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Manually trigger a scheduled task (creates a task without updating next run time).
|
|
* POST: { BusinessID, ScheduledTaskID }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$businessID = (int) ($data['BusinessID'] ?? headerValue('X-Business-ID') ?? 0);
|
|
$scheduledTaskID = (int) ($data['ScheduledTaskID'] ?? 0);
|
|
|
|
if ($businessID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'BusinessID is required']);
|
|
}
|
|
if ($scheduledTaskID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'ScheduledTaskID is required']);
|
|
}
|
|
|
|
try {
|
|
$def = queryOne("
|
|
SELECT Title, Details, TaskCategoryID AS CategoryID
|
|
FROM ScheduledTaskDefinitions
|
|
WHERE ID = ? AND BusinessID = ?
|
|
", [$scheduledTaskID, $businessID]);
|
|
|
|
if (!$def) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Scheduled task not found']);
|
|
}
|
|
|
|
queryTimed("
|
|
INSERT INTO Tasks (BusinessID, CategoryID, TaskTypeID, Title, Details, CreatedOn, ClaimedByUserID)
|
|
VALUES (?, ?, 0, ?, ?, NOW(), 0)
|
|
", [$businessID, $def['CategoryID'], $def['Title'], $def['Details']]);
|
|
|
|
$taskID = (int) lastInsertId();
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'TASK_ID' => $taskID,
|
|
'MESSAGE' => 'Task created from scheduled task (manual trigger)',
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]);
|
|
}
|