function reroute_email_update_8201 in Reroute Email 2.x
Implements hook_update_N().
Updating module configs to use the new property names.
See also
https://www.drupal.org/project/reroute_email/issues/3177642
File
- ./
reroute_email.install, line 94 - Reroute Email installation and upgrade tasks.
Code
function reroute_email_update_8201() {
// A map of changed config names.
$old = [
REROUTE_EMAIL_ALLOWLIST => 'whitelist',
];
// Do not update values if the user sets them manually already.
// `Allowed list addresses` is a new property, so it couldn't exist before.
$config = \Drupal::configFactory()
->getEditable('reroute_email.settings');
if (NULL !== $config
->get(REROUTE_EMAIL_ALLOWLIST)) {
return t('The setting form was updated manually already. This update is to be skipped.');
}
// Update the list of allowed email addresses.
$addresses = $config
->get($old[REROUTE_EMAIL_ALLOWLIST]);
$config
->set(REROUTE_EMAIL_ALLOWLIST, $addresses);
$config
->clear($old[REROUTE_EMAIL_ENABLE]);
$config
->save();
// Return a message to the user.
return t('Reroute email module updates completed successfully. Please visit configuration page to check.');
}