Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3. Shared helpers in api/helpers.php (DB, auth, request/response, security). PDO prepared statements throughout. Same JSON response shapes as CFML.
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Clear ALL orders, line items, tasks, and non-business addresses
|
|
*
|
|
* POST body: { "confirm": "NUKE_ORDERS" }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$confirm = $data['confirm'] ?? '';
|
|
|
|
if ($confirm !== 'NUKE_ORDERS') {
|
|
jsonResponse(['OK' => false, 'ERROR' => "Must pass confirm: 'NUKE_ORDERS' to proceed"]);
|
|
}
|
|
|
|
try {
|
|
// Get counts before deletion
|
|
$lineItemCount = queryOne("SELECT COUNT(*) as cnt FROM OrderLineItems");
|
|
$orderCount = queryOne("SELECT COUNT(*) as cnt FROM Orders");
|
|
$addressCount = queryOne("SELECT COUNT(*) as cnt FROM Addresses WHERE AddressTypeID != 2");
|
|
$taskCount = queryOne("SELECT COUNT(*) as cnt FROM Tasks");
|
|
|
|
// Delete in correct order (foreign key constraints)
|
|
queryTimed("DELETE FROM Tasks");
|
|
queryTimed("DELETE FROM OrderLineItems");
|
|
queryTimed("DELETE FROM Orders");
|
|
queryTimed("DELETE FROM Addresses WHERE AddressTypeID != 2");
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'deleted' => [
|
|
'tasks' => (int) $taskCount['cnt'],
|
|
'lineItems' => (int) $lineItemCount['cnt'],
|
|
'orders' => (int) $orderCount['cnt'],
|
|
'addresses' => (int) $addressCount['cnt'],
|
|
],
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => $e->getMessage(), 'DETAIL' => '']);
|
|
}
|