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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Merge gives error on custom date fields / bug fix code
Pages: [1]

Author Topic: Merge gives error on custom date fields / bug fix code  (Read 271 times)

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Merge gives error on custom date fields / bug fix code
June 28, 2014, 10:39:19 am
I've noticed this for some time:  When trying to merge contacts, if custom fields happen to be date format, the merge will fail with a fatal error.

The error is that the merge expects the field to be in a format like 20140623123000 but the field downloaded from the DB is in a format like 2014-06-23 12:30:00.000000.

Has anyone noticed/fixed this before?  I came up with the following kludgy fix in CustomValueTable.php about line 516:

Code: [Select]
    while ($dao->fetch()) {
      $dataType = $dao->data_type == 'Date' ? 'Timestamp' : $dao->data_type;
      foreach ($fieldValues[$dao->cf_id] as $fieldValue) {
+       //Sometimes dates come through in format like 2014-04-13 12:34:34.0000
+       //If so we convert to timestamp format  like 20140413123434           
+        if ($dataType=='Timestamp' && (strpos($fieldValue['value'], ":")!== FALSE || strpos($fieldValue['value'], "-") !== FALSE )){     
+          $fieldValue['value'] = date ("YmdHms", strtotime($fieldValue['value']));     
+       }
        // Format null values correctly
        if ($fieldValue['value'] === NULL || $fieldValue['value'] === '') {
          switch ($dataType) {
            case 'String':
            case 'Int':
            case 'Link':
            case 'Boolean':
              $fieldValue['value'] = '';
              break;

            case 'Timestamp':
              $fieldValue['value'] = NULL;
              break;

            case 'StateProvince':
            case 'Country':
            case 'Money':
            case 'Float':
              $fieldValue['value'] = (int)0;
              break;
          }
        }
etc. . . . 

This is in CRM/Core/BAO/CustomValueTable.php function setValues

This seems like a fairly kludgy way around the problem - perhaps the value should be formatted correctly when it is first downloaded?  But if so, I don't know where that is.

If this is a known/continuing bug I can submit a bug report.

FYI I'm using CiviCRM 4.2.2 (with NUMEROUS upgrades/bug fixes).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Merge gives error on custom date fields / bug fix code

This forum was archived on 2017-11-26.