-
Notifications
You must be signed in to change notification settings - Fork 461
pkp/pkp-lib#11125 Fix: Copyediting Stage, Discussion tags do not populate [main] #11180
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||
<?php | ||||||
|
||||||
/** | ||||||
* @file classes/migration/upgrade/v3_4_0/I11125_UpdateEmailTemplateVariables.php | ||||||
* | ||||||
* Copyright (c) 2014-2025 Simon Fraser University | ||||||
* Copyright (c) 2000-2025 John Willinsky | ||||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||||||
* | ||||||
* @class I11125_UpdateEmailTemplateVariables | ||||||
* | ||||||
* @brief Migration to update Email Template variable names | ||||||
*/ | ||||||
|
||||||
namespace PKP\migration\upgrade\v3_4_0; | ||||||
|
||||||
use Illuminate\Support\Facades\DB; | ||||||
|
||||||
abstract class I11125_UpdateEmailTemplateVariables extends \PKP\migration\Migration | ||||||
{ | ||||||
public function up(): void | ||||||
{ | ||||||
// Update template variables | ||||||
$this->renameTemplateVariables($this->oldToNewVariablesMap()); | ||||||
} | ||||||
|
||||||
public function down(): void | ||||||
{ | ||||||
$newToOldVariableMap = array_map(function ($variablesMap) { | ||||||
return array_flip($variablesMap); | ||||||
}, $this->oldToNewVariablesMap()); | ||||||
|
||||||
$this->renameTemplateVariables($newToOldVariableMap); | ||||||
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note... At the moment, given the number of migrations without a |
||||||
} | ||||||
|
||||||
/** | ||||||
* Replaces email template variables in templates' subject and body | ||||||
*/ | ||||||
protected function renameTemplateVariables(array $oldNewVariablesMap): void | ||||||
{ | ||||||
foreach ($oldNewVariablesMap as $emailKey => $variablesMap) { | ||||||
$existingVariables = []; | ||||||
$replacementsVariables = []; | ||||||
|
||||||
foreach ($variablesMap as $key => $value) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$existingVariables[] = '/\{\$' . $key . '\}/'; | ||||||
$replacementsVariables[] = '{$' . $value . '}'; | ||||||
} | ||||||
|
||||||
// Default templates | ||||||
$data = DB::table('email_templates_default_data')->where('email_key', $emailKey)->get(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how many rows this and the next table might have (some installations out there have many journals), but such simple string replacements can be done with SQL, then you won't need to download all the record set and the operation should complete faster. |
||||||
|
||||||
$data->each(function (object $entry) use ($existingVariables, $replacementsVariables) { | ||||||
$subject = preg_replace($existingVariables, $replacementsVariables, $entry->subject); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it's a simple string, then you could use the |
||||||
$body = preg_replace($existingVariables, $replacementsVariables, $entry->body); | ||||||
DB::table('email_templates_default_data') | ||||||
->where('email_key', $entry->{'email_key'}) | ||||||
->where('locale', $entry->{'locale'}) | ||||||
->update(['subject' => $subject, 'body' => $body]); | ||||||
}); | ||||||
|
||||||
// Custom templates | ||||||
$customData = DB::table('email_templates')->where('email_key', $emailKey)->get(); | ||||||
$customData->each(function (object $customEntry) use ($existingVariables, $replacementsVariables) { | ||||||
$emailSettingsRows = DB::table('email_templates_settings')->where('email_id', $customEntry->{'email_id'})->get(); | ||||||
foreach ($emailSettingsRows as $emailSettingsRow) { | ||||||
$value = preg_replace($existingVariables, $replacementsVariables, $emailSettingsRow->{'setting_value'}); | ||||||
DB::table('email_templates_settings') | ||||||
->where('email_id', $emailSettingsRow->{'email_id'}) | ||||||
->where('locale', $emailSettingsRow->{'locale'}) | ||||||
->where('setting_name', $emailSettingsRow->{'setting_name'}) | ||||||
->update(['setting_value' => $value]); | ||||||
} | ||||||
}); | ||||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* @return array [email_key => [old_variable => new_variable]] | ||||||
*/ | ||||||
abstract protected function oldToNewVariablesMap(): array; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.