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) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Managed Entities error when installing new module or extension
Pages: [1]

Author Topic: Managed Entities error when installing new module or extension  (Read 1444 times)

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Managed Entities error when installing new module or extension
August 01, 2013, 10:58:27 am
Hi,

I'm using managed entities for a project we are developing. Its very useful to initialize CiviCRM startup structure when the extension is installed.
I'm creating more than 1000 entities (from Contact Types, Custom Groups / Fields, Profiles, Contacts, Relationships, etc).

I'm facing an issue when I try to install another CiviCRM Extension or a Drupal module after this extension was installed.

The error I get is something like this

Code: [Select]
Sorry but we are not able to provide this at the moment.
API error: Field: `name` must be unique. An conflicting entity already exists - id: 84
Return to home page.

I've checked civicrm_managed table and doesn't seem to be two rows with same name for id 84 (this was my first guess reading the error, not really sure how is implemented anyway...)

Any clue where I can start debugging?

cheers!

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Managed Entities error when installing new module or extension
August 01, 2013, 11:30:01 am
Holy smokes! I thought one would be ambitious to have 5 managed-entities in an extension. I'm impressed it didn't completely crash with 1000. ;)

Some thoughts/ideas/questions on debugging:

 * After doing a grep, it looks like the error message ("An conflicting entity already exists") is generated by _civicrm_api3_validate_uniquekey() in api/v3/utils.php.

 * The error is passed along via CRM_Core_ManagedEntities::onApiError() which also writes out the API request to the CiviCRM log (including $params and $results). So check the log to see which $params cause the problem.

 * A couple good enhancements/patches to CRM_Core_ManagedEntities would be to:
   - Pass the API entity-name/action-name into onApiError() and write those values out the log.
   - Pass 'debug => 1' into every call to civicrm_api(). This should add a backtrace to $result.

 * To see a full list of what operations are executed during reconciliation, the only real option right now is to sprinkle log/debug code into CRM_Core_ManagedEntities.

 * An interesting approach might be to comment-out half the ME's and see if the problem persists. Then alternately comment-out by halves to isolate problematic entities (like a binary-search.)

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Managed Entities error when installing new module or extension
August 01, 2013, 12:14:55 pm
Quick aside - for creating custom fields and profiles, you might find this easier / more reliable:

http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension#CreateaModuleExtension-Addcustomfields%28CiviCRMv4.4+%29

(This requires for CiviCRM v4.4-git when generating the extension. However, last time I tested, you could install the extension on v4.3.)

The functional difference between this approach and the ME-approach is upgrades. ME's try to be clever about automatically upgrading, and this works well for simple entities, but it leads to dumb things in other cases. For example, consider upgrading custom-field schema -- e.g. suppose MyExtension v1.0 created two SELECT fields but v2.0 consolidated the same information into one free-form TEXT field. During upgrade, ME's would simply create the TEXT field and *destroy* the old SELECT fields -- causing data loss. I think it's better to define schema without ME's -- so that you can define the migration logic (in CRM_*_Upgrader::upgrade_*).

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Managed Entities error when installing new module or extension
August 02, 2013, 06:02:28 am
Hi Tim,

thanks for your tips. I tried to debug and find the cause of the error, but I had no luck. Too many entities are created.
I didn't want to have some issues with this ME if the user wants to install another module / extension, so I changed a little bit the approach of the set up.

I had one *.mgd.php file per Entity Type (ContactType.mgd.php, ParticipantRole.mgd.php, RelationshipType.mgd.php, etc), so I renamed them as *.ins.php
And then I recreated the idea of _gc_civix_civicrm_managed() but in hook_civicrm_install(), so the same files can be used, but they are not going to be under Managed Entities

Code: [Select]
function gc_civicrm_install() {
// Install entitites
$mgdFiles = _gc_civix_find_files(__DIR__, '*.ins.php');
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
civicrm_api($e['entity'], 'create', $e['params']);
}
}

return _gc_civix_civicrm_install();
}

So far I think is still a great approach to set up a CiviCRM in one step from an extension installation, writing just "easy" php files.

cheers!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Managed Entities error when installing new module or extension

This forum was archived on 2017-11-26.