Add Rosary Builder — custom prayer-sequence sessions
Superuser+ can now build a custom prayer sequence from scratch: - Two-panel builder UI: step sequence (left) + searchable prayer library (right) - 16 standard prayers seeded globally; users can create private custom prayers - Admin can promote private prayers to global and manage the library - Four attribution modes per step: Leader/All, Leader only, All together, None - Optional subject name/pronoun for variable substitution in prayers - Custom sessions fully presented via the existing presenter (auto-split works) - migrate_v4.php creates custom_prayers + builder_steps tables Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+182
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* migrate_v4.php — Adds custom_prayers and builder_steps tables for Rosary Builder.
|
||||
* Seeds standard prayers as global library entries.
|
||||
* Run once in browser, then delete.
|
||||
*/
|
||||
require_once __DIR__ . '/config/db.php';
|
||||
$pdo = get_pdo();
|
||||
$log = [];
|
||||
|
||||
function mig_sql(PDO $pdo, string $label, string $sql, array &$log): void {
|
||||
try {
|
||||
$pdo->exec($sql);
|
||||
$log[] = ['ok', $label];
|
||||
} catch (PDOException $e) {
|
||||
if (in_array($e->errorInfo[1], [1060, 1061, 1050], true)) {
|
||||
$log[] = ['skip', $label . ' (already exists)'];
|
||||
} else {
|
||||
$log[] = ['err', $label . ': ' . $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mig_sql($pdo, 'Create custom_prayers table', "
|
||||
CREATE TABLE IF NOT EXISTS custom_prayers (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
leader_text TEXT,
|
||||
all_text TEXT,
|
||||
is_global TINYINT(1) NOT NULL DEFAULT 0,
|
||||
created_by INT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_global (is_global),
|
||||
INDEX idx_created_by (created_by)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
", $log);
|
||||
|
||||
mig_sql($pdo, 'Create builder_steps table', "
|
||||
CREATE TABLE IF NOT EXISTS builder_steps (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
session_id INT NOT NULL,
|
||||
step_order INT NOT NULL DEFAULT 0,
|
||||
prayer_id INT NOT NULL,
|
||||
attribution ENUM('leader_all','leader_only','all_only','none') NOT NULL DEFAULT 'leader_all',
|
||||
INDEX idx_session (session_id),
|
||||
FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
", $log);
|
||||
|
||||
// Seed standard global prayers (skip if already done)
|
||||
$existing = (int)$pdo->query("SELECT COUNT(*) FROM custom_prayers WHERE is_global=1")->fetchColumn();
|
||||
if ($existing > 0) {
|
||||
$log[] = ['skip', "Standard prayers already seeded ({$existing} found)"];
|
||||
} else {
|
||||
$sa = $pdo->query("SELECT id FROM users WHERE role='superadmin' LIMIT 1")->fetch();
|
||||
$creator_id = $sa ? (int)$sa['id'] : 1;
|
||||
|
||||
$prayers = [
|
||||
[
|
||||
'name' => 'Sign of the Cross',
|
||||
'leader' => "In the name of the Father,\nand of the Son,\nand of the Holy Spirit.",
|
||||
'all' => 'Amen.',
|
||||
],
|
||||
[
|
||||
'name' => 'Apostles\' Creed',
|
||||
'leader' => "I believe in God, the Father Almighty,\nCreator of Heaven and earth;\nand in Jesus Christ, His only Son, Our Lord,\nWho was conceived by the Holy Spirit,\nborn of the Virgin Mary,\nsuffered under Pontius Pilate,\nwas crucified, died, and was buried.\nHe descended into Hell;\nthe third day He rose again from the dead;\nHe ascended into Heaven,\nand sitteth at the right hand of God, the Father Almighty;\nfrom thence He shall come to judge the living and the dead.",
|
||||
'all' => "I believe in the Holy Spirit,\nthe Holy Catholic Church,\nthe communion of saints,\nthe forgiveness of sins,\nthe resurrection of the body\nand life everlasting. Amen.",
|
||||
],
|
||||
[
|
||||
'name' => 'Our Father',
|
||||
'leader' => "Our Father, Who art in Heaven,\nhallowed be Thy name;\nThy kingdom come,\nThy will be done on earth as it is in Heaven.",
|
||||
'all' => "Give us this day our daily bread,\nand forgive us our trespasses,\nas we forgive those who trespass against us;\nand lead us not into temptation,\nbut deliver us from evil. Amen.",
|
||||
],
|
||||
[
|
||||
'name' => 'Hail Mary',
|
||||
'leader' => "Hail Mary, full of grace, the Lord is with thee;\nblessed art thou amongst women,\nand blessed is the fruit of thy womb, Jesus.",
|
||||
'all' => "Holy Mary, Mother of God,\npray for us sinners,\nnow and at the hour of our death. Amen.",
|
||||
],
|
||||
[
|
||||
'name' => 'Glory Be',
|
||||
'leader' => "Glory be to the Father, and to the Son,\nand to the Holy Spirit,",
|
||||
'all' => "as it was in the beginning, is now,\nand ever shall be, world without end. Amen.",
|
||||
],
|
||||
[
|
||||
'name' => 'Fatima Prayer',
|
||||
'leader' => "O my Jesus, forgive us our sins,\nsave us from the fires of hell,",
|
||||
'all' => "lead all souls to Heaven,\nespecially those who are in most need of Thy mercy.",
|
||||
],
|
||||
[
|
||||
'name' => 'Hail Holy Queen',
|
||||
'leader' => "Hail, Holy Queen, Mother of Mercy,\nour life, our sweetness and our hope.\nTo thee do we cry,\npoor banished children of Eve.\nTo thee do we send up our sighs,\nmourning and weeping in this valley of tears.\nTurn then, most gracious advocate,\nthine eyes of mercy toward us,\nand after this our exile\nshow unto us the blessed fruit of thy womb, Jesus.\nO clement, O loving,\nO sweet Virgin Mary.",
|
||||
'all' => "Pray for us, O holy Mother of God,\nthat we may be made worthy of the promises of Christ.",
|
||||
],
|
||||
[
|
||||
'name' => 'Eternal Rest',
|
||||
'leader' => "Eternal rest grant unto {pronoun_obj}, O Lord,",
|
||||
'all' => "and let perpetual light shine upon {pronoun_obj}.\nMay {pronoun_poss} soul and the souls of all the faithful departed,\nthrough the mercy of God, rest in peace. Amen.",
|
||||
],
|
||||
[
|
||||
'name' => 'The Memorare',
|
||||
'leader' => "Remember, O most gracious Virgin Mary,\nthat never was it known\nthat anyone who fled to thy protection,\nimplored thy help, or sought thy intercession,\nwas left unaided.\nInspired by this confidence,\nI fly unto thee, O Virgin of virgins, my mother;\nto thee do I come,\nbefore thee I stand, sinful and sorrowful.\nO Mother of the Word Incarnate,\ndespise not my petitions,\nbut in thy mercy hear and answer me.",
|
||||
'all' => 'Amen.',
|
||||
],
|
||||
[
|
||||
'name' => 'Act of Contrition',
|
||||
'leader' => "O my God, I am heartily sorry for having offended Thee,\nand I detest all my sins\nbecause of thy just punishments,\nbut most of all because they offend Thee, my God,\nwho art all good and deserving of all my love.\nI firmly resolve, with the help of Thy grace,\nto sin no more and to avoid the near occasions of sin.",
|
||||
'all' => 'Amen.',
|
||||
],
|
||||
[
|
||||
'name' => 'O Blood and Water',
|
||||
'leader' => "O Blood and Water,\nwhich gushed forth from the Heart of Jesus\nas a fount of mercy for us,",
|
||||
'all' => 'I trust in You.',
|
||||
],
|
||||
[
|
||||
'name' => 'Eternal Father (Divine Mercy)',
|
||||
'leader' => "Eternal Father, I offer You the Body and Blood,\nSoul and Divinity of Your dearly beloved Son,\nOur Lord Jesus Christ,",
|
||||
'all' => "in atonement for our sins and those of the whole world.",
|
||||
],
|
||||
[
|
||||
'name' => 'For the Sake of His Sorrowful Passion',
|
||||
'leader' => "For the sake of His sorrowful Passion,",
|
||||
'all' => "have mercy on us and on the whole world.",
|
||||
],
|
||||
[
|
||||
'name' => 'Holy God (Divine Mercy Closing)',
|
||||
'leader' => "Holy God, Holy Mighty One, Holy Immortal One,",
|
||||
'all' => "have mercy on us and on the whole world.",
|
||||
],
|
||||
[
|
||||
'name' => 'Prayer to St. Michael the Archangel',
|
||||
'leader' => "Saint Michael the Archangel,\ndefend us in battle.\nBe our defense against the wickedness and snares of the Devil.\nMay God rebuke him, we humbly pray,\nand do thou, O Prince of the heavenly hosts,\nby the power of God, thrust into hell Satan,\nand all the evil spirits,\nwho prowl about the world seeking the ruin of souls.",
|
||||
'all' => 'Amen.',
|
||||
],
|
||||
[
|
||||
'name' => 'Rosary Closing Prayer',
|
||||
'leader' => "Let us pray.\n\nO God, whose only-begotten Son,\nby His life, death, and resurrection,\nhas purchased for us the rewards of eternal life,\ngrant, we beseech Thee,\nthat meditating upon these mysteries\nof the Most Holy Rosary of the Blessed Virgin Mary,\nwe may imitate what they contain\nand obtain what they promise,\nthrough the same Christ Our Lord.",
|
||||
'all' => 'Amen.',
|
||||
],
|
||||
];
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO custom_prayers (name, leader_text, all_text, is_global, created_by)
|
||||
VALUES (?, ?, ?, 1, ?)"
|
||||
);
|
||||
foreach ($prayers as $p) {
|
||||
$stmt->execute([$p['name'], $p['leader'], $p['all'], $creator_id]);
|
||||
}
|
||||
$log[] = ['ok', 'Seeded ' . count($prayers) . ' standard global prayers'];
|
||||
}
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Migrate v4</title>
|
||||
<style>
|
||||
body { font-family: system-ui; max-width: 700px; margin: 40px auto; padding: 0 20px; }
|
||||
h2 { color: #1d2027; }
|
||||
.ok { color: #15803d; } .skip { color: #b45309; } .err { color: #dc2626; }
|
||||
li { margin: 4px 0; font-size: 14px; }
|
||||
.done { background: #f0fdf4; border: 1px solid #86efac; padding: 16px; border-radius: 8px; margin-top: 20px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Migrate v4 — Rosary Builder Tables</h2>
|
||||
<ul>
|
||||
<?php foreach ($log as [$status, $msg]): ?>
|
||||
<li class="<?= $status ?>">
|
||||
<?= $status === 'ok' ? '✓' : ($status === 'skip' ? '◌' : '✗') ?>
|
||||
<?= htmlspecialchars($msg) ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php if (!array_filter($log, fn($l) => $l[0] === 'err')): ?>
|
||||
<div class="done">
|
||||
<strong>Migration complete.</strong>
|
||||
Delete this file now: <code>migrate_v4.php</code>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user