$dbConfig */ $dbConfig = require $basePath . '/config/database.php'; $dryRun = in_array('--dry-run', $argv, true); $useRemote = in_array('--use-remote', $argv, true); if ($useRemote) { $remoteHost = (string) Env::get('DB_HOST_REMOTE', ''); if ($remoteHost !== '') { $dbConfig['host'] = $remoteHost; echo '[db] using DB_HOST_REMOTE for this run' . PHP_EOL; } } $pdo = ConnectionFactory::make($dbConfig); echo 'Backfill 111: orders nieoplacone + payment_status=2 -> w_realizacji' . PHP_EOL; echo $dryRun ? '[mode] dry-run' . PHP_EOL : '[mode] apply' . PHP_EOL; const TARGET_CODE = 'w_realizacji'; $repository = new OrdersRepository($pdo); $sql = "SELECT id, internal_order_number, source, integration_id " . "FROM orders " . "WHERE source IN ('allegro', 'shoppro') " . "AND payment_status = 2 " . "AND LOWER(COALESCE(status_code, '')) = 'nieoplacone' " . "ORDER BY id ASC"; $stmt = $pdo->prepare($sql); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; $total = count($rows); $updated = 0; $skipped = 0; echo '[scan] candidates: ' . $total . PHP_EOL; foreach ($rows as $row) { $orderId = (int) $row['id']; $internalNumber = (string) ($row['internal_order_number'] ?? ''); $source = (string) ($row['source'] ?? ''); $integrationId = (int) ($row['integration_id'] ?? 0); $label = sprintf('#%d %s (source=%s, integration=%d)', $orderId, $internalNumber, $source, $integrationId); if ($dryRun) { echo ' [dry-run] ' . $label . ' -> ' . TARGET_CODE . PHP_EOL; continue; } try { $ok = $repository->updateOrderStatus( $orderId, TARGET_CODE, 'import', 'Backfill 111' ); if ($ok) { $updated++; echo ' [ok] ' . $label . ' -> ' . TARGET_CODE . PHP_EOL; } else { $skipped++; echo ' [skip] ' . $label . ' (updateOrderStatus returned false)' . PHP_EOL; } } catch (Throwable $exception) { $skipped++; fwrite(STDERR, ' [err] ' . $label . ': ' . $exception->getMessage() . PHP_EOL); } } echo PHP_EOL; echo 'Backfill 111: total=' . $total . ' updated=' . $updated . ' skipped=' . $skipped . PHP_EOL; echo 'Done.' . PHP_EOL;