39038-vm/db/migrations/add_welcome_template.php
2026-03-13 17:39:36 +00:00

41 lines
2.0 KiB
PHP

<?php
// db/migrations/add_welcome_template.php
require_once __DIR__ . '/../../db/config.php';
$pdo = db();
$templates = [
[
'event_name' => 'welcome_message',
'email_subject_en' => 'Welcome to CargoLink!',
'email_body_en' => "Dear {user_name},\n\nWelcome to CargoLink! We are excited to have you on board.\n\nYou can now log in to your dashboard and start using our services.\n\nBest regards,\nThe CargoLink Team",
'email_subject_ar' => 'مرحباً بك في كارجو لينك!',
'email_body_ar' => "عزيزي {user_name}،\n\nمرحباً بك في كارجو لينك! نحن سعداء بانضمامك إلينا.\n\nيمكنك الآن تسجيل الدخول إلى لوحة التحكم والبدء في استخدام خدماتنا.\n\nتحياتنا،\nفريق كارجو لينك",
'whatsapp_body_en' => "Welcome to CargoLink, {user_name}! 🚚\n\nWe're glad to have you with us. Log in now to get started: https://cargolink.om",
'whatsapp_body_ar' => "مرحباً بك في كارجو لينك، {user_name}! 🚚\n\nسعداء بانضمامك إلينا. سجل الدخول الآن للبدء: https://cargolink.om"
]
];
foreach ($templates as $t) {
$stmt = $pdo->prepare("SELECT id FROM notification_templates WHERE event_name = ?");
$stmt->execute([$t['event_name']]);
if (!$stmt->fetch()) {
$sql = "INSERT INTO notification_templates (event_name, email_subject_en, email_body_en, email_subject_ar, email_body_ar, whatsapp_body_en, whatsapp_body_ar) VALUES (?, ?, ?, ?, ?, ?, ?)";
$pdo->prepare($sql)->execute([
$t['event_name'],
$t['email_subject_en'],
$t['email_body_en'],
$t['email_subject_ar'],
$t['email_body_ar'],
$t['whatsapp_body_en'],
$t['whatsapp_body_ar']
]);
echo "Added template: {$t['event_name']}\n";
} else {
echo "Template already exists: {$t['event_name']}\n";
}
}