<?php

require_once __DIR__ . '/../app/auth.php';
require_once __DIR__ . '/../app/layout.php';
require_once __DIR__ . '/../app/pricing.php';

$user = sparrow_require_backyard_login();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    sparrow_redirect('/backyard/pricing.php');
}

try {
    $count = sparrow_bundle_pricing_rows_in_database();

    sparrow_redirect('/backyard/pricing.php?bundled=' . (int) $count);
} catch (Throwable $e) {
    sparrow_redirect('/backyard/pricing.php?bundle_error=' . urlencode($e->getMessage()));
}