leads.csv * * Contains personal data — store the output securely and delete when done. */ declare(strict_types=1); if (PHP_SAPI !== 'cli') { http_response_code(404); exit; } require_once dirname(__DIR__) . '/lib/bootstrap.php'; $since = null; foreach ($argv as $arg) { if (str_starts_with($arg, '--since=')) { $since = substr($arg, 8); } } $sql = 'SELECT submission_id, created_at, first_name, last_name, email, phone_e164, campus_id, visit_date, service_time, adults, children, child_age_ranges, questions, email_consent, sms_consent, consent_version, consent_at, variant, attribution, mailchimp_status, sms_status FROM leads'; $params = []; if ($since) { $sql .= ' WHERE created_at >= ?'; $params[] = $since; } $sql .= ' ORDER BY created_at ASC'; $st = Db::pdo()->prepare($sql); $st->execute($params); $out = fopen('php://stdout', 'w'); $first = true; while ($row = $st->fetch()) { if ($first) { fputcsv($out, array_keys($row)); $first = false; } fputcsv($out, $row); }