663fde3909
Full source for loveandrosary.com: slide-based Rosary/novena/Divine Mercy Chaplet presentation tool with multi-user roles, SVG bead ring, audio uploads, donate strip, and public session profiles. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
118 lines
4.3 KiB
PHP
118 lines
4.3 KiB
PHP
<?php
|
|
/**
|
|
* migrate_v2.php — One-time database migration.
|
|
* Run once in the browser, then DELETE this file from the server.
|
|
*
|
|
* What it does:
|
|
* 1. Creates the novena_groups table
|
|
* 2. Adds novena_group_id column to sessions
|
|
* 3. Groups any existing novena day sessions under novena_group records
|
|
*/
|
|
require_once __DIR__ . '/config/db.php';
|
|
|
|
$pdo = get_pdo();
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$log = [];
|
|
|
|
// -----------------------------------------------------------------------
|
|
// 1. Create novena_groups table
|
|
// -----------------------------------------------------------------------
|
|
$pdo->exec("
|
|
CREATE TABLE IF NOT EXISTS novena_groups (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
mystery_set VARCHAR(50) NOT NULL DEFAULT 'sorrowful',
|
|
subject_name VARCHAR(255) NULL,
|
|
subject_pronoun VARCHAR(10) NULL,
|
|
subject_dates VARCHAR(150) NULL,
|
|
photo_path VARCHAR(500) NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
)
|
|
");
|
|
$log[] = 'novena_groups table ready.';
|
|
|
|
// -----------------------------------------------------------------------
|
|
// 2. Add novena_group_id to sessions (silent if already present)
|
|
// -----------------------------------------------------------------------
|
|
try {
|
|
$pdo->exec('ALTER TABLE sessions ADD COLUMN novena_group_id INT NULL');
|
|
$log[] = 'Added novena_group_id column to sessions.';
|
|
} catch (PDOException $e) {
|
|
$log[] = 'novena_group_id column already exists — skipped.';
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// 3. Migrate existing novena sessions that have no group yet
|
|
// -----------------------------------------------------------------------
|
|
$novenas = $pdo->query("
|
|
SELECT * FROM sessions
|
|
WHERE occasion = 'novena_deceased'
|
|
AND (novena_group_id IS NULL OR novena_group_id = 0)
|
|
ORDER BY name, novena_day
|
|
")->fetchAll();
|
|
|
|
if (empty($novenas)) {
|
|
$log[] = 'No ungrouped novena sessions found — nothing to migrate.';
|
|
} else {
|
|
// Bucket sessions by the base name (strip trailing " — Day N")
|
|
$buckets = [];
|
|
foreach ($novenas as $n) {
|
|
$base = preg_replace('/ — Day \d+$/', '', $n['name']);
|
|
$buckets[$base][] = $n;
|
|
}
|
|
|
|
$ins_grp = $pdo->prepare('
|
|
INSERT INTO novena_groups
|
|
(name, mystery_set, subject_name, subject_pronoun, subject_dates, photo_path)
|
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
');
|
|
$upd_ses = $pdo->prepare('UPDATE sessions SET novena_group_id = ? WHERE id = ?');
|
|
|
|
foreach ($buckets as $base_name => $days) {
|
|
$first = $days[0];
|
|
$ins_grp->execute([
|
|
$base_name,
|
|
$first['mystery_set'],
|
|
$first['subject_name'],
|
|
$first['subject_pronoun'],
|
|
$first['subject_dates'],
|
|
$first['photo_path'],
|
|
]);
|
|
$gid = (int)$pdo->lastInsertId();
|
|
foreach ($days as $day) {
|
|
$upd_ses->execute([$gid, $day['id']]);
|
|
}
|
|
$log[] = 'Created group #' . $gid . ' "' . $base_name . '" — ' . count($days) . ' day(s) linked.';
|
|
}
|
|
}
|
|
|
|
?><!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Migrate v2</title>
|
|
<style>
|
|
body { font-family: system-ui, sans-serif; max-width: 640px; margin: 60px auto; padding: 0 24px; color: #1d2027; }
|
|
h1 { color: #2563eb; margin-bottom: 20px; }
|
|
ul { background: #f0fdf4; border: 1px solid #86efac; border-radius: 8px; padding: 16px 16px 16px 36px; margin-bottom: 20px; }
|
|
li { margin-bottom: 6px; }
|
|
.warn { background: #fef3c7; border: 1px solid #fbbf24; border-radius: 8px; padding: 16px; font-weight: 500; }
|
|
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Migration v2 Complete</h1>
|
|
<ul>
|
|
<?php foreach ($log as $line): ?>
|
|
<li><?= htmlspecialchars($line) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<div class="warn">
|
|
⚠ Delete <code>migrate_v2.php</code> from your server now.
|
|
It is no longer needed and should not be left publicly accessible.
|
|
</div>
|
|
</body>
|
|
</html>
|