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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Similar contacts check on New Individual form fails - contact_ajax_check_similar
Pages: [1]

Author Topic: Similar contacts check on New Individual form fails - contact_ajax_check_similar  (Read 773 times)

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 10, 2012, 10:46:03 am
Hi,

On a 4.1.2 / D7 site, the similar contacts check on New Individual form fails. A JavaScript syntax error is shown in Firebug:
   
Code: [Select]
var checkSimilar =  ;
I tracked this down to CRM/Contact/Form/Edit/Individual.php buildQuickForm() getting setting 'contact_ajax_check_similar', which is NULL in the db. How should this be getting set?

Cheers,

Dave J

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: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 10, 2012, 11:28:16 am

we should set the value to 0 if it is null or not set, we can potentially do this by sending a default value to the getItem function

not sure why its not picking the value of 0

can u try this patch:

Code: [Select]

svn diff -x -w CRM/Contact/Form/Edit/Individual.php
Index: CRM/Contact/Form/Edit/Individual.php
===================================================================
--- CRM/Contact/Form/Edit/Individual.php        (revision 40289)
+++ CRM/Contact/Form/Edit/Individual.php        (working copy)
@@ -98,6 +98,9 @@
                                                        'contact_ajax_check_similar',
                                                        null,
                                                        true );
+        if ( $checkSimilar == null ) {
+          $checkSimilar = 0;
+        }
         $form->assign('checkSimilar',$checkSimilar );
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 11, 2012, 04:47:01 am
Hi Lobo,

Thanks for the reply. In previous versions, the AJAX check defaulted to true. Looking into it a bit more, in 4.0.8 CRM/Contact/Form/Edit/Individual.php buildQuickForm():

Code: [Select]
        $checkSimilar = defined( 'CIVICRM_CONTACT_AJAX_CHECK_SIMILAR' ) ? CIVICRM_CONTACT_AJAX_CHECK_SIMILAR : true;
In 4.1.2:

Code: [Select]
        $checkSimilar = CRM_Core_BAO_Setting::getItem( CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
                                                       'contact_ajax_check_similar',
                                                       null,
                                                       true );

So in both cases, the code specifies a default of true. I think what's happening differently in 4.1 is that if CRM_Core_BAO_Setting::getItem finds a value of NULL in the db, it treats that as having found a value (namely NULL) and so returns NULL, rather than treating it as not having found a value and therefore returning the specified default.

I think this happens because when CRM_Core_BAO_Setting::getItem finds an empty value for name in the db, it sets:

Code: [Select]
                    $values[$dao->name] = null;
And what CRM_Core_BAO_Setting::getItem returns is:

Code: [Select]
        CRM_Utils_Array::value( $name, self::$_cache[$cacheKey], $defaultValue )
and CRM_Utils_Array::value() returns:

Code: [Select]
        array_key_exists( $key, $list ) ? $list[$key] : $default
Here the array key exists, with a value of NULL, so NULL is returned.

When CRM_Core_BAO_Setting::getItem finds a NULL value in the db, should it return NULL or return the specified default value? I would have thought the latter, in which case the return statement should change along these lines:

Code: [Select]
--- CRM/Core/BAO/Setting.php.orig       2012-02-17 22:09:14.000000000 +0000
+++ CRM/Core/BAO/Setting.php    2012-05-11 12:44:11.000000000 +0100
@@ -187,7 +187,7 @@
 
         return
             $name ?
-            CRM_Utils_Array::value( $name, self::$_cache[$cacheKey], $defaultValue ) :
+            ( isset(self::$_cache[$cacheKey][$name]) ? self::$_cache[$cacheKey][$name] : $defaultValue ) :
             self::$_cache[$cacheKey];
     }
 
Unless there's existing code that relies on the current behaviour! I've tested this and it works correctly for contact_ajax_check_similar: if the db field is NULL, getItem now returns the default value (here true). I haven't seen any ill effects so far, but early days yet!

Adding a check in CRM/Contact/Form/Edit/Individual.php along the lines you suggested would be a more conservative fix, though I'd change it to:

Code: [Select]
        if ( $checkSimilar === null ) {
          $checkSimilar = true;
        }

This seems to defeat the purpose of specifying a default value for getItem, though.

Cheers,

Dave J

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 11, 2012, 05:43:27 am
Also note that we didn't update this function to use api v3, and because api v2 on ajax has finally be disabled (at least on 4.2), you might have to apply this patch if you ever want to =1;

http://issues.civicrm.org/jira/browse/CRM-10182

out of curiosity, why are you disabling it? On our side up to medium db (<20k) works ok enough according to the users it seem

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 11, 2012, 07:15:05 am
Hi Xavier,

Are you well? Are you looking forward to beautiful English food this September? :-)

Quote from: xavier on May 11, 2012, 05:43:27 am
Also note that we didn't update this function to use api v3, and because api v2 on ajax has finally be disabled (at least on 4.2), you might have to apply this patch if you ever want to =1;

http://issues.civicrm.org/jira/browse/CRM-10182

Thanks for the info.

Quote from: xavier on May 11, 2012, 05:43:27 am
out of curiosity, why are you disabling it? On our side up to medium db (<20k) works ok enough according to the users it seem

I didn't disable it, Civi did ;-) possibly. Pre 4.1, if CIVICRM_CONTACT_AJAX_CHECK_SIMILAR was not defined, the AJAX check defaulted to on. In this 4.1.2 db, contact_ajax_check_similar is NULL in the settings table and CRM_Core_BAO_Setting::getItem retrieves this NULL, ignores the default value and causes a JS syntax error. We didn't intentionally disable it. Discussing on IRC.

Cheers,

Dave J

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 11, 2012, 09:35:03 am
Quote
Are you well? Are you looking forward to beautiful English food this September? :-)

See, I come in a friendly way and try to be helpful and you threaten me...

:)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 18, 2012, 03:03:46 am
Quote from: xavier on May 11, 2012, 09:35:03 am
See, I come in a friendly way and try to be helpful and you threaten me...

:)

Not at all, we've been thinking of you and how we can offer the finest hospitality to our guests this September and have come up with... a farmhouse next to a vineyard and a brewery. With a swimming pool. Nobody was planning on writing any code, were they? :)

Cheers,

Dave J

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Similar contacts check on New Individual form fails - contact_ajax_check_similar
May 18, 2012, 05:20:15 am
I'll come with my inflatable laptop then
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Similar contacts check on New Individual form fails - contact_ajax_check_similar

This forum was archived on 2017-11-26.