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

pkp/pkp-lib#11125 Fix: Copyediting Stage, Discussion tags do not populate [stable3.4] #11178

Open
wants to merge 2 commits into
base: stable-3_4_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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;

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);
}

/**
* 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) {
$existingVariables[] = '/\{\$' . $key . '\}/';
$replacementsVariables[] = '{$' . $value . '}';
}

// Default templates
$data = DB::table('email_templates_default_data')->where('email_key', $emailKey)->get();

$data->each(function (object $entry) use ($existingVariables, $replacementsVariables) {
$subject = preg_replace($existingVariables, $replacementsVariables, $entry->subject);
$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]]
*/
protected function oldToNewVariablesMap(): array
{
return [
'COPYEDIT_REQUEST' => [
'contextAcronym' => 'contextAcronym',
],
'LAYOUT_REQUEST' => [
'contextAcronym' => 'contextAcronym',
],
];
}
}
4 changes: 3 additions & 1 deletion locale/gd/submission.po
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,9 @@ msgid "notification.type.editorAssign"
msgstr ""

msgid "notification.type.copyeditorRequest"
msgstr ""
msgstr
"Chaidh iarraidh ort lèirmheas a dhèanamh air a’ ghrinn-deasachadh a rinneadh "
"air “{$title}”."

msgid "notification.type.layouteditorRequest"
msgstr ""
Expand Down