Skip to content

Commit

Permalink
Bundle initialization and processors/writers
Browse files Browse the repository at this point in the history
Bundle initialization, helper and processors/writers
  • Loading branch information
DnD-Mimosa committed Jan 2, 2015
1 parent 350703d commit 2147137
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/DnD-MagentoConnectorBundle.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/scopes/scope_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

420 changes: 420 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions DependencyInjection/DnDMagentoConnectorExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpnamespace DnD\Bundle\MagentoConnectorBundle\DependencyInjection;use Symfony\Component\HttpKernel\DependencyInjection\Extension;use Symfony\Component\DependencyInjection\ContainerBuilder;use Symfony\Component\DependencyInjection\Loader;use Symfony\Component\Config\FileLocator;/** * Base connector bundle extension * * @author DnD Mimosa <[email protected]> * @copyright 2014 Agence Dn'D (http://www.dnd.fr) * @license Agence Dn'D */class DnDMagentoConnectorExtension extends Extension{ /** * {@inheritdoc} */ public function load(array $configs, ContainerBuilder $container) { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('readers.yml'); $loader->load('processors.yml'); $loader->load('writers.yml'); }}
Expand Down
1 change: 1 addition & 0 deletions DnDMagentoConnectorBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpnamespace DnD\Bundle\MagentoConnectorBundle;use Symfony\Component\HttpKernel\Bundle\Bundle;class DnDMagentoConnectorBundle extends Bundle{}
Expand Down
1 change: 1 addition & 0 deletions Helper/SFTPConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php namespace DnD\Bundle\MagentoConnectorBundle\Helper;class SFTPConnection{ private $connection; private $sftp; public function __construct($host, $port=22) { $this->connection = @ssh2_connect($host, $port); if (! $this->connection) throw new \Exception("Could not connect to $host on port $port."); } public function login($username, $password) { if (! @ssh2_auth_password($this->connection, $username, $password)) throw new \Exception("Could not authenticate with username $username " . "and password $password."); $this->sftp = @ssh2_sftp($this->connection); if (! $this->sftp) throw new \Exception("Could not initialize SFTP subsystem."); } public function uploadFile($local_file, $remote_file) { $sftp = $this->sftp; $stream = @fopen("ssh2.sftp://". $sftp . $remote_file, 'w'); if (! $stream) throw new \Exception("Could not open file: $remote_file"); $data_to_send = @file_get_contents($local_file); if ($data_to_send === false) throw new \Exception("Could not open local file: $local_file."); if (@fwrite($stream, $data_to_send) === false) throw new \Exception("Could not send data from file: $local_file."); @fclose($stream); } public function createDirectory($path) { $sftp = $this->sftp; if(is_dir("ssh2.sftp://". $sftp . $path)) return; $stream = @mkdir("ssh2.sftp://". $sftp . $path, 0777, true); if (! $stream) throw new \Exception("Could not create directory: $path"); }}
Expand Down
1 change: 1 addition & 0 deletions Processor/AttributeProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpnamespace DnD\Bundle\MagentoConnectorBundle\Processor;use Symfony\Component\Validator\Constraints as Assert;use Akeneo\Bundle\BatchBundle\Item\ItemProcessorInterface;use Akeneo\Bundle\BatchBundle\Item\AbstractConfigurableStepElement;use Gedmo\Sluggable\Util\Urlizer;/** * * @author Mimosa <[email protected]>, Merlin <[email protected]> * @copyright 2014 Dn'D (http://www.dnd.fr) * @license http://www.dnd.fr */class AttributeProcessor extends AbstractConfigurableStepElement implements ItemProcessorInterface{ /** * {@inheritdoc} */ public function process($item) { $result = []; $result['type'] = $item->getAttributeType(); $result['code'] = $item->getCode(); $result['label-en_US'] = $item->setLocale('en_US')->getLabel(); $result['label-fr_FR'] = $item->setLocale('fr_FR')->getLabel(); $result['group'] = $item->getGroup()->getCode(); $result['unique'] = ($item->isUnique()) ? 1 : 0; $result['useable_as_grid_column'] = ($item->isUseableAsGridColumn()) ? 1 : 0; $result['useable_as_grid_filter'] = ($item->isUseableAsGridFilter()) ? 1 : 0; $result['allowed_extensions'] = ''; $result['metric_family'] = ''; $result['default_metric_unit'] = ''; $result['localizable'] = ($item->isLocalizable()) ? 1 : 0; $result['scopable'] = ($item->isScopable()) ? 1 : 0; if($item->getAttributeType() == 'pim_catalog_metric'){ $result['metric_family'] = $item->getMetricFamily(); $result['default_metric_unit'] = $item->getDefaultMetricUnit(); } if($item->getAttributeType() == 'pim_catalog_image'){ $result['allowed_extensions'] = implode(",", $item->getAllowedExtensions()); } $families = array(); foreach($item->getFamilies() as $family){ array_push($families, $family->getCode()); } $result['families'] = implode(",", $families); return $result; } /** * {@inheritdoc} */ public function getConfigurationFields() { return array(); }}
Expand Down
1 change: 1 addition & 0 deletions Processor/FamilyProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpnamespace DnD\Bundle\MagentoConnectorBundle\Processor;use Symfony\Component\Validator\Constraints as Assert;use Pim\Bundle\BaseConnectorBundle\Validator\Constraints\Channel as ChannelConstraint;use Pim\Bundle\CatalogBundle\Manager\ChannelManager;use Akeneo\Bundle\BatchBundle\Item\ItemProcessorInterface;use Akeneo\Bundle\BatchBundle\Item\AbstractConfigurableStepElement;/** * * @author Mimosa <[email protected]> * @copyright 2014 Agence Dn'D (http://www.dnd.fr) * @license http://www.dnd.fr */ class FamilyProcessor extends AbstractConfigurableStepElement implements ItemProcessorInterface{ /** * {@inheritdoc} */ public function process($family) { $result = []; $result['code'] = $family->getCode(); $result['label'] = $family->setLocale('fr_FR')->getLabel(); return $result; } /** * {@inheritdoc} */ public function getConfigurationFields() { return array(); } }
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,45 @@ DnD-MagentoConnectorBundle
==========================

Connecteur Magento pour le PIM Akeneo

Ce connecteur vous permettra d'exporter vos données du PIM vers un autre serveur via une connexion SFTP

Vous aurez donc besoin des informations suivantes :

- Hôte
- Port
- Nom d'utilisateur
- Mot de passe

Attention : la partie qui interprète les fichiers côté Magento (ou autres solutions) n'est pas présente sur ce repository

# Pré-requis

- php5
- php5-ssh2
- Akeneo PIM 1.2.x stable

# Instructions d'installation

Assurer vous que votre serveur possède la librairie ssh2 (voir http://php.net/manual/fr/ssh2.installation.php)

## Installation du connecteur sur le PIM de Akeneo

Si ce n'est pas déjà fait, installer le PIM de Akeneo (voir [cette documentation](https://github.com/akeneo/pim-community-standard))

Récuperer composer :

$ cd /my/pim/installation/dir
$ curl -sS https://getcomposer.org/installer | php

Installer le DnD-MagentoConnectorBundle avec composer :

$ php composer.phar require agencednd/magento-connector-bundle:1.0.*@stable

Activer le bundle dans le fichier 'app/AppKernel.php', dans la fonction 'registerBundles', avant la ligne 'return $bundles' :

$bundles[] = new DnD\MagentoConnectorBundle\DnDMagentoConnectorBundle();

# Configuration

Aller dans Diffuser > Profil d'export puis créer votre export de type DnD Magento Connector Bundle
1 change: 1 addition & 0 deletions Resources/config/batch_jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connector: name: DnD Magento Connector Bundle jobs: dnd_csv_product_export: title: dnd_magento_connector.jobs.dnd_csv_product_export.title type: export steps: export: title: dnd_magento_connector.jobs.dnd_csv_product_export.export.title services: reader: pim_base_connector.reader.doctrine.product processor: pim_base_connector.processor.product_to_flat_array writer: dnd_magento_connector.writer.file.csv_product parameters: batch_size: 10 dnd_csv_category_export: title: dnd_magento_connector.jobs.dnd_csv_category_export.title type: export steps: export: title: dnd_magento_connector.jobs.dnd_csv_category_export.export.title services: reader: pim_base_connector.reader.orm.category processor: pim_base_connector.processor.csv_serializer.homogeneous writer: dnd_magento_connector.writer.file dnd_csv_attribute_export: title: dnd_magento_connector.jobs.dnd_csv_attribute_export.title type: export steps: export: title: dnd_magento_connector.jobs.dnd_csv_attribute_export.export.title services: reader: pim_base_connector.reader.orm.attribute processor: dnd_magento_connector.processor.attribute writer: dnd_magento_connector.writer.file.csv dnd_csv_attribute_option_export: title: dnd_magento_connector.jobs.dnd_csv_attribute_option_export.title type: export steps: export: title: dnd_magento_connector.jobs.dnd_csv_attribute_option_export.export.title services: reader: pim_base_connector.reader.orm.attribute_option processor: pim_base_connector.processor.csv_serializer.homogeneous writer: dnd_magento_connector.writer.file dnd_csv_association_type_export: title: dnd_magento_connector.jobs.dnd_csv_association_type_export.title type: export steps: export: title: dnd_magento_connector.jobs.dnd_csv_association_type_export.export.title services: reader: pim_base_connector.reader.orm.association_type processor: pim_base_connector.processor.csv_serializer.homogeneous writer: dnd_magento_connector.writer.file dnd_csv_group_export: title: dnd_magento_connector.jobs.dnd_csv_group_export.title type: export steps: export: title: dnd_magento_connector.jobs.dnd_csv_group_export.export.title services: reader: pim_base_connector.reader.orm.group processor: pim_base_connector.processor.csv_serializer.homogeneous writer: dnd_magento_connector.writer.file csv_family_export: title: dnd_magento_connector.jobs.csv_family_export.export.title type: export steps: export: title: dnd_magento_connector.jobs.csv_family_export.export.title services: reader: dnd_magento_connector.reader.orm.family processor: dnd_magento_connector.processor.family writer: dnd_magento_connector.writer.file.csv#TODO FULL EXPORT#TODO SEND FILE BY FTP
Expand Down
1 change: 1 addition & 0 deletions Resources/config/processors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parameters: dnd_magento_connector.processor.family.class: DnD\Bundle\MagentoConnectorBundle\Processor\FamilyProcessor dnd_magento_connector.processor.attribute.class: DnD\Bundle\MagentoConnectorBundle\Processor\AttributeProcessorservices: dnd_magento_connector.processor.family: class: %dnd_magento_connector.processor.family.class% parent: pim_base_connector.processor.transformer arguments: - %pim_catalog.entity.family.class% dnd_magento_connector.processor.attribute: class: %dnd_magento_connector.processor.attribute.class%
Expand Down
1 change: 1 addition & 0 deletions Resources/config/readers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parameters: pim_base_connector.reader.orm.entity.class: Pim\Bundle\BaseConnectorBundle\Reader\ORM\EntityReader services: # readers dnd_magento_connector.reader.orm.family: class: %pim_base_connector.reader.orm.entity.class% arguments: - '@doctrine.orm.default_entity_manager' - %pim_catalog.entity.family.class%
Expand Down
1 change: 1 addition & 0 deletions Resources/config/writers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parameters: dnd_magento_connector.writer.file.class: DnD\Bundle\MagentoConnectorBundle\Writer\File\FileWriter dnd_magento_connector.writer.file.csv.class: DnD\Bundle\MagentoConnectorBundle\Writer\File\CsvWriter dnd_magento_connector.writer.file.csv_product.class: DnD\Bundle\MagentoConnectorBundle\Writer\File\CsvProductWriter services: dnd_magento_connector.writer.file: class: %dnd_magento_connector.writer.file.class% dnd_magento_connector.writer.file.csv: class: %dnd_magento_connector.writer.file.csv.class% dnd_magento_connector.writer.file.csv_product: class: %dnd_magento_connector.writer.file.csv_product.class% arguments: - '@pim_catalog.manager.media'
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dnd_magento_connector: jobs: dnd_csv_product_export: title: Export products in CSV File export.title: Products Export dnd_csv_category_export: title: Export categories in CSV File export.title: Categories Export dnd_csv_attribute_export: title: Export attributes in CSV File export.title: Attributes Export dnd_csv_attribute_option_export: title: Export attributes options in CSV File export.title: Attributes Options Export dnd_csv_association_type_export: title: Export associations in CSV File export.title: Associations Export dnd_csv_group_export: title: Export groups in CSV File export.title: Groups Export csv_family_export: title: Export families in CSV File export.title: Families Export export: host: label: Host help: SFTP connection host (Public IP) port: label: Port help: SFTP connection port username: label: Username help: SFTP connection username password: label: Password help: SFTP connection password remoteFilePath: label: Remote File Path help: Remote File Path (from the root of your SFTP user) imageFolderPath: label: Image Folder Path help: Image Folder Path (from the root of your SFTP user)
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/messages.fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dnd_magento_connector: jobs: dnd_csv_product_export: title: Export des produits en CSV export.title: Export de produits dnd_csv_category_export: title: Export des catégories en CSV export.title: Export de catégories dnd_csv_attribute_export: title: Export des attributs en CSV export.title: Export des attributs dnd_csv_attribute_option_export: title: Export des options des attributs en CSV export.title: Export des options des attributs dnd_csv_association_type_export: title: Export des associations en CSV export.title: Export des associations dnd_csv_group_export: title: Export des groupes en CSV export.title: Export des groupes csv_family_export: title: Export des familles en CSV export.title: Export de familles export: host: label: Hôte help: Hôte de la connexion SFTP (IP Publique) port: label: Port help: Port de la connexion SFTP username: label: Utilisateur help: Utilisateur de la connexion SFTP password: label: Mot de passe help: Mot de passe de la connexion SFTP remoteFilePath: label: Chemin du fichier distant help: Chemin du fichier distant (depuis la racine de votre utilisateur SFTP) imageFolderPath: label: Chemin du dossier des images help: Chemin du dossier des images (depuis la racine de votre utilisateur SFTP)
Expand Down
1 change: 1 addition & 0 deletions Writer/File/ArchivableWriterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpnamespace DnD\Bundle\MagentoConnectorBundle\Writer\File;/** * Interface for file writer that supports archiving the results * * @author Filips Alpe <[email protected]> * @copyright 2013 Akeneo SAS (http://www.akeneo.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */interface ArchivableWriterInterface{ /** * Return an array of files written by the writer in the following format: * array( * '/full/path/to/the/file' => 'path/relative/to/the/export/directory' * ) * * @return array */ public function getWrittenFiles();}
Expand Down
Loading

0 comments on commit 2147137

Please sign in to comment.