We're doing a migration from a custom database into a Drupal 7 instance (7.22) using the Migrate module. We are using the Phone module in one of our content types, for a few different fields, which may or may not be filled. If the data being migrated doesn't happen to have a phone number in it to fill the field, many warnings show up:

2 Informational Undefined offset: 2 File /location/modules/phone/include/phone.ca.inc, line 77(file: /location/modules/phone/include/phone.ca.inc, line 77)
2 Informational Undefined offset: 3 File /location/modules/phone/include/phone.ca.inc, line 79(file: /location/modules/phone/include/phone.ca.inc, line 79)
2 Informational Undefined offset: 4 File /location/modules/phone/include/phone.ca.inc, line 79(file: /location/modules/phone/include/phone.ca.inc, line 79)
2 Informational Undefined offset: 5 File /location/modules/phone/include/phone.ca.inc, line 82(file: /location/modules/phone/include/phone.ca.inc, line 82)

Of course /location/ is not real, I just changed it for the purposes of this post. With a lot of data being migrated, this can cause hundreds and hundreds of these warnings. In addition, when the migrated content type is displayed, weird things happen such as just phone numbers looking like "()" instead of not showing up at all (I'm using a view to display this particular content type, and an empty phone field should just not be displayed at all).

I actually fixed the problem by going into the phone.ca.inc file and just adding an if statement around the code in the format_ca_phone_number($phonenumber, $field) function. It's crazy simple, and just says if ($phonenumber == "") { return ""; } else { do the function normally; }. This takes care of all the warnings and also allows the content type to be displayed correctly on the page with an empty field. Any chance this could make it in to the release code, or am I doing something really stupid here? I did test creating an instance of the content type (instead of migrating) with the if statement in the code and nothing seemed to go wrong.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bbdata’s picture

I also encountered this issue where the same notices would flood my logs because the phone number field was empty form the source.

I turned the OP's suggestion into a patch for anyone else running into the same problem.

damonbla’s picture

Thank you! I should have done that myself, but knew much less about Drupal when I originally posted this than I do now.