<?php
/**
 * Print the site's dynamic route paths as a JSON array, so the QA crawler knows
 * the full URL set (the sitemap is incomplete). Static pages are hard-coded in
 * the crawler; this covers DB-driven slugs.
 *
 *   php api/cli/qa-routes.php   ->  ["/projects/foo","/projects/bar", ...]
 */

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../config.php';

$pdo = new PDO(
    sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', DB_HOST, DB_NAME),
    DB_USER,
    DB_PASS,
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_COLUMN]
);

$routes = [];
// Published project case-study pages.
foreach ($pdo->query("SELECT slug FROM cja_projects WHERE published = 1") as $slug) {
    if ($slug !== '') $routes[] = "/projects/{$slug}";
}

echo json_encode(array_values($routes), JSON_UNESCAPED_SLASHES);
