Problem/Motivation
I am trying to migrate a D7 file field to a D9 media file, using D7 view data export and D9 feeds.
my xml
<?xml version="1.0" encoding="UTF-8" ?>
<nodes>
<node>
<titre>test2</titre>
<Groupe-de-travail>Groupe 2 - Postes de travail portables</Groupe-de-travail>
<Type-de-document>Plaquette technique</Type-de-document>
<description><p>eeee</p>
</description>
<Fichier-s-><span class="file"><img class="file-icon" alt="PDF icon" title="application/pdf" src="/modules/file/icons/application-pdf.png" /> <a href="https://myD7site/fr/system/files/document_gt/plaquette_technique/groupe_2_-_postes_de_travail_portables/file-example_pdf_500_kb.pdf" type="application/pdf; length=469513">file-example_pdf_500_kb.pdf</a></span></Fichier-s->
</node>
<node>When importing :
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1: INSERT INTO "media_field_data" ("mid", "vid", "bundle", "langcode", "status", "uid", "name", "thumbnail__target_id", "thumbnail__alt", "thumbnail__title", "thumbnail__width", "thumbnail__height", "created", "changed", "default_langcode", "revision_translation_affected", "content_translation_source", "content_translation_outdated") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17); Array ( [:db_insert_placeholder_0] => 80 [:db_insert_placeholder_1] => 80 [:db_insert_placeholder_2] => docuement_gt [:db_insert_placeholder_3] => fr [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] =>
file-example_pdf_500_kb.pdf [:db_insert_placeholder_7] => 52 [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => 180 [:db_insert_placeholder_11] => 180 [:db_insert_placeholder_12] => 1676369082 [:db_insert_placeholder_13] => 1676369082 [:db_insert_placeholder_14] => 1 [:db_insert_placeholder_15] => 1 [:db_insert_placeholder_16] => und [:db_insert_placeholder_17] => 0 )
Comments
Comment #2
matoeil commentedComment #3
megachrizThe data you tried to import to media_field_data:name is too long.
<span class="file"><img class="file-icon" alt="PDF icon" title="application/pdf" src="/modules/file/icons/application-pdf.png" /> <a href="https://myD7site/fr/system/files/document_gt/plaquette_technique/groupe_2_-_postes_de_travail_portables/file-example_pdf_500_kb.pdf" type="application/pdf; length=469513">file-example_pdf_500_kb.pdf</a></span>has a length of 378 chars and the media name has a maximum length of 255 chars.So I would inspect your mappings to see if you mapped the things the way you intended.
Additionally, Feeds could perhaps try to check if content is too long to import. In that case it would provide a more user friendly warning message instead of displaying the SQL error.
Comment #4
matoeil commentedIs there an example of what information must contain the xml xpath to migrate a file from D7 to a D9 file media, using feeds?
In my case above , once correcting the text size, a media is created but it is not linked to the file system.
how does work the "Autocreate entity" option of feeds for media entities ?
Comment #5
matoeil commentedComment #6
matoeil commentedI understand it is not possible to import file to media ref fields ?
https://www.drupal.org/project/feeds/issues/2928904
It would be useful to indicate that limitation explicitely on the /project/feeds page.
Comment #7
matoeil commentedComment #8
megachrizIt is not possible to map to a media field yet, meaning a media field on a node for example. I've noted the areas where Feeds needs work on #1960800: [meta] Feeds 8.x roadmap.
Since I don't use the Media module myself much, I don't know exactly what the limitations for importing to media entities are. But since media entities do have a file field themselves, I expect it should be possible to import a file to a media entity. You would need to use the Media processor to do so. And map file url to "File: name".
The autocreate option was made especially for taxonomy terms, but it can work for other entity types too. The limitation is that it can only create the label/title of the entity to reference. This make sense for taxonomy terms, but not for every other entity type. I've not paid much attention to that feature yet, but it is indeed a weak spot (not user friendly part) of the module.
Comment #9
matoeil commentedthanks