Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete CSV import for type 'media' #245

Open
tybw opened this issue Feb 27, 2019 · 0 comments
Open

Incomplete CSV import for type 'media' #245

tybw opened this issue Feb 27, 2019 · 0 comments

Comments

@tybw
Copy link

tybw commented Feb 27, 2019

Summary

Importing 'media' type via CSV using console command resulted in incomplete data.

Description

  1. path column in bitbag_cms_media table was not set.
  2. link column in bitbag_cms_media table was not set.
  3. bitbag_cms_media_channels table was empty.
  4. bitbag_cms_media_sections table was set, but when deleting records from bitbag_cms_media on database level, the delete operation was not cascading to bitbag_cms_media_sections.

Version

Sylius version: 1.4.0
Bitbab SyliusCmsPlugin version: 2.3.0

Details

The command used:

bin/console bitbag:import:csv media media.csv

The CSV file header is as follows:

"channels","code","type","sections","image","name_en_NZ","content_en_NZ","link_en_NZ"

Leaving the column image blank or skipping the whole column from the CSV file won't help because exception occurs:

Import failed at index 42. Exception message: File cannot be blank.  

Solutions and Questions

I managed to fix problem 1, 2 and 3 with some quick fixes to src/Importer/MediaImporter.php.
Is there any reason against these fixes?

  1. Add to line 83 the following:
$media->setPath($this->getColumnValue('image', $row));
  1. Add to line 81 the following:
$media->setLink($this->getTranslatableColumnValue('link__locale__', $locale, $row));
  1. Add to line 106 the following:
'link__locale__'
  1. Add to line 85 of the same file the following:
$this->importerChannelsResolver
     ->resolve(
         $media,
         $this->getColumnValue(self::CHANNELS_COLUMN, $row)
     );

As for problem 4, I saw from the entity's doctrine orm settings src/Resources/config/doctrine/Media.orm.yml that onDelete: CASCADE was set for the section side of the many-to-many relation only. Is there any reason it is not set for the block side of the relation?

    manyToMany:
        sections:
            targetEntity: BitBag\SyliusCmsPlugin\Entity\SectionInterface
            joinTable:
                name: bitbag_cms_media_sections
                joinColumns:
                    media_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    section_id:
                        referencedColumnName: id
                        onDelete: CASCADE
@tybw tybw changed the title Incomplete importing 'media' type via CSV Incomplete CSV import for type 'media' Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant