Skip to content

Commit db6f211

Browse files
Feat importexport bundle (#186)
* feat: import export bundle --------- Co-authored-by: Florian ALEXANDRE <f.alexandre@novactive.com> Co-authored-by: Said Oulhaj <said.oulhaj-ext@almaviacx.com>
1 parent d0bc60e commit db6f211

File tree

235 files changed

+10553
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+10553
-11
lines changed

.gitignore

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
vendor
2-
ibexa
3-
chromedriver
4-
.php_cs.cache
5-
bin/do.bash
6-
.phpunit.result.cache
7-
documentation/export
8-
.idea
9-
node_modules
10-
drivers
11-
.php-cs-fixer.cache
1+
./vendor
2+
./ibexa
3+
./chromedriver
4+
./.php_cs.cache
5+
./bin/do.bash
6+
./.phpunit.result.cache
7+
./documentation/export
8+
./.idea
9+
./node_modules
10+
./drivers
11+
./.php-cs-fixer.cache
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 Novactive, https://github.com/Novactive/AlmaviaCXIbexaImportExportBundle <dirtech.web@almaviacx.com>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# AlmaviaCX Ibexa Import/Export Bundle
2+
3+
Import / Export workflow :
4+
5+
6+
A `job` trigger a `workflow`
7+
8+
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`
9+
10+
11+
## Step
12+
13+
A step service must implement `AlmaviaCX\Bundle\IbexaImportExport\Step\StepInterface` and have the tag `almaviacx.import_export.component`
14+
15+
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Step\AbstractStep` to simplify the creation of a service
16+
17+
### Provided steps
18+
19+
#### AlmaviaCX\Bundle\IbexaImportExport\Step\IbexaContentToArrayStep
20+
21+
Transform a content into an associative array. Take a map as argument to extract properties from a content to generate the associative array
22+
23+
More explaination on the transformation process [here](./doc/ibexa_content_to_array_step.md)
24+
25+
Options are :
26+
- map (array representing the resulting associative array. each entry value correspond to a property of the content. ex : `["title" => "content.fields[title].value"]`)
27+
28+
## Writer
29+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
mdb_path=$1
4+
sqlite_path=$2
5+
id=$BASHPID
6+
tmp_dir="/tmp/mdb-convert/${id}"
7+
8+
test -f $sqlite_path && rm $sqlite_path
9+
10+
echo "Starting conversion in ${tmp_dir}"
11+
mkdir -p $tmp_dir
12+
mdb-schema $mdb_path sqlite > ${tmp_dir}/schema.sql
13+
mkdir -p ${tmp_dir}/sql
14+
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
15+
cat ${tmp_dir}/schema.sql | sqlite3 $sqlite_path
16+
for f in ${tmp_dir}/sql/* ; do (echo 'BEGIN;'; cat $f; echo 'COMMIT;') | sqlite3 $sqlite_path; done
17+
rm -rf $tmp_dir
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
install: true
2+
test: false
3+
repo: Novactive/AlmaviaCXIbexaImportExportBundle
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "almaviacx/ibexaimportexportbundle",
3+
"description": "Bundle to handle import/export",
4+
"keywords": [
5+
"ibexa",
6+
"bundle"
7+
],
8+
"homepage": "https://github.com/Novactive/AlmaviaCXIbexaImportExportBundle",
9+
"type": "ibexa-bundle",
10+
"authors": [
11+
{
12+
"name": "AlmaviaCX",
13+
"homepage": "https://almaviacx.com/expertises/web-mobile/",
14+
"email": "dirtech.web@almaviacx.com"
15+
}
16+
],
17+
"license": [
18+
"MIT"
19+
],
20+
"require": {
21+
"php": "^7.3 || ^8.0",
22+
"craue/formflow-bundle": "^3.0",
23+
"symfony/uid": "^5.4"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"AlmaviaCX\\Bundle\\IbexaImportExportBundle\\": "src/bundle",
28+
"AlmaviaCX\\Bundle\\IbexaImportExport\\": "src/lib"
29+
}
30+
},
31+
"suggest": {
32+
"matthiasnoback/symfony-console-form": "Used to execute workflow from CLI",
33+
"phpoffice/phpspreadsheet": "Used for the XlsReader",
34+
"symfony/messenger": "Used to run job asynchronously"
35+
},
36+
"extra": {
37+
},
38+
"bin": [
39+
"bin/mdb-to-sqlite.bash"
40+
]
41+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Reader
2+
3+
The job of a reader is to fetch the datas from somewhere and transmit them to the workflow processors.
4+
5+
A reader service must implement `AlmaviaCX\Bundle\IbexaImportExport\Reader\ReaderInterface` and have the tag `almaviacx.import_export.component` and provide an alias
6+
7+
```yaml
8+
tags:
9+
- { name: almaviacx.import_export.component, alias: reader.csv}
10+
```
11+
12+
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Reader\AbstractReader` to simplify the creation of a service
13+
14+
Using this abstraction, you just need to implement the `getName` and `__invoke` methods.
15+
16+
```injectablephp
17+
public static function getName()
18+
{
19+
return new TranslatableMessage('reader.csv.name', [], 'import_export');
20+
}
21+
22+
public function __invoke(): Iterator
23+
{
24+
// TODO: Implement __invoke() method.
25+
}
26+
```
27+
28+
You can also override the following functions :
29+
- `getOptionsFormType` to provide the form type used to manage the reader options
30+
- `getOptionsType` to provide a different options class
31+
32+
33+
## Provided readers
34+
35+
### AlmaviaCX\Bundle\IbexaImportExport\Reader\Csv\CsvReader
36+
37+
Fetch rows from a CSV file.
38+
39+
Related options : `AlmaviaCX\Bundle\IbexaImportExport\Reader\Csv\CsvReader\CsvReaderOptions`
40+
41+
### AlmaviaCX\Bundle\IbexaImportExport\Reader\Ibexa\ContentList\IbexaContentListReader
42+
43+
Fetch a list of Ibexa contents
44+
45+
Related options : `AlmaviaCX\Bundle\IbexaImportExport\Reader\Ibexa\ContentList\IbexaContentListReaderOptions`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Step
2+
3+
A step service must implement `AlmaviaCX\Bundle\IbexaImportExport\Step\StepInterface` and have the tag `almaviacx.import_export.component`
4+
5+
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Step\AbstractStep` to simplify the creation of a service
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Workflow
2+
3+
Workflow can be created throught the admin UI or as a Symfony service.
4+
5+
## Workflow service
6+
7+
The workflow service must implement `AlmaviaCX\Bundle\IbexaImportExport\Workflow\WorkflowInterface` and have the tag `almaviacx.import_export.workflow`
8+
```yaml
9+
App\ImportExport\Workflow\ImportContentWorkflow:
10+
tags:
11+
- { name: almaviacx.import_export.workflow }
12+
```
13+
14+
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Workflow\AbstractWorkflow` to simplify the creation of a service.
15+
16+
Using this abstraction, you just need to implement the `getDefaultConfig` method in order to provide the configuration.
17+
18+
Exemple :
19+
```injectablephp
20+
public static function getDefaultConfig(): WorkflowConfiguration
21+
{
22+
$configuration = new WorkflowConfiguration(
23+
'app.import_export.workflow.import_content',
24+
'Import content',
25+
);
26+
$readerOptions = new CsvReaderOptions();
27+
$readerOptions->headerRowNumber = 0;
28+
$configuration->setReader(
29+
CsvReader::class,
30+
$readerOptions
31+
);
32+
33+
$writerOptions = new IbexaContentWriterOptions();
34+
$writerOptions->map = new ItemTransformationMap(
35+
[
36+
'contentRemoteId' => [
37+
'transformer' => SlugTransformer::class,
38+
'source' => new PropertyPath( '[name]' )
39+
],
40+
'mainLanguageCode' => 'eng-GB',
41+
'contentTypeIdentifier' => 'article',
42+
'fields[eng-GB][title]' => new PropertyPath( '[name]' ),
43+
'fields[eng-GB][intro]' => new PropertyPath( '[intro]' ),
44+
]
45+
);
46+
$configuration->addProcessor(
47+
IbexaContentWriter::class,
48+
$writerOptions
49+
);
50+
return $configuration;
51+
}
52+
```
53+
54+
Every options that are not specified this way will be asked when creating the job triggering this workflow
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Writer
2+
3+
A writer service must implement `AlmaviaCX\Bundle\IbexaImportExport\Writer\WriterInterface` and have the tag `almaviacx.import_export.component`
4+
5+
The bundle provide the `AlmaviaCX\Bundle\IbexaImportExport\Writer\AbstractWriter` to simplify the creation of a service

0 commit comments

Comments
 (0)