Refactor SMS sending to use KavehNegar VerifyLookup templates
- Removed SmsTextResolver dependency from multiple services and controllers. - Introduced dispatchTemplate method in SmsService to handle SMS sending with templates. - Updated existing SMS sending logic across various services (OtpService, PreRegistrationController, ClinicInvitationService, PaymentManager, SecretaryController, RepresentationActionController) to utilize the new dispatchTemplate method. - Enhanced SmsMessageTemplate entity to include kavenegar_template and token_map fields. - Created migration to add new fields to the sms_message_templates table and populate them with existing data. - Updated SeedSmsMessageTemplatesCommand to handle new template structure. - Added documentation for the new SMS template structure and usage.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* افزودن نام تمپلت کاوهنگار (VerifyLookup) و نگاشت متغیر→token به تمپلتهای پیامک سیستمی،
|
||||
* و پرکردن مقادیر برای تگهای موجود.
|
||||
*/
|
||||
final class Version20260705072835 extends AbstractMigration
|
||||
{
|
||||
private const SEED = [
|
||||
'otp' => ['clinicpro-otp', ['code' => 'token', 'site' => 'token10']],
|
||||
'payment' => ['clinicpro-payment', ['doctor' => 'token10', 'date' => 'token20']],
|
||||
'clinic_invitation' => ['clinicpro-clinic-invite', ['clinic' => 'token10', 'link' => 'token']],
|
||||
'pre_registration' => ['clinicpro-pre-register', ['username' => 'token', 'password' => 'token2', 'link' => 'token3']],
|
||||
'notification_mobile' => ['clinicpro-notify-code', ['code' => 'token']],
|
||||
'secretary' => ['clinicpro-secretary', ['owner' => 'token10', 'username' => 'token', 'link' => 'token3']],
|
||||
'doctor_appointment' => ['clinicpro-doctor-appt', ['patient' => 'token10', 'date' => 'token2', 'time' => 'token3']],
|
||||
'welcome' => ['clinicpro-welcome', ['name' => 'token10', 'site' => 'token20']],
|
||||
];
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'sms_message_templates: افزودن kavenegar_template و token_map + پرکردن تگهای موجود';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE sms_message_templates ADD kavenegar_template VARCHAR(100) DEFAULT NULL, ADD token_map JSON DEFAULT NULL');
|
||||
|
||||
foreach (self::SEED as $tag => [$template, $map]) {
|
||||
$this->addSql(
|
||||
'UPDATE sms_message_templates SET kavenegar_template = :tpl, token_map = :map WHERE tag = :tag',
|
||||
['tpl' => $template, 'map' => json_encode($map, JSON_UNESCAPED_UNICODE), 'tag' => $tag]
|
||||
);
|
||||
}
|
||||
|
||||
$this->addSql("UPDATE sms_message_templates SET token_map = '[]' WHERE token_map IS NULL");
|
||||
$this->addSql('ALTER TABLE sms_message_templates MODIFY token_map JSON NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE sms_message_templates DROP kavenegar_template, DROP token_map');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user