Skip to content

Conversation

@anonymoususer72041
Copy link

Summary

This pull request introduces support for a configurable default phone country calling code and updates phone number handling to normalize numbers to E.164 where possible.

The changes include:

Backend support for E.164 normalization

  • Add StringUtility::extractPhoneNumberE164($string) to normalize phone numbers:
  • Trims input and normalizes leading 00 to + (e.g. 0049...+49...).
  • Strips all non-digit characters except a leading +.
  • If the input already starts with +, it is treated as an E.164-style number and returned as-is (after normalization).
  • For local numbers without +, the default phone country calling code is applied and the number is converted to E.164.
  • Update StringUtility::extractPhoneNumber($string) to delegate to extractPhoneNumberE164($string), while keeping the previous NANP-based implementation as commented legacy code for future refactoring.

Site configuration for default phone country calling code

  • Add column default_phone_country_code (VARCHAR(8), default '+1') to the site table in the schema and schema migration.
  • Extend the session and site configuration layer to store and retrieve the default phone country calling code (e.g. via Session::getDefaultPhoneCountryCode() / Session::setDefaultPhoneCountryCode() and Site::setDefaultPhoneCountryCode()).

Installer support (new installations)

  • Extend the “Loading Extras – Localization” step in the installer to ask for the default phone country calling code.
  • Add a + prefixed text input (defaultPhoneCountryCodeDigits) that only accepts digits on the client side.
  • Store the chosen code as +<digits> in the site.default_phone_country_code column when the installer completes.
  • Existing installations receive the new configuration column with a default of +1 as part of the schema migration and can then adjust it via the Admin UI.

Admin UI (Localization settings)

  • Extend the Localization settings page to display and edit the default phone country calling code:
  • Show only the digits part in the input field (e.g. +4949).
  • On save, clean the submitted value to digits only and persist it as +<digits> via Site::setDefaultPhoneCountryCode().
  • If no digits are submitted, the existing value in the database is left unchanged.

Motivation

Historically, OpenCATS relied on a NANP-centric phone number format and hard-coded assumptions such as the country code +1. This causes several issues for non-US/Canadian users:

  • Phone numbers entered in local formats for other countries are not consistently or correctly normalized.
  • The system has no explicit notion of which country calling code should be applied when normalizing plain local numbers.
  • Administrators outside the NANP region cannot configure their preferred default behavior centrally.

By introducing a configurable default phone country calling code and moving phone number handling toward E.164, this Pull Request:

  • Makes phone number storage and processing more predictable and international-friendly.
  • Allows each installation to set an appropriate default phone country calling code via:
  • the installer for new installations, and
  • the Localization settings in the Admin UI for existing installations.
  • Keeps backward compatibility by:
  • defaulting to +1 for existing databases (through the schema default),
  • preserving the previous extractPhoneNumber() logic as commented legacy code to make a future refactor easier to understand,
  • avoiding behavioral changes in the upgrade wizard flow (no new required steps during upgrade).

Overall, this is a first, backward-compatible step toward better internationalized phone number handling, while still fitting cleanly into existing OpenCATS patterns for configuration, schema updates, and settings UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant