I have an export xml file generated by the export_to_xml.php script for a standard page.
I now need to import about 100 standard pages via the import_from_xml.php, however looking at the export file it would seem that the exported asset id is used in a lot of the xml action_id tags! Is this just to make the action_id tag unique?
Also the standard page that was exported had metadata attached to it, but I do not seem to be able to see any reference to the metadata values in the exported xml file?
The exported XML file has the main tags of <actions></actions>. Is it possible just to add more <action> tags to create a second asset within the main <actions> tag or would another new asset be contained in another set of <actions> tags?
I have looked at the xml_example.xml file in the script folder, but this seems to do with creating users and does not relate to metadata.
Cheers
Yes, this is just to ensure action IDs are unique as we use the same export script in our testing framework and it needs unique names in order to record time/memory/queries for each import action.
[quote]Also the standard page that was exported had metadata attached to it, but I do not seem to be able to see any reference to the metadata values in the exported xml file?[/quote]
I'm not sure if it exports metadata, but I thought it did. I'll let someone more familiar post about this.
[quote]The exported XML file has the main tags of <actions></actions>. Is it possible just to add more <action> tags to create a second asset within the main <actions> tag or would another new asset be contained in another set of <actions> tags?[/quote]
Yes, you can add more actions between those tags.
Metadata schema or value associations are not exported from the script (ref. 3.18.9).
The "set_metadata_schema" and "set_metadata_value" actions will be required to import metadata values.
I have provided a short example of how to apply a Metadata Schema and set a field within that schema to a Standard Page below.
This assumes that actions named "standard_page", "metadata_schema", "metadata_field" are included above these lines.
...
apply_metadata_schema
set_metadata_schema
[[output://standard_page.assetid]]
[[output://metadata_schema.assetid]]
1
set_metadata_field
set_metadata_value
[[output://standard_page.assetid]]
[[output://metadata_field.assetid]]
Fred
[quote]I have provided a short example of how to apply a Metadata Schema and set a field within that schema to a Standard Page below.
This assumes that actions named "standard_page", "metadata_schema", "metadata_field" are included above these lines.[/quote]
Hi Mark
Thanks for the reply.
I'm very sad to report that your assumptions fall very short of my knowledge on these import/export scripts. I still have very little information on how these scripts work having searched for any documentation on them at all.
I have my value for "standard_page" because that's the value I'm importing in my XML, but it would seem that I have to some how define the metadata schema in my import xml?? This seems strange to me as the schema will already exist within squiz! I would think that "metadata_schema" would be an id value? This value I could then reference for the values of the metadata fields, or do I have to some how define the metadata schema in full?
If I have to 'create' the matadata schema would this not create the metadata schema during my import? Is there any sort of get_… value?
Do you know if there is any documentation on what tags can be used in the xml import scripts and what the values can be used with what tags?
ie what values can be placed in the <action_type> tag?
Any information you could share or pointers to further documentation would be very welcome.
Cheers
[quote]I’m very sad to report that your assumptions fall very short of my knowledge on these import/export scripts. I still have very little information on how these scripts work having searched for any documentation on them at all.
I have my value for “standard_page” because that’s the value I’m importing in my XML, but it would seem that I have to some how define the metadata schema in my import xml?? This seems strange to me as the schema will already exist within squiz! I would think that “metadata_schema” would be an id value? This value I could then reference for the values of the metadata fields, or do I have to some how define the metadata schema in full?
If I have to ‘create’ the matadata schema would this not create the metadata schema during my import? Is there any sort of get_… value?
Do you know if there is any documentation on what tags can be used in the xml import scripts and what the values can be used with what tags?
ie what values can be placed in the <action_type> tag?
Any information you could share or pointers to further documentation would be very welcome.[/quote]
There is not any documentation available for the import/export scripts, however it is possible to obtain a feel of the XML import format by exporting existing assets which have been set up in the manner you desire for the import. This is done by running the export_to_xml script as detailed in the thread “Any documentation on XML importing”.
If the Metadata Schema referenced in the import already exists in MySource Matrix, then this schema and its fields can be referenced by asset ID. In this case, the schema and field would not need to be created in the import. For example, if the Standard Page was not yet associated with the schema the following XML would be used in place of the respective definitions in my previous post (assuming below that the asset IDs of the Metadata Schema and Metadata Field are 123 and 456 respectively):
123
456The values for the <action_type> tag refer to Trigger Actions, found in the core/assets/system/triggers/trigger_action_types directory - omitting the leading "trigger_" from the subdirectories shown. For example the "set_role" action_type will fire the Set Role trigger action. Each action will have one or more specific parameters to carry out the required action (eg; <schemaid> in the set_metadata_schema action).
Hi Mark
Many thanks for the information.
[quote]There is not any documentation available for the import/export scripts, however it is possible to obtain a feel of the XML import format by exporting existing assets which have been set up in the manner you desire for the import. This is done by running the export_to_xml script as detailed in the thread “Any documentation on XML importing”.[/quote]
I tried this approach of exporting my asset first, but without any documentation on these import/export scripts, found out the slow way that when you export an asset with metadata applied the script does not export the attached metadata!! Unless I’m missing something and you know of a way to export an asset with its metadata? Yes would be a good answer
[quote]If the Metadata Schema referenced in the import already exists in MySource Matrix, then this schema and its fields can be referenced by asset ID. In this case, the schema and field would not need to be created in the import. For example, if the Standard Page was not yet associated with the schema the following XML would be used in place of the respective definitions in my previous post (assuming below that the asset IDs of the Metadata Schema and Metadata Field are 123 and 456 respectively):
123
456The values for the <action_type> tag refer to Trigger Actions, found in the [i]core/assets/system/triggers/trigger_action_types[/i] directory - omitting the leading "trigger_" from the subdirectories shown. For example the "set_role" action_type will fire the Set Role trigger action. Each action will have one or more specific parameters to carry out the required action (eg; <schemaid> in the set_metadata_schema action).[/quote]
Thanks for this information. A lot more makes sence now on what these scripts are doing and how they are doing it.
Thanks :D
[quote]If the Metadata Schema referenced in the import already exists in MySource Matrix, then this schema and its fields can be referenced by asset ID. In this case, the schema and field would not need to be created in the import. For example, if the Standard Page was not yet associated with the schema the following XML would be used in place of the respective definitions in my previous post (assuming below that the asset IDs of the Metadata Schema and Metadata Field are 123 and 456 respectively):
123
456The values for the <action_type> tag refer to Trigger Actions, found in the core/assets/system/triggers/trigger_action_types directory - omitting the leading "trigger_" from the subdirectories shown. For example the "set_role" action_type will fire the Set Role trigger action. Each action will have one or more specific parameters to carry out the required action (eg; <schemaid> in the set_metadata_schema action).[/quote]
Mark, I wanting to create user assets, I can successfully create the user asset, set the metadata schema, but when it comes to setting data for the metadata fields I am getting the following errors:
12:13:09 - 14 Jan
User: MySource System (0)
Level: MySource Warning
(/scripts/import/import_from_xml.php:71) - Action ID "set_metadata_field_city_7" could not be executedThis happens for each action that is trying to set a metadata field, here is what I have for the xml:
set_metadata_field_city_1448
set_metadata_value
[[output://create_User_1448.assetid]]
4909
Everything seems to be correct. Any ideas why this error might arise?
Unfortunately the export_to_xml script does not export Metadata Schema associations or field values.
I would recommend creating an Asset Listing in your system to point to the assets you would like to export, and configure the "Display Format" Bodycopy as Raw HTML to output the expected field values as XML "set_metadata_field" actions to assign these fields. This would then be appended to your XML file and used for subsequent imports.
I would envision a "Display Format" similar to below (where "field_name" is replaced with the field name you wish to import, "field_id" with the field ID, and "asset_prefix" with a prefix matching the "create" actions in your XML file). This structure will be repeated for each field you need to import. This might need a bit of tweaking but hopefully this illustrates the concept.
set_metadata_field_%asset_id%_field_name
set_metadata_value
[[output://asset_prefix_%asset_id%.assetid]]
%field_id%
…and a "Page Display Format" to also assign the relevant schema (which you will need to hard-code) and show assets' field definitions:
set_metadata_schema
... [contents of set_metadata_schema action here] ...
%asset_listing%
[quote]Mark, I wanting to create user assets, I can successfully create the user asset, set the metadata schema, but when it comes to setting data for the metadata fields I am getting the following errors:
12:13:09 - 14 Jan
User: MySource System (0)
Level: MySource Warning
(/scripts/import/import_from_xml.php:71) - Action ID "set_metadata_field_city_7" could not be executed…
Everything seems to be correct. Any ideas why this error might arise?[/quote]
Sorry, I have missed out one important field for the set_metadata_value action.
(baseman, please also add this to any previous instructions I have given)
your_metadata_field_name_here
This action should now complete, assuming the <fieldid> and <field_name> are valid for the associated schema.
[quote]Sorry, I have missed out one important field for the set_metadata_value action.
(baseman, please also add this to any previous instructions I have given)
your_metadata_field_name_here
This action should now complete, assuming the <fieldid> and <field_name> are valid for the associated schema.[/quote]
Thanks Mark it is now working.
One thing though, we have a lot of fields that don't have data and we get a mysource error for every field that is empty. Is this normal? And if so, is there a way to suppress the errors?
set_metadata_field_city_50 [ -- ]
+--------------------------------------------------------------+
| MySource Warning |
|--------------------------------------------------------------|
| File : [SYSTEM_ROOT]/scripts/import/import_from_xml.php |
| Line : 71 |
|--------------------------------------------------------------|
| Action ID "set_metadata_field_city_50" could not be executed |
+--------------------------------------------------------------+
That's good to hear. ![]()
[quote]One thing though, we have a lot of fields that don't have data and we get a mysource error for every field that is empty. Is this normal? And if so, is there a way to suppress the errors?[/quote]
There is a setting on Metadata Fields to "Allow Empty" (or similar wording). Please uncheck this from fields which are likely to be empty before your import if empty fields are acceptable for this field. If the restriction is there for a good reason, the import data will need to be refined to exclude the XML actions for each "empty" instance.