add Upgrader to maintain profile behaviour
This commit is contained in:
parent
df51d59cea
commit
b3f82fbfba
1 changed files with 36 additions and 0 deletions
|
@ -102,4 +102,40 @@ class CRM_Twingle_Upgrader extends CRM_Extension_Upgrader_Base {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade to 1.5.0
|
||||||
|
*
|
||||||
|
* - Activate mapping of `purpose` and `user_extra_field` to notes in each existing profile to
|
||||||
|
* maintain default behavior after making the fields optional.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @throws \Civi\Core\Exception\DBQueryException
|
||||||
|
* @throws \Civi\Twingle\Exceptions\ProfileException
|
||||||
|
*/
|
||||||
|
public function upgrade_5150(): bool {
|
||||||
|
$this->ctx->log->info('Activate mapping of `purpose` and `user_extra_field` to notes in each existing profile.');
|
||||||
|
|
||||||
|
$profiles = CRM_Twingle_Profile::getProfiles();
|
||||||
|
if ($profiles) {
|
||||||
|
foreach ($profiles as $profile) {
|
||||||
|
$profile_changed = FALSE;
|
||||||
|
$contribution_notes = $profile->getAttribute('map_as_contribution_notes', []);
|
||||||
|
$contact_notes = $profile->getAttribute('map_as_contact_notes', []);
|
||||||
|
if (!in_array('purpose', $contribution_notes)) {
|
||||||
|
$profile->setAttribute('map_as_contribution_notes', array_merge($contribution_notes, ['purpose']));
|
||||||
|
$profile_changed = TRUE;
|
||||||
|
}
|
||||||
|
if (!in_array('user_extrafield', $contact_notes)) {
|
||||||
|
$profile->setAttribute('map_as_contact_notes', array_merge($contact_notes, ['user_extrafield']));
|
||||||
|
$profile_changed = TRUE;
|
||||||
|
}
|
||||||
|
if ($profile_changed) {
|
||||||
|
$profile->saveProfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue