Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
vendor
ibexa
chromedriver
.php_cs.cache
bin/do.bash
.phpunit.result.cache
documentation/export
.idea
node_modules
drivers
.php-cs-fixer.cache
./vendor
./ibexa
./chromedriver
./.php_cs.cache
./bin/do.bash
./.phpunit.result.cache
./documentation/export
./.idea
./node_modules
./drivers
./.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions components/ImportExportBundle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Novactive, https://github.com/Novactive/AlmaviaCXIbexaImportExportBundle <dirtech.web@almaviacx.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
29 changes: 29 additions & 0 deletions components/ImportExportBundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# AlmaviaCX Ibexa Import/Export Bundle

Import / Export workflow :


A `job` trigger a `workflow`

A `workflow` call a `reader` to get a list of items, then use a list of `step` to filter/modify the items and finally pass them to a list of `writer`


## Step

A step service must implement `AlmaviaCX\Bundle\IbexaImportExport\Step\StepInterface` and have the tag `almaviacx.import_export.component`

The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Step\AbstractStep` to simplify the creation of a service

### Provided steps

#### AlmaviaCX\Bundle\IbexaImportExport\Step\IbexaContentToArrayStep

Transform a content into an associative array. Take a map as argument to extract properties from a content to generate the associative array

More explaination on the transformation process [here](./doc/ibexa_content_to_array_step.md)

Options are :
- map (array representing the resulting associative array. each entry value correspond to a property of the content. ex : `["title" => "content.fields[title].value"]`)

## Writer

17 changes: 17 additions & 0 deletions components/ImportExportBundle/bin/mdb-to-sqlite.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

mdb_path=$1
sqlite_path=$2
id=$BASHPID
tmp_dir="/tmp/mdb-convert/${id}"

test -f $sqlite_path && rm $sqlite_path

echo "Starting conversion in ${tmp_dir}"
mkdir -p $tmp_dir
mdb-schema $mdb_path sqlite > ${tmp_dir}/schema.sql
mkdir -p ${tmp_dir}/sql
for i in $( mdb-tables $mdb_path ); do mdb-export --quote="'" -D "%Y-%m-%d %H:%M:%S" -H -I sqlite $mdb_path $i > ${tmp_dir}/sql/$i.sql; done
cat ${tmp_dir}/schema.sql | sqlite3 $sqlite_path
for f in ${tmp_dir}/sql/* ; do (echo 'BEGIN;'; cat $f; echo 'COMMIT;') | sqlite3 $sqlite_path; done
rm -rf $tmp_dir
3 changes: 3 additions & 0 deletions components/ImportExportBundle/ci-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
install: true
test: false
repo: Novactive/AlmaviaCXIbexaImportExportBundle
41 changes: 41 additions & 0 deletions components/ImportExportBundle/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "almaviacx/ibexaimportexportbundle",
"description": "Bundle to handle import/export",
"keywords": [
"ibexa",
"bundle"
],
"homepage": "https://github.com/Novactive/AlmaviaCXIbexaImportExportBundle",
"type": "ibexa-bundle",
"authors": [
{
"name": "AlmaviaCX",
"homepage": "https://almaviacx.com/expertises/web-mobile/",
"email": "dirtech.web@almaviacx.com"
}
],
"license": [
"MIT"
],
"require": {
"php": "^7.3 || ^8.0",
"craue/formflow-bundle": "^3.0",
"symfony/uid": "^5.4"
},
"autoload": {
"psr-4": {
"AlmaviaCX\\Bundle\\IbexaImportExportBundle\\": "src/bundle",
"AlmaviaCX\\Bundle\\IbexaImportExport\\": "src/lib"
}
},
"suggest": {
"matthiasnoback/symfony-console-form": "Used to execute workflow from CLI",
"phpoffice/phpspreadsheet": "Used for the XlsReader",
"symfony/messenger": "Used to run job asynchronously"
},
"extra": {
},
"bin": [
"bin/mdb-to-sqlite.bash"
]
}
45 changes: 45 additions & 0 deletions components/ImportExportBundle/doc/reader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Reader

The job of a reader is to fetch the datas from somewhere and transmit them to the workflow processors.

A reader service must implement `AlmaviaCX\Bundle\IbexaImportExport\Reader\ReaderInterface` and have the tag `almaviacx.import_export.component` and provide an alias

```yaml
tags:
- { name: almaviacx.import_export.component, alias: reader.csv}
```
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Reader\AbstractReader` to simplify the creation of a service

Using this abstraction, you just need to implement the `getName` and `__invoke` methods.

```injectablephp
public static function getName()
{
return new TranslatableMessage('reader.csv.name', [], 'import_export');
}
public function __invoke(): Iterator
{
// TODO: Implement __invoke() method.
}
```

You can also override the following functions :
- `getOptionsFormType` to provide the form type used to manage the reader options
- `getOptionsType` to provide a different options class


## Provided readers

### AlmaviaCX\Bundle\IbexaImportExport\Reader\Csv\CsvReader

Fetch rows from a CSV file.

Related options : `AlmaviaCX\Bundle\IbexaImportExport\Reader\Csv\CsvReader\CsvReaderOptions`

### AlmaviaCX\Bundle\IbexaImportExport\Reader\Ibexa\ContentList\IbexaContentListReader

Fetch a list of Ibexa contents

Related options : `AlmaviaCX\Bundle\IbexaImportExport\Reader\Ibexa\ContentList\IbexaContentListReaderOptions`
5 changes: 5 additions & 0 deletions components/ImportExportBundle/doc/step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Step

A step service must implement `AlmaviaCX\Bundle\IbexaImportExport\Step\StepInterface` and have the tag `almaviacx.import_export.component`

The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Step\AbstractStep` to simplify the creation of a service
54 changes: 54 additions & 0 deletions components/ImportExportBundle/doc/workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Workflow

Workflow can be created throught the admin UI or as a Symfony service.

## Workflow service

The workflow service must implement `AlmaviaCX\Bundle\IbexaImportExport\Workflow\WorkflowInterface` and have the tag `almaviacx.import_export.workflow`
```yaml
App\ImportExport\Workflow\ImportContentWorkflow:
tags:
- { name: almaviacx.import_export.workflow }
```
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Workflow\AbstractWorkflow` to simplify the creation of a service.

Using this abstraction, you just need to implement the `getDefaultConfig` method in order to provide the configuration.

Exemple :
```injectablephp
public static function getDefaultConfig(): WorkflowConfiguration
{
$configuration = new WorkflowConfiguration(
'app.import_export.workflow.import_content',
'Import content',
);
$readerOptions = new CsvReaderOptions();
$readerOptions->headerRowNumber = 0;
$configuration->setReader(
CsvReader::class,
$readerOptions
);
$writerOptions = new IbexaContentWriterOptions();
$writerOptions->map = new ItemTransformationMap(
[
'contentRemoteId' => [
'transformer' => SlugTransformer::class,
'source' => new PropertyPath( '[name]' )
],
'mainLanguageCode' => 'eng-GB',
'contentTypeIdentifier' => 'article',
'fields[eng-GB][title]' => new PropertyPath( '[name]' ),
'fields[eng-GB][intro]' => new PropertyPath( '[intro]' ),
]
);
$configuration->addProcessor(
IbexaContentWriter::class,
$writerOptions
);
return $configuration;
}
```

Every options that are not specified this way will be asked when creating the job triggering this workflow
5 changes: 5 additions & 0 deletions components/ImportExportBundle/doc/writer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Writer

A writer service must implement `AlmaviaCX\Bundle\IbexaImportExport\Writer\WriterInterface` and have the tag `almaviacx.import_export.component`

The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Writer\AbstractWriter` to simplify the creation of a service
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace AlmaviaCX\Bundle\IbexaImportExportBundle;

use AlmaviaCX\Bundle\IbexaImportExportBundle\DependencyInjection\CompilerPass\ComponentPass;
use AlmaviaCX\Bundle\IbexaImportExportBundle\DependencyInjection\CompilerPass\ItemValueTransformerPass;
use AlmaviaCX\Bundle\IbexaImportExportBundle\DependencyInjection\CompilerPass\WorkflowPass;
use AlmaviaCX\Bundle\IbexaImportExportBundle\DependencyInjection\Security\Provider\PolicyProvider;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class AlmaviaCXIbexaImportExportBundle extends Bundle
{
/**
* Builds the bundle.
*
* It is only ever called once when the cache is empty.
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
/** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $ibexaExtension */
$ibexaExtension = $container->getExtension('ibexa');
$ibexaExtension->addPolicyProvider(new PolicyProvider());

$container->addCompilerPass(new ComponentPass());
$container->addCompilerPass(new WorkflowPass());
$container->addCompilerPass(new ItemValueTransformerPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace AlmaviaCX\Bundle\IbexaImportExportBundle\Command;

use AlmaviaCX\Bundle\IbexaImportExport\Event\PostJobCreateFormSubmitEvent;
use AlmaviaCX\Bundle\IbexaImportExport\Job\Form\Type\JobProcessConfigurationFormType;
use AlmaviaCX\Bundle\IbexaImportExport\Job\Job;
use AlmaviaCX\Bundle\IbexaImportExport\Job\JobService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class CreateJobCommand extends Command
{
protected JobService $jobService;
protected EventDispatcherInterface $eventDispatcher;

protected static $defaultName = 'import_export:job:create';

public function __construct(JobService $jobService, EventDispatcherInterface $eventDispatcher)
{
parent::__construct();
$this->jobService = $jobService;
$this->eventDispatcher = $eventDispatcher;
}

protected function configure()
{
parent::configure();
$this->addArgument('identifier', InputArgument::REQUIRED, 'Workflow identifier');
$this->addArgument('label', InputArgument::REQUIRED, 'Job label');
$this->addArgument('creator', InputArgument::REQUIRED, 'Creator');
$this->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug mode');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$job = new Job();
$job->setLabel($input->getArgument('label'));
$job->setCreatorId((int) $input->getArgument('creator'));
$job->setWorkflowIdentifier($input->getArgument('identifier'));

/** @var \Matthias\SymfonyConsoleForm\Console\Helper\FormHelper $formHelper */
$formHelper = $this->getHelper('form');

$job = $formHelper->interactUsingForm(
JobProcessConfigurationFormType::class,
$input,
$output,
[],
$job
);

$this->eventDispatcher->dispatch(new PostJobCreateFormSubmitEvent($job));
$this->jobService->createJob($job, false);

return Command::SUCCESS;
}
}
Loading
Loading