Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve email notfication migration #602

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions api/app/Console/Commands/EmailNotificationMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function updateIntegration(FormIntegration $integration)
return;
}
$existingData = $integration->data;
if ($integration->integration_id === 'email') {
if ($integration->integration_id === 'email' && isset($existingData->notification_emails)) {
$integration->data = [
'send_to' => $existingData->notification_emails ?? null,
'sender_name' => 'OpnForm',
Expand All @@ -75,7 +75,8 @@ public function updateIntegration(FormIntegration $integration)
'include_hidden_fields_submission_data' => false,
'reply_to' => $existingData->notification_reply_to ?? null
];
} elseif ($integration->integration_id === 'submission_confirmation') {
return $integration->save();
} else if ($integration->integration_id === 'submission_confirmation' && isset($existingData->notification_subject)) {
$integration->integration_id = 'email';
$integration->data = [
'send_to' => $this->getMentionHtml($integration->form),
Expand All @@ -86,8 +87,9 @@ public function updateIntegration(FormIntegration $integration)
'include_hidden_fields_submission_data' => false,
'reply_to' => $existingData->confirmation_reply_to ?? null
];
return $integration->save();
}
return $integration->save();
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding logging for audit purposes.

Since this is a one-time migration script, it would be helpful to log successful migrations for audit purposes and troubleshooting.

Consider adding logging:

     if ($integration->integration_id === 'email' && isset($existingData->notification_emails)) {
         // ... existing code ...
+        $this->info("Migrated email integration {$integration->id} for form {$integration->form_id}");
         return $integration->save();
     } else if ($integration->integration_id === 'submission_confirmation' && isset($existingData->notification_subject)) {
         // ... existing code ...
+        $this->info("Migrated submission confirmation integration {$integration->id} for form {$integration->form_id}");
         return $integration->save();
     }
+    $this->warn("Skipped integration {$integration->id} - no matching conditions");
     return;

Committable suggestion was skipped due to low confidence.

}

private function getMentionHtml(Form $form)
Expand Down
Loading