Send email if notify on complete is set

This commit is contained in:
Jake Barnby 2025-09-24 22:38:12 +12:00
parent 5e8951fbe0
commit 4970aa7426
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 74 additions and 0 deletions

View file

@ -54,6 +54,14 @@
"emails.recovery.thanks": "Thanks,",
"emails.recovery.buttonText": "Reset password",
"emails.recovery.signature": "{{project}} team",
"emails.csvExport.subject": "Your CSV export is ready",
"emails.csvExport.preview": "Your data export has been completed successfully.",
"emails.csvExport.hello": "Hello {{user}},",
"emails.csvExport.body": "Your CSV export is ready for download. Click the link below to download your data export.",
"emails.csvExport.footer": "This download link will expire in 1 hour.",
"emails.csvExport.thanks": "Thanks,",
"emails.csvExport.buttonText": "Download CSV",
"emails.csvExport.signature": "{{project}} team",
"emails.invitation.subject": "Invitation to {{team}} Team at {{project}}",
"emails.invitation.preview": "{{owner}} invited you to join {{team}} at {{project}}",
"emails.invitation.hello": "Hello {{user}},",

View file

@ -516,5 +516,71 @@ class Migrations extends Action
return;
}
$user = $this->dbForPlatform->findOne('users', [
Query::equal('$sequence', [$userInternalId])
]);
// Set up locale
$locale = new Locale(System::getEnv('_APP_LOCALE', 'en'));
$locale->setFallback(System::getEnv('_APP_LOCALE', 'en'));
// Generate JWT
$expiry = (new \DateTime())->add(new \DateInterval('PT1H'))->format('U');
$encoder = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', \intval($expiry), 0);
$jwt = $encoder->encode([
'bucketId' => $bucketId,
'fileId' => $fileId,
'projectId' => $project->getId(),
]);
// Generate download URL with JWT
$endpoint = System::getEnv('_APP_DOMAIN', '');
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled' ? 'https' : 'http';
$downloadUrl = "{$protocol}://{$endpoint}/v1/storage/buckets/{$bucketId}/files/{$fileId}/push?project={$project->getId()}&jwt={$jwt}";
// Get localized email content
$subject = $locale->getText('emails.csvExport.subject');
$preview = $locale->getText('emails.csvExport.preview');
$hello = $locale->getText('emails.csvExport.hello');
$body = $locale->getText('emails.csvExport.body');
$footer = $locale->getText('emails.csvExport.footer');
$thanks = $locale->getText('emails.csvExport.thanks');
$buttonText = $locale->getText('emails.csvExport.buttonText');
$signature = $locale->getText('emails.csvExport.signature');
// Build email body using inner template
$message = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-inner-base.tpl');
$message
->setParam('{{body}}', $body, escapeHtml: false)
->setParam('{{hello}}', $hello)
->setParam('{{footer}}', $footer)
->setParam('{{thanks}}', $thanks)
->setParam('{{buttonText}}', $buttonText)
->setParam('{{signature}}', $signature)
->setParam('{{direction}}', $locale->getText('settings.direction'))
->setParam('{{project}}', $project->getAttribute('name'))
->setParam('{{user}}', $user->getAttribute('name', $user->getAttribute('email')))
->setParam('{{redirect}}', $downloadUrl);
$emailBody = $message->render();
$emailVariables = [
'direction' => $locale->getText('settings.direction'),
'project' => $project->getAttribute('name'),
'user' => $user->getAttribute('name', $user->getAttribute('email')),
'redirect' => $downloadUrl,
];
$queueForMails
->setSubject($subject)
->setPreview($preview)
->setBody($emailBody)
->setBodyTemplate(__DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl')
->setVariables($emailVariables)
->setName($user->getAttribute('name', $user->getAttribute('email')))
->setRecipient($user->getAttribute('email'))
->trigger();
Console::info('CSV export notification email sent to ' . $user->getAttribute('email'));
}
}