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

VACMS-20371: Clean up extensions #20730

Merged
merged 8 commits into from
Mar 3, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public function processOne(string $key, mixed $item, array &$sandbox): string {
}
$number_only_extension = $this->replaceNonNumerals($original_extension);
if ($original_extension === $number_only_extension) {
return "No change to extension $original_extension in paragraph id $item";
return "No change to extension '$original_extension' in paragraph id $item";
}
$phone_paragraph->set(name: 'field_phone_extension', value: $number_only_extension);
$phone_paragraph->save();
return "Extension updated for paragraph id $item from '$original_extension' to '$number_only_extension'";
}
catch (\Exception $e) {
$message = "Exception during update of paragraph id $item with extension: $original_extension";
$message = "Exception during update of paragraph id $item with extension: '$original_extension'";
return $message;
}

Expand All @@ -106,7 +106,7 @@ public static function replaceNonNumerals(string $extension): string {
}

// Remove non-numerical characters from the extension.
$just_numbers = preg_replace('/[^0-9]/', '', $extension);
$just_numbers = trim(preg_replace('/[^0-9]/', '', $extension));

return $just_numbers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function processOne(string $key, mixed $item, array &$sandbox): string {
}
$phone_paragraph->set(name: 'field_phone_extension', value: $separated_extensions[0]);
$phone_paragraph->save();
$message = "1st extension for paragraph $item changed from '$original_extension' to $separated_extensions[0]' .";
$message = "1st extension for paragraph $item changed from '$original_extension' to '$separated_extensions[0]'. ";
}

// Create the second extension and phone.
Expand All @@ -116,7 +116,7 @@ public function processOne(string $key, mixed $item, array &$sandbox): string {
$phone_parent_paragraph = \Drupal::entityTypeManager()->getStorage('paragraph')->load($phone_parent_id);
$phone_parent_paragraph->get($phone_parent_field_name)->appendItem($second_phone);
$phone_parent_paragraph->save();
$message .= "2nd extension created for paragraph $second_phone_id from '$original_extension' to $separated_extensions[1]'." . PHP_EOL;
$message .= "2nd extension created for paragraph $second_phone_id from '$original_extension' to '$separated_extensions[1]'.";
}
}
catch (\Exception $e) {
Expand All @@ -138,15 +138,16 @@ public function processOne(string $key, mixed $item, array &$sandbox): string {
* E.g. '2132,2995' becomes ['2132','2995']
*/
public static function splitExtensions(string $dual_extension): array {
if (!preg_match('/[^0-9]/', $dual_extension)) {
$pattern = '/(^\d+[,|;]\s?\d+)|(^\d+\sor\s\d+)|(^\d+\/\d+)|(^\d+\sthen\s\d+)/';
if (!preg_match($pattern, $dual_extension)) {
return [];
}
$first_extension = [];
preg_match('/^\d+/', $dual_extension, $first_extension);
$second_extension = [];
preg_match('/\d+$/', $dual_extension, $second_extension);

return [$first_extension[0], $second_extension[0]];
return [trim($first_extension[0]), trim($second_extension[0])];
}

}
Loading