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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • changing the status of Contribution can break if you aren't an auth user
Pages: [1]

Author Topic: changing the status of Contribution can break if you aren't an auth user  (Read 734 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
changing the status of Contribution can break if you aren't an auth user
October 08, 2014, 12:47:31 am
Hi,

I'm trying to do the equivalent of

Code: [Select]
$drush civicrm-api contribution.create contribution_status_id=1  id=1 debug=1

and when I run it without starting a session (-u 1), something I would really want to avoid in my real case, I get:

Code: [Select]
Array
(
    [is_error] => 1
    [error_message] => A fatal error was triggered: Not enough data to create activity object,
    [trace] => #0 /var/www/civi.git/CRM/Activity/BAO/Activity.php(284): CRM_Core_Error::fatal('Not enough data...')
#1 /var/www/civi.git/CRM/Activity/BAO/Activity.php(1859): CRM_Activity_BAO_Activity::create(Array)
#2 /var/www/civi.git/CRM/Contribute/BAO/Contribution.php(302): CRM_Activity_BAO_Activity::addActivity(Object(CRM_Contribute_BAO_Contribution), 'Offline')
#3 [internal function]: CRM_Contribute_BAO_Contribution::create(Array, Array)
#4 /var/www/civi.git/api/v3/utils.php(1173): call_user_func_array(Array, Array)
#5 /var/www/civi.git/api/v3/Contribution.php(73): _civicrm_api3_basic_create('CRM_Contribute_...', Array, 'Contribution')
#6 /var/www/civi.git/api/api.php(88): civicrm_api3_contribution_create(Array)
#7 /var/www/civi.git/drupal/drush/civicrm.drush.inc(1147): civicrm_api('contribution', 'create', Array)
#8 [internal function]: drush_civicrm_api('contribution.cr...', 'contribution_st...', 'id=1', 'debug=1')
#9 /usr/share/php/drush/includes/command.inc(334): call_user_func_array('drush_civicrm_a...', Array)
#10 /usr/share/php/drush/includes/command.inc(208): _drush_invoke_hooks('civicrm-api', Array, 'civicrm')
#11 [internal function]: drush_command('contribution.cr...', 'contribution_st...', 'id=1', 'debug=1')
#12 /usr/share/php/drush/includes/command.inc(175): call_user_func_array('drush_command', Array)
#13 /usr/share/php/drush/drush.php(92): drush_dispatch(Array)
#14 /usr/share/php/drush/drush.php(61): _drush_bootstrap_and_dispatch()
#15 /usr/share/php/drush/drush.php(16): drush_main()
#16 {main}

I don't understand why it's trying to create an activity when I'm updating an existing contribution. Is this normal and expected behaviour?


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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: changing the status of Contribution can break if you aren't an auth user
October 08, 2014, 02:12:11 am
Hmm - my guess is it should be created on create rather than update. Although it would be legit it it were an activity to reflect the change in the contribution for some reason

Seems likely that it is a bug
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: changing the status of Contribution can break if you aren't an auth user
October 08, 2014, 09:20:55 am
I'm not sure I understand the aim of that activity in the 1st place.

What is this in the activity that you won't get from the contribution record?

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: changing the status of Contribution can break if you aren't an auth user
October 08, 2014, 02:10:22 pm
Well - I think that is a whole different discussion - but I think that if creating a contribution through the UI creates one then through the api should too. I would note that we do have customers that use the activity listing in various wierd & wonderful ways - so I wouldn't be hurrying to make a change
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: changing the status of Contribution can break if you aren't an auth user
October 09, 2014, 12:22:18 am
The contribution is created normally via the contribution page, and I don't see any activity?

Here I'm not trying to create but to update a contribution, trying to create an activity related to logged in user (that doesn't happen to exist in my case) doesn't quite make sense, but the greater context of creating activities based on (insert hypothetical reasons and factor in some moon phase based one for comical effect) when you create a contribution is unclear enough I'm not sure what's expected behaviour.

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

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: changing the status of Contribution can break if you aren't an auth user
October 24, 2014, 03:31:33 am
Hey Xavier and others,

Did you found a work around? We have the same problem our financial system (Odoo) updates the payment status of contributions in Civi. But we get the error as soon as we try to update the Contribution. It is on Civi 4.4.5

Jaap
Developer at Edeveloper / CiviCoop

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: changing the status of Contribution can break if you aren't an auth user
October 24, 2014, 08:36:57 am
It does make sense to generate an activity when changing a contribution amount, so maybe that's why an activity is being generated in your case.

Since even changing the status of a contribution has knock-on effects in the whole bookkeeping system, I wouldn't be surprised at quite a lot of complexity going on behind the scenes with any change to a contribution record.

I do update the status of contribution records in a payment processor extension via the api (using 'create' instead of 'update') and it's working well even when I have no idea what else might be happening (though I haven't tested it with 4.5). So maybe there are other issues involved.

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: changing the status of Contribution can break if you aren't an auth user
October 24, 2014, 08:50:10 am
The issue appears when you are not logged in and using the API via the REST interface.
My analyses so far has been that in the Contribution BAO it is looking for an activity of type Contribution and source_record_id of the contribution ID. This exist in the database but it doesn't get found by the REST API. So the it tries to create an activity with only a status parameter.
Developer at Edeveloper / CiviCoop

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: changing the status of Contribution can break if you aren't an auth user
October 24, 2014, 11:22:11 am
Hey

I have located the problem. Once a conribution status is set from pending to complete. CiviCRM will create an activity. When activity is created the source contact is set to the User ID from the session. Doing an API call from drush or Rest means that there is no user id set into the session.

For the latter problem (no user id in session) by a rest call I have made an extension which includes an API Wrapper which will store the User ID into the session because we know the user ID from the API key.

See github (https://github.com/CiviCooP/org.civicoop.apiuidfix) for my extension
Developer at Edeveloper / CiviCoop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • changing the status of Contribution can break if you aren't an auth user

This forum was archived on 2017-11-26.