Closed (fixed)
Project:
CiviCRM Entity
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2016 at 15:54 UTC
Updated:
11 Mar 2016 at 03:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
lunk rat commentedComment #3
markusa commentedcan you post or send me the export code for your Rule?
Comment #4
lunk rat commented[EDIT] Here is a barebones simple component, which can be executed manually from the components screen. It takes two text parameters (First Name and Last Name). If successful it displays the created CiviCRM contact ID as a site message.
Here is the result from running this component on a fresh install of Drupal/CiviCRM:
Comment #5
markusa commentedok and what CiviCRM version are you using? This shouldn't matter but I'd like to know.
Comment #6
lunk rat commented@markusa I'm on 4.6.9 in the dev sandbox that I am working with. I could upgrade to 4.6.12 I suppose.
Comment #7
markusa commented@lunk_rat thanks, I'll review this rule on 4.6.9 and 4.6.12, but I don't think its going to be a CiviCRM specific issue anyway.
Comment #8
lunk rat commentedThank you @markusa for looking into this. I updated #4 with a new component more suitable for testing, which I tested on a fresh install. Same result.
Comment #9
lunk rat commentedI think I might have found a clue. Looking at the export of the rule, the second parameter is
param_civi_user. However, in the Rules UI, this second parameter appears with a label "Drupal user" and wants data of type User:I'm not sure if this is supposed to be the Drupal user that has permission to create contacts in CiviCRM, or the to-be Drupal user of the created contact, or ... what. I tried putting
1for a value. I also tried2(the CiviCRM cid of my Drupal user 1). No dice.At any rate, since the execution error barks about
Entity property civi_user doesn't support writing, I think that the problem lies here.Comment #10
markusa commentedI can replicate the issue. I'll have to dig in now and see what's up.
Comment #11
markusa commentedyeah, you know this is a pickle. I see why.. The way rules creates the entity is entirely via entity metadata wrappers, and the civi_user property has no way to set....so we need to find the way for that not to error.
It happens like this:
rule action triggers, which is the function:
rules_action_entity_create() in rules/modules/entity.eval.inc
which calls
entity_property_values_create_entity()
which is throwing the exception originally
http://www.drupalcontrib.org/api/drupal/contributions!entity!includes!en...
what we need is for rules to ignore that property and not include it in its form, so as no value, even null is attempted to be set....
Comment #12
lunk rat commented@markusa Okay, thank you for the explanation. What steps are needed to patch our way out of this pickle?! How can I help?
Comment #13
markusa commented@lunk_rat, I'm nearing to a solution, will be trying to get this into a beta2 release very soon, I've got a batch of updates queued up....later this week hopefully...
Comment #14
lunk rat commentedThank you @markusa, your timing couldn't be better. I sat down today to write a hack-job CiviCRM API rules handler for creating contacts because my project deadline has arrived and I need to create contacts in Rules.
Please let me know if I can help your efforts. Much appreciated! Cheers.
Comment #15
markusa commentedI've put in a merge request to get this in....should be coming down on Drupal.org from the maintainer in the next release.
today, you can download my fork of civicrm_entity to get it:
https://github.com/jackrabbithanna/civicrm_entity
Comment #16
lunk rat commented@markusa, thank you for the effort you have put into patching this. I installed the latest 7.x-2.0-beta1+17-dev which has the commit that references this issue. However, unfortunately I am still getting the exact same error:
Any clues?
Comment #17
markusa commentedok, make sure you've cleared your caches
Comment #18
lunk rat commentedCleared site caches, cleared Rules caches, ran cron, ran db updates, etc. etc.
Comment #19
markusa commentedok, saw the problem, I forgot 3 lines in the patch that I pushed up
I've updated the github repo with the fix
Comment #20
lunk rat commentedI cloned the repo, cleared caches and created a new component from scratch. Now when I execute, I get:
The website encountered an unexpected error. Please try again later.Comment #21
markusa commentedWhen I use the "Create entity" action it works for me, but it doesn't work with the component posted here.
I had to set the Contact Type to "Individual" and not 1
You need to use the name of the contact type there....
Individual, Household, or Organization
With that change, your component works for me!
Comment #22
lunk rat commented@markusa thank you! That did the trick. I changed the component so that 'Contact type' contains the string
Individualand all is working. This is great! Now we can create CiviCRM contacts with Rules . . . brilliant.Cheers.
Comment #23
markusa commentedComment #24
lunk rat commentedI have discovered a further problem: Even though the contact is created, the Provided variable "Created entity" always comes back empty. This should be populated with the newly created contact entity for use in subsequent actions.
Comment #25
markusa commentedComment #26
lunk rat commentedI can reproduce the problem on a fresh install.
Comment #27
lunk rat commentedI learned a bit more about what I am encountering. I was trying to use the
civicrm-contact:idof the newly created contact entity before it was actually getting saved to the database. So I guess I need to save the entity before it gets its CID from CiviCRM in order to use the CID in subsequent actions. I tried to execute a "Save entity" action but this action refuses to recognize the newly createdcivicrm_contactentity as an entity that it can save. Thoughts?Comment #28
lunk rat commentedNevermind, it works like any other
Create entityaction. For some reason I was expecting it to magically save immediately. When the rule is evaluated, the entity is saved. What I needed to do was create a component that creates the entity and then passes that entity as provided by the component after the component is evaluated. Then in a master rule I can use the provided entity in subsequent components/actions. It all works great!