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
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ The core repository [`yokai/batch`](https://github.com/yokai-php/batch) : contai

Some bridges to popular packages :

| Bridge with | |
| ------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [`box/spout`](https://github.com/yokai-php/batch-box-spout) | Read/Write from/to CSV/ODS/XLSX |
| [`doctrine/dbal`](https://github.com/yokai-php/batch-doctrine-dbal) | Read/Write from/to SQL databases |
| [`doctrine/orm`](https://github.com/yokai-php/batch-doctrine-orm) | Read from Doctrine ORM entities |
| [`doctrine/persistence`](https://github.com/yokai-php/batch-doctrine-persistence) | Write to Doctrine ORM/ODM objects |
| [`symfony/console`](https://github.com/yokai-php/batch-symfony-console) | Add command to trigger jobs and async job launcher via command |
| [`symfony/framework-bundle`](https://github.com/yokai-php/batch-symfony-framework) | Bundle to integrate with Symfony framework |
| [`symfony/messenger`](https://github.com/yokai-php/batch-symfony-serializer) | Trigger jobs using message dispatch |
| [`symfony/serializer`](https://github.com/yokai-php/batch-symfony-serializer) | Process items using (de)normalization |
| [`symfony/validator`](https://github.com/yokai-php/batch-symfony-validator) | Skip invalid items during process |
| Bridge with | |
|------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [`box/spout`](https://github.com/yokai-php/batch-box-spout) | Read/Write from/to CSV/ODS/XLSX |
| [`doctrine/dbal`](https://github.com/yokai-php/batch-doctrine-dbal) | Read/Write from/to SQL databases |
| [`doctrine/orm`](https://github.com/yokai-php/batch-doctrine-orm) | Read from Doctrine ORM entities |
| [`doctrine/persistence`](https://github.com/yokai-php/batch-doctrine-persistence) | Write to Doctrine ORM/ODM objects |
| [`league/flysystem`](https://github.com/yokai-php/batch-league-flysystem) | Copy/Move files in a job / Trigger job when file found |
| [`symfony/console`](https://github.com/yokai-php/batch-symfony-console) | Add command to trigger jobs and async job launcher via command |
| [`symfony/framework-bundle`](https://github.com/yokai-php/batch-symfony-framework) | Bundle to integrate with Symfony framework |
| [`symfony/messenger`](https://github.com/yokai-php/batch-symfony-serializer) | Trigger jobs using message dispatch |
| [`symfony/serializer`](https://github.com/yokai-php/batch-symfony-serializer) | Process items using (de)normalization |
| [`symfony/validator`](https://github.com/yokai-php/batch-symfony-validator) | Skip invalid items during process |

And some special packages :
- [`yokai/batch-symfony-pack`](https://github.com/yokai-php/batch-symfony-pack): Minimal pack for Symfony Framework
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"doctrine/dbal": "^2.11",
"doctrine/orm": "^2.8",
"doctrine/persistence": "^2.0",
"league/flysystem": "^3.0",
"psr/container": "^1.0",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.0|^2.0|^3.0",
Expand All @@ -29,6 +30,7 @@
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.5",
"league/flysystem-memory": "^3.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^9.5",
Expand All @@ -55,6 +57,7 @@
"Yokai\\Batch\\Bridge\\Doctrine\\DBAL\\": "src/batch-doctrine-dbal/src/",
"Yokai\\Batch\\Bridge\\Doctrine\\ORM\\": "src/batch-doctrine-orm/src/",
"Yokai\\Batch\\Bridge\\Doctrine\\Persistence\\": "src/batch-doctrine-persistence/src/",
"Yokai\\Batch\\Bridge\\League\\Flysystem\\": "src/batch-league-flysystem/src/",
"Yokai\\Batch\\Bridge\\Symfony\\Console\\": "src/batch-symfony-console/src/",
"Yokai\\Batch\\Bridge\\Symfony\\Framework\\": "src/batch-symfony-framework/src/",
"Yokai\\Batch\\Bridge\\Symfony\\Messenger\\": "src/batch-symfony-messenger/src/",
Expand All @@ -72,6 +75,7 @@
"Yokai\\Batch\\Tests\\Bridge\\Doctrine\\DBAL\\": "src/batch-doctrine-dbal/tests/",
"Yokai\\Batch\\Tests\\Bridge\\Doctrine\\ORM\\": "src/batch-doctrine-orm/tests/",
"Yokai\\Batch\\Tests\\Bridge\\Doctrine\\Persistence\\": "src/batch-doctrine-persistence/tests/",
"Yokai\\Batch\\Tests\\Bridge\\League\\Flysystem\\": "src/batch-league-flysystem/tests/",
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Console\\": "src/batch-symfony-console/tests/",
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Framework\\": "src/batch-symfony-framework/tests/",
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Messenger\\": "src/batch-symfony-messenger/tests/",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parameters:
- src/batch-doctrine-dbal/src/
- src/batch-doctrine-orm/src/
- src/batch-doctrine-persistence/src/
- src/batch-league-flysystem/src/
- src/batch-symfony-console/src/
- src/batch-symfony-framework/src/
- src/batch-symfony-messenger/src/
Expand Down
2 changes: 2 additions & 0 deletions scripts/split-branch
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ remote batch-box-spout git@github.com:yokai-php/batch-box-spout.git
remote batch-doctrine-dbal git@github.com:yokai-php/batch-doctrine-dbal.git
remote batch-doctrine-orm git@github.com:yokai-php/batch-doctrine-orm.git
remote batch-doctrine-persistence git@github.com:yokai-php/batch-doctrine-persistence.git
remote batch-league-flysystem git@github.com:yokai-php/batch-league-flysystem.git
remote batch-symfony-console git@github.com:yokai-php/batch-symfony-console.git
remote batch-symfony-framework git@github.com:yokai-php/batch-symfony-framework.git
remote batch-symfony-messenger git@github.com:yokai-php/batch-symfony-messenger.git
Expand All @@ -41,6 +42,7 @@ split 'src/batch-box-spout' batch-box-spout
split 'src/batch-doctrine-dbal' batch-doctrine-dbal
split 'src/batch-doctrine-orm' batch-doctrine-orm
split 'src/batch-doctrine-persistence' batch-doctrine-persistence
split 'src/batch-league-flysystem' batch-league-flysystem
split 'src/batch-symfony-console' batch-symfony-console
split 'src/batch-symfony-framework' batch-symfony-framework
split 'src/batch-symfony-messenger' batch-symfony-messenger
Expand Down
2 changes: 2 additions & 0 deletions scripts/split-tag
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ remote batch-box-spout git@github.com:yokai-php/batch-box-spout.git
remote batch-doctrine-dbal git@github.com:yokai-php/batch-doctrine-dbal.git
remote batch-doctrine-orm git@github.com:yokai-php/batch-doctrine-orm.git
remote batch-doctrine-persistence git@github.com:yokai-php/batch-doctrine-persistence.git
remote batch-league-flysystem git@github.com:yokai-php/batch-league-flysystem.git
remote batch-symfony-console git@github.com:yokai-php/batch-symfony-console.git
remote batch-symfony-framework git@github.com:yokai-php/batch-symfony-framework.git
remote batch-symfony-messenger git@github.com:yokai-php/batch-symfony-messenger.git
Expand All @@ -41,6 +42,7 @@ split 'src/batch-box-spout' batch-box-spout
split 'src/batch-doctrine-dbal' batch-doctrine-dbal
split 'src/batch-doctrine-orm' batch-doctrine-orm
split 'src/batch-doctrine-persistence' batch-doctrine-persistence
split 'src/batch-league-flysystem' batch-league-flysystem
split 'src/batch-symfony-console' batch-symfony-console
split 'src/batch-symfony-framework' batch-symfony-framework
split 'src/batch-symfony-messenger' batch-symfony-messenger
Expand Down
6 changes: 6 additions & 0 deletions src/batch-league-flysystem/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gitattributes export-ignore
.gitignore export-ignore
docs/ export-ignore
tests/ export-ignore
LICENSE export-ignore
*.md export-ignore
27 changes: 27 additions & 0 deletions src/batch-league-flysystem/.github/workflows/lockdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Lock down Pull Requests'

on:
pull_request:
types: opened

jobs:
lockdown:
runs-on: ubuntu-latest
steps:
- uses: dessant/repo-lockdown@v2
with:
github-token: ${{ github.token }}
close-pr: true
lock-pr: true
pr-comment: >
Thanks for your pull request!

However, this repository does not accept pull requests,
see the README for details.

If you want to contribute,
you should instead open a pull request on the main repository:

https://github.com/yokai-php/batch-src

Thank you
3 changes: 3 additions & 0 deletions src/batch-league-flysystem/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.phpunit.result.cache
/vendor/
/composer.lock
19 changes: 19 additions & 0 deletions src/batch-league-flysystem/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2019 Yann Eugoné

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.
46 changes: 46 additions & 0 deletions src/batch-league-flysystem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# league/flysystem bridge for Batch processing library

[![Latest Stable Version](https://img.shields.io/packagist/v/yokai/batch-league-flysystem?style=flat-square)](https://packagist.org/packages/yokai/batch-league-flysystem)
[![Downloads Monthly](https://img.shields.io/packagist/dm/yokai/batch-league-flysystem?style=flat-square)](https://packagist.org/packages/yokai/batch-league-flysystem)

Bridge of [`league/flysystem`](https://github.com/thephpleague/flysystem) for [Batch](https://github.com/yokai-php/batch).


## :warning: BETA

This library is following [semver](https://semver.org/).
However before we reach the first stable version (`v1.0.0`), we may decide to introduce **API changes in minor versions**.
This is why you should stick to a `v0.[minor].*` requirement !


# Installation

```
composer require yokai/batch-league-flysystem
```


## Documentation

This package provides:

- a [job](docs/copy-files-job.md) that copy file(s) from one filesystem to another
- a [job](docs/move-files-job.md) that move file(s) from one filesystem to another


## Contribution

This package is a readonly split of a [larger repository](https://github.com/yokai-php/batch-src),
containing all tests and sources for all librairies of the batch universe.

Please feel free to open an [issue](https://github.com/yokai-php/batch-src/issues)
or a [pull request](https://github.com/yokai-php/batch-src/pulls)
in the [main repository](https://github.com/yokai-php/batch-src).

The library was originally created by [Yann Eugoné](https://github.com/yann-eugone).
See the list of [contributors](https://github.com/yokai-php/batch-src/contributors).


## License

This library is under MIT [LICENSE](LICENSE).
33 changes: 33 additions & 0 deletions src/batch-league-flysystem/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "yokai/batch-flysystem",
"description": "league/flysystem bridge for yokai/batch",
"keywords": ["batch", "job", "filesystem", "flysystem"],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Yann Eugoné",
"email": "eugone.yann@gmail.com"
}
],
"require": {
"php": "^8.0",
"league/flysystem": "^3.0",
"yokai/batch": "^0.4.0"
},
"autoload": {
"psr-4": {
"Yokai\\Batch\\Bridge\\League\\Flysystem\\": "src/"
}
},
"require-dev": {
"league/flysystem-memory": "^3.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
"psr-4": {
"Yokai\\Batch\\Tests\\Bridge\\League\\Flysystem\\": "tests/"
}
}
}
1 change: 1 addition & 0 deletions src/batch-league-flysystem/docs/copy-files-job.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
todo
1 change: 1 addition & 0 deletions src/batch-league-flysystem/docs/move-files-job.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
todo
21 changes: 21 additions & 0 deletions src/batch-league-flysystem/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Tests">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
83 changes: 83 additions & 0 deletions src/batch-league-flysystem/src/Job/CopyFilesJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

namespace Yokai\Batch\Bridge\League\Flysystem\Job;

use Closure;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemReader;
use League\Flysystem\FilesystemWriter;
use League\Flysystem\UnableToReadFile;
use League\Flysystem\UnableToWriteFile;
use Yokai\Batch\Exception\UnexpectedValueException;
use Yokai\Batch\Job\JobInterface;
use Yokai\Batch\Job\Parameters\JobParameterAccessorInterface;
use Yokai\Batch\JobExecution;

/**
* This job allows you to copy files from one filesystem ot another.
*/
class CopyFilesJob implements JobInterface
{
public function __construct(
private JobParameterAccessorInterface $location,
private FilesystemReader $source,
private FilesystemWriter $destination,
private ?Closure $transformLocation = null,
) {
}

final public function execute(JobExecution $jobExecution): void
{
$config = $this->location->get($jobExecution);
if (\is_string($config)) {
$locations = [$config];
} elseif (\is_array($config)) {
$locations = $config;
} else {
throw UnexpectedValueException::type('string|string[]', $config);
}

$transformLocation = $this->transformLocation ?? fn ($sourceLocation) => $sourceLocation;
foreach ($locations as $sourceLocation) {
$destinationLocation = $transformLocation($sourceLocation);
if (!\is_string($destinationLocation)) {
throw UnexpectedValueException::type('string', $destinationLocation);
}

try {
$this->destination->writeStream(
$destinationLocation,
$this->source->readStream($sourceLocation)
);
} catch (UnableToReadFile $exception) {
$jobExecution->addFailureException($exception, [], false);
$jobExecution->getLogger()->error(
'Unable to read file from filesystem.',
['file' => $sourceLocation]
);
continue;
} catch (UnableToWriteFile $exception) {
$jobExecution->addFailureException($exception, [], false);
$jobExecution->getLogger()->error(
'Unable to write file to filesystem.',
['file' => $destinationLocation]
);
continue;
} catch (FilesystemException $exception) {
$jobExecution->addFailureException($exception, [], false);
$jobExecution->getLogger()->error(
'Unable to copy file.',
['source' => $sourceLocation, 'destination' => $destinationLocation]
);
continue;
}

$jobExecution->getLogger()->notice(
'Copied file from filesystem to another.',
['source' => $sourceLocation, 'destination' => $destinationLocation]
);
}
}
}
Loading