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 »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Custom field values messed up (1.8->2.0)
Pages: [1]

Author Topic: Custom field values messed up (1.8->2.0)  (Read 2672 times)

barrylb

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Custom field values messed up (1.8->2.0)
June 30, 2008, 02:02:16 am
I am trying to upgrade from 1.8->2.04 and my custom field values are messed up for many custom fields... It appears that values for one contact are being copied from a different contact.  Obviously a major problem! 

Any idea how I debug this problem?  Or is there some manual process I can do?  There are no errors shown in the upgrade process and I think I ran all the correct steps. 

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Custom field values messed up (1.8->2.0)
June 30, 2008, 09:36:34 am
In 1.8 / 1.9 "civicrm_custom_value" table is used to store custom values whereas in 2.0 its the table with the format "civicrm_value_customGrpName".

You will need to look for an entry with different custom field values in 1.8 & 2.0, for same contact(-id) / contribution(-id) ..etc for which the custom-group is being used for. Also check in 1.9 just to confirm if the problem is /w 1.8 -> 1.9 or 1.9 -> 2.0 upgrade.
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

barrylb

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: Custom field values messed up (1.8->2.0)
June 30, 2008, 10:20:33 pm
Ok, I've done an upgrade from 1.8->1.9 which worked correctly.  The problem happens with 1.9 -> 2.0 and I believe I have found a bug.

I have reviewed a file CRM/Upgrade/TwoZero/Form/Step5.php which does the custom field upgrades. There is an SQL statement on line 177:

INSERT INTO {$group->table_name} (domain_id,entity_id,{$field->column_name})
SELECT $domainID, cv.entity_id, $col FROM civicrm_custom_value cv
WHERE cv.custom_field_id={$field->id}
ON DUPLICATE KEY UPDATE {$field->column_name}={$col}

It seems the "ON DUPLICATE KEY UPDATE" part is causing incorrect values to be put into the table. I am not an expert on this feature so I can't explain the reasons but I ran some statements manually and it put in the wrong values.

I believe I have a fix, that is to insert all the rows first, then to update the fields. I added the following before while ($field->fetch()) { on line 172.

$query = "
INSERT INTO {$group->table_name} (domain_id,entity_id)
SELECT DISTINCT $domainID, cv.entity_id
FROM civicrm_custom_value cv";
$res    = $this->runQuery( $query );
$res->free();

Then a few lines down I changed the first-mentioned SQL query to this:

UPDATE {$group->table_name} cvu, civicrm_custom_value cv
SET cvu.{$field->column_name} = $col
WHERE cvu.domain_id=$domainID AND cvu.entity_id=cv.entity_id AND cv.custom_field_id={$field->id}

I ran the upgrade process with this modification and all my custom values seem correct now. I would appreciate any feedback on this - have I done the right thing? Am I right that this a bug? Surely this is affecting other people?


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: Custom field values messed up (1.8->2.0)
June 30, 2008, 11:16:39 pm

this has not come up before. might be a mysql version issue. what version of mysql are you using

thanx

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

barrylb

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: Custom field values messed up (1.8->2.0)
June 30, 2008, 11:34:46 pm
MySQL version is 5.0.38

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: Custom field values messed up (1.8->2.0)
June 30, 2008, 11:42:03 pm

check: http://bugs.mysql.com/bug.php?id=27210

it does claim that this is fixed in 5.0.38, but am not sure. i suspect we would have had other reports by now if folks had tripped on this issue

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

barrylb

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: Custom field values messed up (1.8->2.0)
July 05, 2008, 11:36:52 am
Ok, I have upgraded to MySQL 5.0.51a and the CiviCRM upgrade seems to have worked properly this time. My custom field values seem to be correct. So it would seem it was an issue with my earlier version of MySQL. 

I don't know if I would have solved it without your suggestion - so thanks very much!

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Custom field values messed up (1.8->2.0)
July 07, 2008, 09:12:24 am
I had a similar problem, but it was related to the names of my custom fields - they had funny characters like quotes in them, which created obvious problems because the table names it was trying to create weren't allowed.

So, in case anyone reads this (and maybe it should go in some documentation?) -- be sure to check your custom field names and remove any characters that aren't lowercase or underscore before trying a 2.0 upgrade.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Custom field values messed up (1.8->2.0)

This forum was archived on 2017-11-26.