CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Wrong default country on import?
Pages: [1] 2

Author Topic: Wrong default country on import?  (Read 5538 times)

awarnock

  • Guest
Wrong default country on import?
February 20, 2009, 02:34:57 pm
I'm using CiviCRM v2.2 in standalone, running on a Fedora Core 10 system.

I have a list of contacts that I'm importing from a CSV file.  Almost all (but not absolutely all) have addresses in the US, so the field is unpopulated in the CSV file.  The default country for new contacts is set to the US (I checked specifically).

What's happening is that the imported contacts have the wrong country.  It looks like what's happening is that instead of applying the default country, it looks at the state (VA, for Virginia) and grabs the first country with a state that sorta matches (in this case, putting our contacts in Hungary).  Now, I have nothing against Hungary - my grandfather was born there.  But in this particular case, I'd like the country to reflect our contacts' actual country of residence.  Any suggestions?

And, for the contacts already entered (several thousand) with the wrong country, is there an easy way to change them in bulk - something like "if country='Hungary' then country='United States'"?

Thanks!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Wrong default country on import?
February 20, 2009, 05:37:26 pm

Can you reproduce this issue on http://drupal.demo.civicrm.org/

and if so, please file an issue. We'll fix for the next release of 2.2

update civicrm_address set country_id = 1228 where country_id = 1099;

is the sql to update all addresses to US if country is Hungary

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

awarnock

  • Guest
Re: Wrong default country on import?
February 21, 2009, 02:32:32 pm
Yeah - I can duplicate it on the demo site.  I filed the issue and included the CSV file that demonstrated the problem.  Thanks.

awarnock

  • Guest
Re: Wrong default country on import?
February 21, 2009, 02:37:50 pm
Quote
update civicrm_address set country_id = 1228 where country_id = 1099;

is the sql to update all addresses to US if country is Hungary

Got it - thanks.  At least, that works correctly as long as none of the contacts actually do live in Hungary.  But there are few enough of those, I suspect.  I just needed to know the table to modify.  Much appreciated.

awarnock

  • Guest
Re: Wrong default country on import?
February 21, 2009, 03:16:42 pm
Well, it's a little uglier than a single SQL command since the country that gets assigned to each imported contact depends on which US state their address is in.  So, I have lots of substitutions to make, not all of them obvious (since some of the non-US countries might actually be correct).  I think I probably need to just re-import all of the records after setting the countries explicitly.

Is there a command-line import script someplace?  I don't mind the length of time it takes to do the import (I've got 15,000+ contacts to import) but my browser session keeps timing out.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Wrong default country on import?
February 21, 2009, 05:24:59 pm
Quote from: awarnock on February 21, 2009, 03:16:42 pm
Is there a command-line import script someplace?  I don't mind the length of time it takes to do the import (I've got 15,000+ contacts to import) but my browser session keeps timing out.

A command line script does not exist as yet. This has come up a few times in the past. A code contribution for this would be highly appreciated :). Will primarily involve stiching together code that already exists

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

awarnock

  • Guest
Re: Wrong default country on import?
February 21, 2009, 07:23:41 pm
OK - thanks.  I appreciate the help.

arrow

  • Guest
Re: Wrong default country on import?
September 29, 2009, 08:40:55 pm
I've run afoul this as well.  It appears I'm going to have to write a perl script map all the civicrm.country_ids to = 1228 ('United States') where their state_province_ids match any of the U.S. states.  Joy.

this is still a problem in import in civicrm 2.2.8 when all the countries and regions are enabled in localization before import, fwiw. 
we did have U.S. as our default, but it didn't make a difference.

->Arrow



arrow

  • Guest
Re: Wrong default country on import?
September 29, 2009, 09:50:25 pm
I take it back:  this problem is a lot scarier than I thought.  Apparently the import resulted in completely faulty state_province_ids being imported, even though the display is showing properly.  Perhaps based on postal code logic?  Who knows.  This is very sad:

1105 Melrose Ave     Glendale     CA     91202-2485     Spain

this is the display.  However, in the database:

mysql> select state_province_id from civicrm_address where street_address = '1105 Melrose Ave';
+-------------------+
| state_province_id |
+-------------------+
|              2434 |

Whyever would it import with the state_province_id equaling C?rdiz and the Country id equaling Spain?

I can't fix this without something to hang the fix off of.  I can't find the email address in any of the address tables.  How can I identify the users and match them to my spreadsheet and try to script a fix?  What a sorry mess.


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Wrong default country on import?
September 30, 2009, 08:31:03 am

1. can you try to reproduce on the sandbox or demo server. I do think that the display will match the db values

2. seems like u have an inconsistency in your import file, with the state and country not matching. What behavior do you expect in a case like this? ideally i think the system should classify that line as an error and not import it

3. would be great to have a more positive attitude and try to figure out whats happening and why and helping towards getting a fix in rather than bemoaning the current state

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

arrow

  • Guest
Re: Wrong default country on import?
September 30, 2009, 01:39:35 pm
Sorry, I didn't mean to be negative!  I meant our addresses are a mess.  Do you know where the email addresses are located for the contacts?  How else can I tie civicrm_address with the appropriate contact id?  Is there a table I don't know about, in other words, or is there a schema for 2.2.6 I can look at?  Because our spreadsheet (obviously) still has States, so I can go in and fix all the state_province_ids if I just knew who to attach them to.  I don't want to trust just the first address line. 

Thanks, lobo.

I would be happy to provide the very dopey perl script I wrote, but all it does is output sql based on the states ids to "fix" the country_ids to match United States for all U.S. state_province_ids.  And that didn't fix it for us since our state_province_ids are not US States.  But I will attach the two files for any users like awarnock this might've helped. 

I'm not allowed to use the test db because this is confidential data.  Maybe I could make a limited set of rows and mess up the names and addresses...But as you can see the state_province_id is for a province in Spain. this is only one example. All of our US imports are like this--I can see them listed in the display in a contact search.  I see City, State, postal code, and then some random Country that is not the United States, and when I go into the db and look at the state_province_id, sure enough it's for some random province in that non-U.S. country.  But in the interface they have a State.

->Arrow

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Wrong default country on import?
September 30, 2009, 02:41:20 pm

civicrm_email and they are linked to civicrm_contact via the contact_id foreign key

to some extent the rest of the address is a bit immaterial. its more the state / country mismatch. I do hope that we dont randonly select state_province ids and if we do, we will fix it asap. We've done a fair amount of imports and have not heard of this mangling before. However ensuring your import does have valid state/country pairs is also a good safety check

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

arrow

  • Guest
Re: Wrong default country on import?
October 01, 2009, 06:31:46 pm
Thanks, lobo. That was the key. I exported the old state_province_ids and names  and emails and I've written a hinky script to write the sql to fix. It's working well.  I've discovered all the Canadian addresses are similarly showing up with African nations and stuff. Only North American addresses affected so far, with one exception:  LAN (Lancashire) province (it's in the U.K.)

I want to help you track down this issue so I've got a test import csv file with just one of the addresses and the name changed but with the header mappings.  I'll try to reproduce on http://drupal.demo.civicrm.org.  Maybe the problem will be gone with 3.0!  :)

arrow

  • Guest
Re: Wrong default country on import?
October 01, 2009, 06:48:11 pm
Well, it appears as if the issue is fixed in 3.0 with this minimal sample. My contact imported correctly (United States as country) with the same settings (same mapping, which I saved as arrow_test, and with same config: all countries and provinces enabled under localization, no Country in the spreadsheet, but with default country set as U.S.)

Contact's last name is Delala.  

I did, however, receive the following error during import, even though the import completed:

    * warning: substr_compare() [function.substr-compare]: The length must be greater than zero in /var/www/drupal-6.civicrm.org/svn/civicrm3.0/CRM/Import/Parser/Contact.php on line 1026.
    * warning: substr_compare() [function.substr-compare]: The length must be greater than zero in /var/www/drupal-6.civicrm.org/svn/civicrm3.0/CRM/Import/Parser/Contact.php on line 1026.
    * warning: substr_compare() [function.substr-compare]: The length must be greater than zero in /var/www/drupal-6.civicrm.org/svn/civicrm3.0/CRM/Import/Parser/Contact.php on line 1026.

I am attaching the .csv file.

cwgng

  • Guest
Re: Wrong default country on import?
November 05, 2009, 11:43:22 am
I'm testing importing a data set currently and am finding the same error:

Code: [Select]
warning: substr_compare() [function.substr-compare]: The length must be greater than zero in »
/<MY CIVICRM ROOT>/civicrm/CRM/Import/Parser/Contact.php on line 1026.

Line 1026 is inside the "checkGender" function:

Code: [Select]
...
  1026              if ( substr_compare( $value, $gender, 0, strlen( $gender ), true ) === 0 ) {
...

In this test import data set, two of my contacts do not have any gender listed. Could this cause the problem? Oddly, I see that warning 6 times. Doing more investigation ...

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Wrong default country on import?

This forum was archived on 2017-11-26.