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) »
  • Inconsistency with create/enable/disable/delete activity_type from API
Pages: [1]

Author Topic: Inconsistency with create/enable/disable/delete activity_type from API  (Read 471 times)

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Inconsistency with create/enable/disable/delete activity_type from API
March 13, 2015, 07:49:05 am
I'm trying to get this working so that I can deal with the install of my extension. I'm really just needing the best approach to manage an activity_type for an extension install/uninstall/etc. Currently I'm trying to do it via API.

I need to actually understand how to enable/disable/delete an activity_type use the API or BAO/DAO. I have create working, but the other stuff doesn't seem to work properly using the API, or the API is totally messed up right now when it comes to activity types, OR I have no clue what I am doing  :'(.

The old ActivityType API is deprecated and we are now supposed to use OptionValue to create the activity type.

I do this to create my activity_type for a contact:
Code: [Select]
$result = civicrm_api3('OptionValue', 'create', array(
  'sequential' => 1,
  'name' => "Small Group Attendance1",
  'option_group_id' => 2,
));

It seems logical that deleting the activity would use the OptionValue delete API as here:
Code: [Select]
$result = civicrm_api3('OptionValue', 'delete', array(
  'sequential' => 1,
  'option_group_id' => 2,  // I tried with/without this
  'id' => 70, // activity_type_id
));

The first run of this command DOES something. It is successful. However, the activity_type is still there in the UI. If I run the command again I get the following error:
Code: [Select]
"error_message":"Could not interpret return values from function.",
"is_error":1

I also tried Activity Delete, and that initially runs successfully, but the activity is still there. A second run of it returns an error.

Can anyone explain what is actually going on here?

Would it make more sense to use the new managed hook for an activity_type?

I REALLY appreciate any help/direction for this.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inconsistency with create/enable/disable/delete activity_type from API
March 13, 2015, 08:03:25 am
I think using hook_managed is a good idea.
In both api calls I suggest passing 'option_group_id => "activity_type" instead of the value 2, because it will be more portable.
In the delete, maybe this is a case of caching? Try clearing caches after doing so and see if the option goes away.
Note that deleting an activity type (aka option group) does not delete associated activities automatically.
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Inconsistency with create/enable/disable/delete activity_type from API
March 13, 2015, 08:03:27 am
Can you check if it's still there in the db? Wondering if it's a cache issue

Clear caches see if it helps
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: Inconsistency with create/enable/disable/delete activity_type from API
March 17, 2015, 01:04:26 pm
I was able to figure out the issue. When dealing with activity type using the OptionValue API, you have to use the ID FOR the OptionValue when the activity type is created, not the activity type id. This was pretty annoying, but I can understand why this is the case.

Now If I pass the OptionValue ID, rather than the ActivityType ID it will delete properly.

Thanks for the help/suggestions!

BTW, what is the best approach to deleting ALL activity records for an activity type that has been deleted?
« Last Edit: March 17, 2015, 01:12:03 pm by lee.gooding »

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: Inconsistency with create/enable/disable/delete activity_type from API
March 18, 2015, 08:16:15 am
Quote from: Coleman Watts on March 13, 2015, 08:03:25 am
Note that deleting an activity type (aka option group) does not delete associated activities automatically.

Coleman, can you double check this? I'm deleting my activity type via option group and it is deleting the activities from the following tables: civicrm_activity_contact and civicrm_activity

I'm using the following API to delete the OptionValue:
Code: [Select]
$result = civicrm_api3('OptionValue', 'delete', array(
            'sequential' => 1,
            'id' => $option_value_id, // option value ID
        ));

Is there another table with activity data that I am missing?


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Inconsistency with create/enable/disable/delete activity_type from API

This forum was archived on 2017-11-26.