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) »
  • Array vs. scalar problem in 2.1.4 import?
Pages: [1]

Author Topic: Array vs. scalar problem in 2.1.4 import?  (Read 1579 times)

tbruce

  • Guest
Array vs. scalar problem in 2.1.4 import?
January 26, 2009, 01:01:57 pm
Hi:

We're trying to track down a problem with data importation in 2.1.4.  Basically, some empty fields cause problems.

Looking at the code, it would appear that the code in getActiveFieldParams (at approximately line 629 of ...../Import/Parser.php) is assigning array-type values to each element of the array $params, making it an array of arrays.  Yet most of the code we've looked at in ...../Import/Parser/Contact.php wants to treat these as scalar values.  The result is that when there is no value with which to stuff an element of $params  (say, $params[foo]), various bits of code that look like

if ($params[foo] && whatever){
   ... do something...
}

always execute because (as an array) $params[foo] will always be defined, even if empty.  Results are, of course, unpredictable depending on data values etc.  We do notice that some error messages that should be returning the value of a $params element as part of the message are returning the string 'Array' instead, and that preg_replace complains of receiving array rather than string values in various places where it's used.

I have to admit I'm wondering if we have this right, if only because this is a pretty wide-ranging problem and I'd expect more complaints over this kind of breakage.  But I suppose it's possible that nobody else has hit this yet.

Thoughts?

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: Array vs. scalar problem in 2.1.4 import?
January 26, 2009, 05:47:14 pm

can you reproduce your issue on our sandbox server

i just checked the code and that function. $params is an array for some cases only (if the field is a location or relationship field). so most fields will execute this code:

Code: [Select]
               if ( ! isset($params[$this->_activeFields[$i]->_name] ) ) {
                    if ( !isset($this->_activeFields[$i]->_related) ) {
                        $params[$this->_activeFields[$i]->_name] = $this->_activeFields[$i]->_value;

                    }
                }

lobo


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

slavering.dog

  • Guest
Re: Array vs. scalar problem in 2.1.4 import?
February 05, 2009, 07:16:47 am
I did not reproduce it on the sandbox (I work with tbruce) -- but see last paragraph.

 We are getting a lot of "Invalid value for field(s) : Birth-Date; Is Deceased; Deceased Date; Individual Suffix; Individual Prefix; Gender ..." errors which make no sense to me because I do not believe our data is actually malformed.

At the same time drupal is throwing a errors at the top of the page in its red box:
"# warning: preg_match() expects parameter 2 to be string, array given in
/var/www/html/patron/modules/civicrm/CRM/Utils/Date.php on line 590.
# warning: preg_match() expects parameter 2 to be string, array given in /var/www/html/patron/modules/civicrm/CRM/Utils/String.php on line 288.
# warning: preg_match() expects parameter 2 to be string, array given in /var/www/html/patron/modules/civicrm/CRM/Utils/String.php on line 290."

The one error I did get in the sandbox which I didn't understand was a invalid value message for the gender field, when the imported  field was nothing but the string "F" or the string "M".  I stopped trying to import to the Gender field, and that was when I succeeded. Am I missing something?

- Brian Hughes

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Array vs. scalar problem in 2.1.4 import?

This forum was archived on 2017-11-26.