2017 © Pedro PelĂĄez
 

symfony-bundle import-bundle

Import data from files (.csv, .xml, ...)

image

2lenet/import-bundle

Import data from files (.csv, .xml, ...)

  • Wednesday, July 4, 2018
  • by sebheitzmann
  • Repository
  • 6 Watchers
  • 2 Stars
  • 360 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 9 Versions
  • 350 % Grown

The README.md

ImportBundle - Click And Mortar

Import Bundle can be used to populate entities from flat files (.csv, .xml, etc.), (*1)

1. Installation

Add package your composer.json file:, (*2)

"require": {
    ...
    "2lenet/import-bundle": "^1.0"
    ...
}

Launch composer update to add bundle to your project:, (*3)

composer update 2lenet/import-bundle

Add bundle in your app/AppKernel.php file:, (*4)

$bundles = array(
            ...
            new ClickAndMortar\ImportBundle\ClickAndMortarImportBundle(),
        );

2. Configuration

Configure bundle with your own entities in your app/config.yml file. Example:, (*5)

click_and_mortar_import:
  entities:
    customer_from_pim:
      model: Acme\DemoBundle\Entity\Customer
      repository: AcmeDemoBundle:Customer
      unique_key: id
      mappings:
        id: "ID"
        name: "Name_For_Customer"
        firstname: "FirstName"
        gender: "Sex"
        age: "Age"
        ...

You can define multiple imports for a single entity by simply changing the name of the import procedure (eg. add a new part under entities with name customer_from_ecommerce), (*6)

Options available:, (*7)

Option Mandatory Example Comment
model Yes Acme\DemoBundle\Entity\Customer Model name in your project
repository Yes AcmeDemoBundle:Customer Repository name for entity
unique_key No id Allows entities update from a property
only_update No false If true, only update existing entities by using unique_key
import_helper_service No acme.demo.import_helper.my_import_helper Extension point to complete classic mapping data on entity. Service must implements "ImportHelperInterface" interface

3. Usage

Launch import of file with command:, (*8)

php app/console candm:import /path/of/your/file/customers.csv customer_from_pim

Options available:, (*9)

Option Comment
--delete-after-import Delete file after import

4. Extension

You can create your own reader to read other file types., (*10)

Create your class (in YourOrganizationName/YourBundle/Reader/Readers) and extends AbstractReader:, (*11)

<?php

namespace YourOrganizationName\YourBundle\Reader\Readers;

use ClickAndMortar\ImportBundle\Reader\AbstractReader;

/**
 * Class MyCustomXmlReader
 *
 * @package YourOrganizationName\YourBundle\Reader\Readers
 */
class MyCustomXmlReader extends AbstractReader
{
    /**
     * Read my custom XML file and return data array
     *
     * @param string $path
     *
     * @return array
     */
    public function read($path)
    {
        $data = array();

        ...

        return $data;
    }

    /**
     * Support only xml type
     *
     * @param string $type
     *
     * @return bool
     */
    public function support($type)
    {
        return $type == 'xml';
    }
}

Declare class as service (in YourOrganizationName/YourBundle/Resource/config/services.yml) and add tag clickandmortar.import.reader:, (*12)

parameters:
  yourorganizationname.yourbundle.reader.my_custom_reader.class: YourOrganizationName\YourBundle\Reader\Readers\MyCustomXmlReader

services:
  yourorganizationname.yourbundle.reader.my_custom_reader:
    class: %yourorganizationname.yourbundle.reader.my_custom_reader.class%
    tags:
      - { name: clickandmortar.import.reader }

And that's all!, (*13)

The Versions

04/07 2018

dev-master

9999999-dev

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

04/07 2018

1.4.1

1.4.1.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

02/07 2018

1.4

1.4.0.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

28/06 2018

1.3.1

1.3.1.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

16/05 2018

1.3

1.3.0.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

03/05 2018

1.2

1.2.0.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

19/04 2018

1.1

1.1.0.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

by Simon CARRE
by SĂ©bastien HEITZMANN

15/03 2016

dev-phpunit-tests

dev-phpunit-tests

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Simon CARRE

15/03 2016

1.0

1.0.0.0

Import data from files (.csv, .xml, ...)

  Sources   Download

MIT

The Requires

 

by Simon CARRE