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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Setting Boolean to 0 with CustomValueTable::setValues: not of the type Timestamp
Pages: [1]

Author Topic: Setting Boolean to 0 with CustomValueTable::setValues: not of the type Timestamp  (Read 1363 times)

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Setting Boolean to 0 with CustomValueTable::setValues: not of the type Timestamp
February 18, 2010, 06:53:02 am
Hi,

This call...

Code: [Select]
 $set_params = array(
    'entityID' => $providerID,
    'custom_72' => 0,
  );
  CRM_Core_BAO_CustomValueTable::setValues($set_params);

...where custom_72 is Boolean:

Code: [Select]
| Field                               | Type             | Null | Key | Default | Extra          |
| applicant_may_edit_submitted_eoi_72 | tinyint(4)       | YES  |     | NULL    |                |

...gives this error:

Code: [Select]
Sorry. A non-recoverable error has occurred.

One of parameters (value: 0) is not of the type Timestamp

Backtrace from setValues call in custom module:

Code: [Select]
.../civicrm/CRM/Core/Error.php, backtrace, 263
.../civicrm/CRM/Utils/Type.php, fatal, 256
.../civicrm/CRM/Core/DAO.php, validate, 918
.../civicrm/CRM/Core/DAO.php, composeQuery, 857
.../civicrm/CRM/Core/BAO/CustomValueTable.php, executeQuery, 221
.../civicrm/CRM/Core/BAO/CustomValueTable.php, create, 524
.../getcon_civi/getcon_civi.module, setValues, 1372

Thought I was going mad to begin with, double-checked the data type but I think it may be due to this change in CustomValueTable::create: http://fisheye2.atlassian.com/changelog/CiviCRM?cs=16957

Since I'm setting the field to 0 and 0 == null, this code would set $type to 'Timestamp', which might explain the error message.

I don't know what the intention of this changeset was - it relates to CRM-3290 - and whether a Boolean really should be treated as a Timestamp when $value is null. If it should, would changing "$value == null" to "$value === null" or "is_null($value)" preserve the intention of this changeset without breaking setting Booleans to 0 ?

Update: tried changing "$value == null" to "is_null($value)" as above, it fixes the original problem but breaks contact edit form submission  :o :

Code: [Select]
Sorry. A non-recoverable error has occurred.

One of parameters (value: ) is not of the type Boolean

This occurred while saving a contact where several boolean custom fields were not set, which I guess is the case triggering the error.

I reverted this last change and instead tried changing my parameters to CustomValueTable::setValues. I tried FALSE instead of 0...
Code: [Select]
  $set_params = array(
    'entityID' => $providerID,
    'custom_72' => FALSE,
  );
  CRM_Core_BAO_CustomValueTable::setValues($set_params);
but this resulted in the field not being modified: it remained as 1 in the db.

Dave J
« Last Edit: February 18, 2010, 08:03:14 am by davej »

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Setting Boolean to 0 with CustomValueTable::setValues: not of the type Timestamp
February 24, 2010, 06:44:13 am
Dave :
This patch should fix it for you :
http://fisheye2.atlassian.com/browse/CiviCRM/branches/v3.1/CRM/Core/BAO/CustomValueTable.php?r1=26389&r2=26393

Thanks for catching this!
-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Setting Boolean to 0 with CustomValueTable::setValues: not of the type Timestamp
February 24, 2010, 07:41:21 am
Hi Yashoda,

Quote from: Yashodha Chaku on February 24, 2010, 06:44:13 am
This patch should fix it for you :
http://fisheye2.atlassian.com/browse/CiviCRM/branches/v3.1/CRM/Core/BAO/CustomValueTable.php?r1=26389&r2=26393

Indeed it does! My CRM_Core_BAO_CustomValueTable::setValues call now works and the contact edit form still submits correctly. :)

Quote from: Yashodha Chaku on February 24, 2010, 06:44:13 am
Thanks for catching this!

Thanks for fixing it!

Dave J

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Setting Boolean to 0 with CustomValueTable::setValues: not of the type Timestamp

This forum was archived on 2017-11-26.