Problem/Motivation

I'm testing the version on the latest developper branch of this module and have this problem:

I have a content type that is in fact a photobook. You can add photos to it.
When I export such a node, the yaml file has for every photo a full path to the url of the photo. In fact, on my local development system it starts with "http://localhost/...".
When I import this node to my live system, I see a conflict off course between the url's of the images. The import says "http://localhost..." and the live machine has "http://www.example.com/...".

In the yaml file of the node of the version 2.1 of this module there was no reference to url but only to the id of the image.
I can send some examples of both versions if needed.

By the way: the version on the branch is now 2bfa12c22b63b35ff1affcc106ea7e2520842cb0
By the way 2: I want to switch to Drupal 9 because version 8 doesn't receives any updates anymore and version 2.1 of this module is not Drupal 9 compatible. (and version 3.0beta1 does not work)

Steps to reproduce

Export a node with images on a local machine and import it on the live server.

Proposed resolution

If the url is needed, it should start after the specification of the server.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#7 wrong-parentclass-3251829-7.patch490 bytesericvl

Comments

EricVL created an issue. See original summary.

blanca.esqueda’s picture

Thanks for the report @EricVL,
If you can please send me the XML samples of both versions.

ericvl’s picture

Hi Blanca,

Thank tou for your response. Here they are.
The first is the 2.1 version and the last is the 3.0.dev version.

uuid:
  -
    value: 1feb5e21-fb41-4e16-8717-98c19cb95480
langcode:
  -
    value: nl
type:
  -
    target_id: fotoalbum
    target_type: node_type
    target_uuid: 5b75660f-8577-4a61-84e4-a483bff06fc0
revision_timestamp:
  -
    value: '2019-05-02T09:05:08+00:00'
    format: 'Y-m-d\TH:i:sP'
revision_uid:
  -
    target_type: user
    target_uuid: 4d2a29d6-d0b7-4ef3-8feb-84498298fa35
revision_log: {  }
status:
  -
    value: true
uid:
  -
    target_type: user
    target_uuid: 4d2a29d6-d0b7-4ef3-8feb-84498298fa35
title:
  -
    value: '2011-09-18 Festival Izegem'
created:
  -
    value: '2019-05-02T09:03:55+00:00'
    format: 'Y-m-d\TH:i:sP'
changed:
  -
    value: '2019-05-02T09:06:29+00:00'
    format: 'Y-m-d\TH:i:sP'
promote:
  -
    value: false
sticky:
  -
    value: false
default_langcode:
  -
    value: true
revision_translation_affected:
  -
    value: true
path:
  -
    alias: null
    pid: null
    langcode: nl
body:
  -
    value: "<p><span>Herfstmuziekfestival 2011 Izegem</span></p>\r\n"
    format: basic_html
    processed: "<p><span>Herfstmuziekfestival 2011 Izegem</span></p>\n"
    summary: ''
    summary_processed: ''
field_afdelingen:
  -
    target_type: taxonomy_term
    target_uuid: a3d87752-2c2e-4692-a3d3-3bed86953603
  -
    target_type: taxonomy_term
    target_uuid: c0033571-7f8b-4998-ab3f-81f033cd28db
field_image:
  -
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: cd65a710-4fee-4eaa-8de4-6cef0f2ed2b6
  -
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: e2c310ea-74a8-4b11-a315-df37840cd749
  -
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: 77ff8698-610c-481b-bb36-11d3a1f8f7d1
  -
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: ec2a63d5-e450-4315-887a-b8f3ef94f761
  -
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: 4f472872-34a2-40ae-b18f-0754371d5a2c
  -
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: e60a1023-798b-4f4e-8920-04fff32d893c
field_tags: {  }
_content_sync:
  entity_type: node
  entity_dependencies:
    user:
      - user.user.4d2a29d6-d0b7-4ef3-8feb-84498298fa35
      - user.user.4d2a29d6-d0b7-4ef3-8feb-84498298fa35
    taxonomy_term:
      - taxonomy_term.afdelingen.a3d87752-2c2e-4692-a3d3-3bed86953603
      - taxonomy_term.afdelingen.c0033571-7f8b-4998-ab3f-81f033cd28db
    file:
      - file.file.cd65a710-4fee-4eaa-8de4-6cef0f2ed2b6
      - file.file.e2c310ea-74a8-4b11-a315-df37840cd749
      - file.file.77ff8698-610c-481b-bb36-11d3a1f8f7d1
      - file.file.ec2a63d5-e450-4315-887a-b8f3ef94f761
      - file.file.4f472872-34a2-40ae-b18f-0754371d5a2c
      - file.file.e60a1023-798b-4f4e-8920-04fff32d893c

and

uuid:
  -
    value: 1feb5e21-fb41-4e16-8717-98c19cb95480
langcode:
  -
    value: nl
type:
  -
    target_id: fotoalbum
revision_timestamp:
  -
    value: '2019-05-02T09:05:08+00:00'
    format: 'Y-m-d\TH:i:sP'
revision_uid:
  -
    target_type: user
    target_uuid: 4d2a29d6-d0b7-4ef3-8feb-84498298fa35
revision_log: {  }
status:
  -
    value: true
uid:
  -
    target_type: user
    target_uuid: 4d2a29d6-d0b7-4ef3-8feb-84498298fa35
title:
  -
    value: '2011-09-18 Festival Izegem'
created:
  -
    value: '2019-05-02T09:03:55+00:00'
    format: 'Y-m-d\TH:i:sP'
changed:
  -
    value: '2019-05-02T09:06:29+00:00'
    format: 'Y-m-d\TH:i:sP'
promote:
  -
    value: false
sticky:
  -
    value: false
default_langcode:
  -
    value: true
revision_translation_affected:
  -
    value: true
body:
  -
    value: "<p><span>Herfstmuziekfestival 2011 Izegem</span></p>\r\n"
    format: basic_html
    processed: |
      <p><span>Herfstmuziekfestival 2011 Izegem</span></p>
    summary: ''
    summary_processed: ''
field_afdelingen:
  -
    target_type: taxonomy_term
    target_uuid: a3d87752-2c2e-4692-a3d3-3bed86953603
  -
    target_type: taxonomy_term
    target_uuid: c0033571-7f8b-4998-ab3f-81f033cd28db
field_image:
  -
    target_id: 42
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: cd65a710-4fee-4eaa-8de4-6cef0f2ed2b6
    url: 'http://localhost/site9/web/sites/default/files/Fotoalbum-2011-09-18%20Festival%20Izegem/293121_198103940260132_129195683817625_492331_1984774794_n.jpg'
  -
    target_id: 43
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: e2c310ea-74a8-4b11-a315-df37840cd749
    url: 'http://localhost/site9/web/sites/default/files/Fotoalbum-2011-09-18%20Festival%20Izegem/293987_198104116926781_129195683817625_492336_1617593910_n.jpg'
  -
    target_id: 44
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: 77ff8698-610c-481b-bb36-11d3a1f8f7d1
    url: 'http://localhost/site9/web/sites/default/files/Fotoalbum-2011-09-18%20Festival%20Izegem/298816_198103996926793_129195683817625_492333_31369441_n.jpg'
  -
    target_id: 45
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: ec2a63d5-e450-4315-887a-b8f3ef94f761
    url: 'http://localhost/site9/web/sites/default/files/Fotoalbum-2011-09-18%20Festival%20Izegem/299755_198104153593444_129195683817625_492337_1158735830_n.jpg'
  -
    target_id: 46
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: 4f472872-34a2-40ae-b18f-0754371d5a2c
    url: 'http://localhost/site9/web/sites/default/files/Fotoalbum-2011-09-18%20Festival%20Izegem/301134_198104030260123_129195683817625_492334_607856044_n.jpg'
  -
    target_id: 47
    alt: ''
    title: ''
    width: 720
    height: 482
    target_type: file
    target_uuid: e60a1023-798b-4f4e-8920-04fff32d893c
    url: 'http://localhost/site9/web/sites/default/files/Fotoalbum-2011-09-18%20Festival%20Izegem/316214_198104076926785_129195683817625_492335_1065758849_n.jpg'
field_tags: {  }
_content_sync:
  entity_type: node
  entity_dependencies:
    user:
      - user.user.4d2a29d6-d0b7-4ef3-8feb-84498298fa35
    taxonomy_term:
      - taxonomy_term.afdelingen.a3d87752-2c2e-4692-a3d3-3bed86953603
      - taxonomy_term.afdelingen.c0033571-7f8b-4998-ab3f-81f033cd28db

Good luck with it.
Greetings

ericvl’s picture

As a second tip:
The url tag was introduced in the commitnumber 420998cfeed939976cf667d854a2681e0ed33d99. The previous commit (583d32380f1638fc7e40c2021565e526e48f6f8d) didn't had this url tag.
I don't know if one has to have a reference to the file url here because the reference is in the file.file.... yaml.
Any way, if one need the url then the name of the server shouldn't be in it. Only what is following the webroot should be there.
Cheers

ericvl’s picture

Tip 3:

The files are not added to the entity_dependencies tag in the latest version. Could be a reason to create the (faulty) url.

Tip 4:

If you add a picture to a user then you have the phenomenon.
The url to the picture is a fixed path and the file dependency is not added to the user yaml.

Tip 5:
Create a content_type "article" and add a picture to it.
Same story.

ericvl’s picture

Status: Active » Needs review

Hello everybody,

I think I found a solution for a lot of bugs that are created here and even so for this one too.

In the file ImageItemNormalizer.php there is a class ImageItemNormalizer that is based on EntityReferenceFieldItemNormalizer. So the parent of the class ImageItemNormalizer is the class EntityReferenceFieldItemNormalizer.

The parent class EntityReferenceFieldItemNormalizer was ment to be the class that is created in the content_sync module and not the class EntityReferenceFieldItemNormalizer from the core.

Never the less, the EntityReferenceFieldItemNormalizer class from core is referenced in line 7 in the use statement.
This is probably wrong. It should use parent EntityReferenceFieldItemNormalizer from the code in the module.

If I comment out line 7 in the ImageItemNormalizer.php then the correct class is used as parent.

With this change, the long paths to the image files and even to media files in the exported yaml files are gone and I could use the yaml files to update the live server from the files created on my localhost.

One remark before you change the file: disable the module before changing and after the change enable the module again because a full new snapshot have to be created.
Can this be tested by the community to check if this could be a solution for a lot of frustrations.

Greetings
Eric

ericvl’s picture

StatusFileSize
new490 bytes

If anyone is interrested in the patch. Here it is.

prashant.c’s picture

Status: Needs review » Needs work

In #7 following is removed

use Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer;

but the class ImageItemNormalizer extends it.

class ImageItemNormalizer extends EntityReferenceFieldItemNormalizer 
ericvl’s picture

@Prashant.c
Yes, it extends from EntityReferenceFieldItemNormalizer but not from the one in core. It should extend from the EntityReferenceFieldItemNormalizer in the same folder (src/Normalizer) of the module. And if you delete the "use" line in the file, it will extends the one in the same folder.
I think, this was copied from another module, created a new EntityReferenceFieldItemNormalizer in the module and forgotten to delete the original line.
If you use the patch, it will work.

ericvl’s picture

Status: Needs work » Needs review
blanca.esqueda’s picture

Version: 3.0.x-dev » 4.0.x-dev
Component: Code » Import
ericvl’s picture

Status: Needs review » Reviewed & tested by the community