We're updating the issue view to help you get more done. 

Exporter strips long attribute names creating invalid XML profiles

Description

I've installed the SPECTRUM installation profile which comes with CA 1.6.1. I've made a few minor modification to the data model to match with my own organisations' business requirements.

I can export the installation profile, but when I try to use it again, it fails with an error: "There were errors parsing the profile(s): Profile validation failed. Your profile doesn't conform to the required XML schema."

See: http://docs.collectiveaccess.org/wiki/Cookbook_Chapter_2:_Installation_Profiles

I've validated the resulting profile with xmllint using this command:

xmllint --no-out --schema profile.xsd myschema.xml

Validation fails because of this error: placement with duplicate key "ca_attribute_fieldCollectionEv"

When I go check inside myschema.xml, I can see that I have indeed two elements with the same code attribute:

<placement code="ca_attribute_fieldCollectionEv">
<bundle>ca_attribute_fieldCollectionEventName</bundle>
</placement>
<placement code="ca_attribute_fieldCollectionEv">
<bundle>ca_attribute_fieldCollectionEventRefNo</bundle>
</placement>

Obviously, this is a bug. I've hunted through the CA codebase and found the cause:

In ConfigurationExporter.php on line 738: this happens to generate the code attribute value:

$vo_placement->setAttribute("code", $this->makeIDNO($va_placement["placement_code"]));

The function signature of the makeIDNO() method accepts a $pn_length parameter which is by default set to 30 characters.

This means that any placement code or ca_attribute prefixed attribute name which is longer then 30 characters, will get truncated. This means that you risk creating duplicate keys.

Suggestion: get rid of the truncation logic in the makeIDNO method on line 1277.

It's not advisable to truncate a machine key in the first place. In this case, the profile wouldn't work on installation, worst case would be that it does work but you risk ending up with an inconsistent database if other parts of the profile refer to a the original, unaltered machine code.

Environment

Using my ansible box: https://github.com/netsensei/ansible-collectiveaccess

Ubuntu Trusty Thar 14.04
512Mb RAM
NGinX based
PHP 5.6 with a few required extensions
MySQL database

Assignee

User known

Reporter

Matthias Vandermaesen

Labels

None

Components

Affects versions

Priority

Major
Configure