diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 6f3b7aed..11562840 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -1,64 +1,86 @@ name: Behat on: push: - branches: [ master ] + branches: [ '4.0' ] pull_request: - branches: [ master ] + branches: [ '4.0' ] jobs: behat: runs-on: ubuntu-latest env: APP_ENV: "test" - PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" + IM_SKIP_DB_SETUP: "1" + PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/coreshop_test" + PIMCORE_INSTALL_ADMIN_USERNAME: "admin" + PIMCORE_INSTALL_ADMIN_PASSWORD: "admin" + PIMCORE_INSTALL_MYSQL_HOST_SOCKET: "127.0.0.1" + PIMCORE_INSTALL_MYSQL_USERNAME: "root" + PIMCORE_INSTALL_MYSQL_PASSWORD: "root" + PIMCORE_INSTALL_MYSQL_DATABASE: "coreshop_test" + PIMCORE_INSTALL_MYSQL_PORT: "3306" + PIMCORE_KERNEL_CLASS: 'Kernel' + PIMCORE_CLASS_DIRECTORY: 'var/tmp/behat/var/classes' + + strategy: + matrix: + php: [ 8.1, 8.2 ] + pimcore: [ ^11.0 ] + dependencies: [ highest ] + exclude: + - php: 8.1 + dependencies: lowest + services: - mysql: - image: mysql:5.7 + database: + image: "mysql:8" env: MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: data_defs_test ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" - strategy: - matrix: - php: [8.0] - pimcore: [^10.0, ^10.1] + + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, Deps ${{ matrix.dependencies }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + ini-values: display_errors=On, display_startup_errors=On, error_reporting=32767 extensions: intl, gd, simpleXML, dom, exif, fileinfo, iconv, mbstring, mysqli, pdo_mysql, zip, zlib - name: Check PHP Version run: php -v - - name: Verify MySQL connection + - name: Setup DB run: | - mysql --version - sudo apt-get install -y mysql-client - mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "SHOW DATABASES" + mysql --host 127.0.0.1 --port ${{ job.services.database.ports['3306'] }} -uroot -proot -e "CREATE DATABASE coreshop_test CHARSET=utf8mb4;" - name: Get composer cache directory id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache composer dependencies - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - - name: Composer install + - if: matrix.dependencies == 'highest' + name: Install dependencies highest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader + + - if: matrix.dependencies == 'lowest' + name: Install dependencies lowest run: | composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update - composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - name: Cache clear run: bin/console cache:clear @@ -66,5 +88,27 @@ jobs: - name: Assets Install run: bin/console assets:install --symlink + - name: Install Pimcore + run: PIMCORE_KERNEL_CLASS=Kernel vendor/bin/pimcore-install --env=test --skip-database-config + + - name: Install DataDefinitions + run: bin/console pimcore:bundle:install DataDefinitionsBundle + - name: Run Behat run: vendor/bin/behat --strict --no-interaction -vvv -f progress --config behat.yml.dist -p default + + - name: Upload Behat logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: "Behat logs (non-JS, PHP ${{ matrix.php }}, Symfony ${{ matrix.pimcore }})" + path: etc/build/ + if-no-files-found: ignore + + - name: Upload Pimcore logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: "Pimcore logs (non-JS, PHP ${{ matrix.php }}, Symfony ${{ matrix.pimcore }})" + path: var/log/ + if-no-files-found: ignore diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9a41bbf9..f25dff49 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,70 +1,79 @@ name: Static Tests (Lint, Stan) on: push: - branches: [ master ] + branches: [ '4.0' ] pull_request: - branches: [ master ] + branches: [ '4.0' ] jobs: lint: runs-on: ubuntu-latest env: APP_ENV: "test" - PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/data_defs_test" + PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/coreshop_test" + + strategy: + matrix: + php: [ 8.1, 8.2 ] + pimcore: [ ^11.0 ] + dependencies: [ highest ] + exclude: + - php: 8.1 + dependencies: lowest + services: - mysql: - image: mysql:5.7 + database: + image: "mysql:8" env: MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: data_defs_test + MYSQL_DATABASE: coreshop_test ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}" - strategy: - matrix: - php: [8.0] - pimcore: [^10.0, ^10.1] + + name: "${{ matrix.pimcore }}, PHP ${{ matrix.php }}, Deps ${{ matrix.dependencies }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: intl, gd, simpleXML, dom, exif, fileinfo, iconv, mbstring, mysqli, pdo_mysql, zip, zlib + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + ini-values: display_errors=On, display_startup_errors=On, error_reporting=32767 + extensions: intl, gd, simpleXML, dom, exif, fileinfo, iconv, mbstring, mysqli, pdo_mysql, zip, zlib - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Validate composer.json and composer.lock + run: composer validate - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Verify MySQL connection - run: | - mysql --version - sudo apt-get install -y mysql-client - mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "SHOW DATABASES" + - name: Cache composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- - - name: Validate composer.json and composer.lock - run: composer validate + - if: matrix.dependencies == 'highest' + name: Install dependencies highest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader - - name: Composer install - run: | - composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update - composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - if: matrix.dependencies == 'lowest' + name: Install dependencies lowest + run: | + composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update + composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest - - name: Validate YAML - run: bin/console lint:yaml src --parse-tags + - name: Validate YAML + run: bin/console lint:yaml src --parse-tags - - name: STAN - run: | - cp -f config/packages/stan/config.yaml config/packages/dev/config.yaml - bin/console cache:clear --env=dev - vendor/bin/phpstan analyse -c phpstan.neon src -l 3 + - name: STAN + run: | + cp -f config/packages/stan/config.yaml config/packages/dev/config.yaml + bin/console cache:clear --env=dev + vendor/bin/phpstan analyse -c phpstan.neon src -l 3 diff --git a/.gitignore b/.gitignore index a399305d..62faa52b 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,7 @@ var/classes var/config test.csv web +public +docker-compose.yaml +test-commands.txt +.docker \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2e456eb7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,81 +0,0 @@ -sudo: false -language: php - -addons: - mariadb: '10.2' - hosts: - - pimcore-test.dev -services: - - mysql - -env: - global: - - PIMCORE_ENVIRONMENT=test - - PIMCORE_TEST_DB_DSN="mysql://root@localhost/im_test" - - PIMCORE_VERSION="~6.5" - - IM_TEST=1 - - IM_SUITE=application - - SYMFONY_VERSION="^3.4" - -matrix: - include: - - sudo: required - php: 7.3 - env: - - IM_SUITE=codestyle - - - sudo: required - php: 7.3 - env: - - IM_SUITE=stan - - - sudo: required - php: 7.2 - - - sudo: required - php: 7.3 - - - sudo: required - php: 7.2 - env: - - SYMFONY_VERSION="^4.0" - - - sudo: required - php: 7.3 - env: - - SYMFONY_VERSION="^4.0" - - - sudo: required - php: 7.2 - env: - - PIMCORE_VERSION="dev-master" - - SYMFONY_VERSION="^4.0" - - - sudo: required - php: 7.3 - env: - - PIMCORE_VERSION="dev-master" - - SYMFONY_VERSION="^4.0" - allow_failures: - - env: - - IM_SUITE=codestyle - - env: - - PIMCORE_VERSION="dev-master" - - env: - - PIMCORE_VERSION="dev-master" - - SYMFONY_VERSION="^4.0" - fast_finish: true - -cache: - directories: - - $HOME/.cache/composer - -install: - - etc/travis/install - -script: - - etc/travis/script - -notifications: - email: - - travis-ci@coreshop.org diff --git a/behat-bootstrap.php b/behat-bootstrap.php index 5a946700..db37a032 100755 --- a/behat-bootstrap.php +++ b/behat-bootstrap.php @@ -1,10 +1,20 @@ =8.0", "ext-json": "*", "box/spout": "^3.0", + "coreshop/pimcore-bundle": "^4.0", + "coreshop/resource-bundle": "^4.0", + "coreshop/rule-bundle": "^4.0", + "jms/serializer": "^3.17.1", "league/csv": "^9.7", - "coreshop/resource-bundle": "^3.0", - "coreshop/rule-bundle": "^3.0", - "coreshop/pimcore-bundle": "^3.0", - "pimcore/pimcore": "^10.0" + "nyholm/psr7": "^1.5", + "pimcore/admin-ui-classic-bundle": "^1.0", + "pimcore/pimcore": "^11.0", + "psr/http-client-implementation": "^1.0", + "psr/http-factory-implementation": "^1.0", + "symfony/dotenv": "^6.3", + "symfony/http-client": "^6.3" }, "require-dev": { "roave/security-advisories": "dev-latest", "behat/behat": "^3.8", - "friends-of-behat/symfony-extension": "^2.2.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-symfony": "^0.12", - "phpstan/phpstan-webmozart-assert": "^0.12" + "friends-of-behat/symfony-extension": "^2.1", + "phpstan/phpstan": "^1.5.4", + "phpstan/phpstan-doctrine": "^1.3.2", + "phpstan/phpstan-symfony": "^1.1.8", + "phpstan/phpstan-webmozart-assert": "^1.1.2" }, "conflict": { - + "guzzlehttp/psr7": "< 2.0" }, "suggest": { - "dpfaffenbauer/process-manager": "Allows to start Imports/Exports from within Pimcore UI and also tracks Status of current processes." + "dpfaffenbauer/process-manager": "Allows to start Imports/Exports from within Pimcore UI and also tracks Status of current processes.", + "guzzlehttp/psr7": "For downloading external data like Images" }, "autoload": { "psr-4": { @@ -60,7 +68,11 @@ }, "autoload-dev": { "psr-4": { - "Wvision\\Bundle\\DataDefinitionsBundle\\Behat\\": "tests/DataDefinitionsBundle/Behat" + "Wvision\\Bundle\\DataDefinitionsBundle\\Behat\\": "tests/DataDefinitionsBundle/Behat", + "Pimcore\\Model\\DataObject\\": [ + "var/classes/DataObject", + "var/tmp/behat/var/classes/DataObject" + ] }, "classmap": [ "src/Kernel.php" diff --git a/config/config.yaml b/config/config.yaml index 3df4a70d..d84a1e5f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,6 +1,5 @@ imports: - { resource: services.yaml } - - { resource: migrations.yaml } - { resource: system.yml } - { resource: 'local/' } diff --git a/config/migrations.yaml b/config/migrations.yaml deleted file mode 100644 index 9617ac97..00000000 --- a/config/migrations.yaml +++ /dev/null @@ -1,19 +0,0 @@ -doctrine_migrations: - connection: default - migrations_paths: - 'Pimcore\Bundle\CoreBundle\Migrations': '@PimcoreCoreBundle/Migrations' - storage: - table_storage: - table_name: 'migration_versions' - version_column_name: 'version' - version_column_length: 1024 - executed_at_column_name: 'executed_at' - execution_time_column_name: 'execution_time' - all_or_nothing: false - check_database_platform: false - factories: - 'Doctrine\Migrations\MigrationsRepository': 'Pimcore\Migrations\FilteredMigrationsRepository' - 'Doctrine\Migrations\Metadata\Storage\MetadataStorage': 'Pimcore\Migrations\FilteredTableMetadataStorage' - - - diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 9675d5a6..df3e2daf 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,7 +1,9 @@ security: + enable_authenticator_manager: true + providers: pimcore_admin: - id: Pimcore\Bundle\AdminBundle\Security\User\UserProvider + id: Pimcore\Security\User\UserProvider firewalls: dev: @@ -9,46 +11,25 @@ security: security: false # Pimcore WebDAV HTTP basic // DO NOT CHANGE! - pimcore_admin_webdav: - pattern: ^/admin/asset/webdav + pimcore_webdav: + pattern: ^/asset/webdav provider: pimcore_admin http_basic: ~ - # Pimcore admin form login // DO NOT CHANGE! - pimcore_admin: - anonymous: ~ - pattern: ^/admin(/.*)?$ - # admin firewall is stateless as we open the admin - # session on demand for non-blocking parallel requests - stateless: true - provider: pimcore_admin - logout: - path: /admin/logout - target: /admin/login - success_handler: Pimcore\Bundle\AdminBundle\Security\LogoutSuccessHandler - guard: - entry_point: Pimcore\Bundle\AdminBundle\Security\Guard\AdminAuthenticator - authenticators: - - Pimcore\Bundle\AdminBundle\Security\Guard\AdminAuthenticator - two_factor: - auth_form_path: /admin/login/2fa # Path or route name of the two-factor form - check_path: /admin/login/2fa-verify # Path or route name of the two-factor code check - default_target_path: /admin # Where to redirect by default after successful authentication - always_use_default_target_path: false # If it should always redirect to default_target_path - auth_code_parameter_name: _auth_code # Name of the parameter for the two-factor authentication code - trusted_parameter_name: _trusted # Name of the parameter for the trusted device option - multi_factor: false # If ALL active two-factor methods need to be fulfilled (multi-factor authentication) - + # Pimcore Admin Bundle firewall + pimcore_admin: '%pimcore_admin_bundle.firewall_settings%' access_control: # Pimcore admin ACl // DO NOT CHANGE! - - { path: ^/admin/settings/display-custom-logo, roles: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: ^/admin/login/2fa-verify, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS} - - { path: ^/admin/login/2fa, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS} - - { path: ^/admin/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/admin/settings/display-custom-logo, roles: PUBLIC_ACCESS } + - { path: ^/admin/login/2fa-verify, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS } + - { path: ^/admin/login/2fa-setup, roles: ROLE_PIMCORE_USER } + - { path: ^/admin/login/2fa, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS } + - { path: ^/admin/login$, roles: PUBLIC_ACCESS } + - { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: PUBLIC_ACCESS } - { path: ^/admin, roles: ROLE_PIMCORE_USER } + - { path: ^/asset/webdav, roles: ROLE_PIMCORE_USER } role_hierarchy: # Pimcore admin // DO NOT CHANGE! - ROLE_PIMCORE_ADMIN: [ROLE_PIMCORE_USER] + ROLE_PIMCORE_ADMIN: [ROLE_PIMCORE_USER] \ No newline at end of file diff --git a/config/packages/test/config.yaml b/config/packages/test/config.yaml index f7eb973f..b6c73d1e 100644 --- a/config/packages/test/config.yaml +++ b/config/packages/test/config.yaml @@ -21,3 +21,12 @@ parameters: framework: session: handler_id: 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler' + +data_definitions: + config_location: + import_definitions: + write_target: + type: settings-store + export_definitions: + write_target: + type: settings-store \ No newline at end of file diff --git a/config/routes.yaml b/config/routes.yaml index 3c1894dd..b516051b 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -1,2 +1,2 @@ _pimcore: - resource: "@PimcoreCoreBundle/Resources/config/routing.yml" + resource: "@PimcoreCoreBundle/config/routing.yaml" diff --git a/config/routes/dev/routes.yaml b/config/routes/dev/routes.yaml index 8ee148fe..50d25c70 100644 --- a/config/routes/dev/routes.yaml +++ b/config/routes/dev/routes.yaml @@ -1,3 +1,2 @@ _pimcore_dev: - resource: "@PimcoreCoreBundle/Resources/config/routing_dev.yml" - + resource: "@PimcoreCoreBundle/config/routing_dev.yaml" \ No newline at end of file diff --git a/config/system.yml b/config/system.yml index 5995ca1d..b7a4b2b8 100644 --- a/config/system.yml +++ b/config/system.yml @@ -12,7 +12,6 @@ pimcore: default_language: '' disable_usage_statistics: false debug_admin_translations: false - instance_identifier: '' documents: versions: days: null @@ -32,14 +31,6 @@ pimcore: steps: 10 icc_rgb_profile: '' icc_cmyk_profile: '' - hide_edit_image: false - disable_tree_preview: false - services: - google: - client_id: '' - email: '' - simple_api_key: '' - browser_api_key: '' httpclient: adapter: Socket proxy_host: '' @@ -53,14 +44,6 @@ pimcore: return: name: pimcore email: pimcore@example.com - newsletter: - sender: - name: '' - email: '' - return: - name: '' - email: '' - use_specific: true applicationlog: mail_notification: send_log_summary: false diff --git a/docs/import/persister.md b/docs/import/persister.md new file mode 100644 index 00000000..37b7f464 --- /dev/null +++ b/docs/import/persister.md @@ -0,0 +1,14 @@ +## Persister +A persister takes care about the save process. It basically saves objects. Following Persisters are currently available: + +- `Persister` saves objects + +To create your own persister you need to implement `Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface` +and add a new service: + +```yml +acme_bundle.data_definitions.my_persister: + class: AcmeBundle\DataDefinitions\MyPersister + tags: + - { name: data_definitions.persister, type: my-persister } +``` \ No newline at end of file diff --git a/docs/import/setter.md b/docs/import/setter.md index 4580af84..7a473c71 100644 --- a/docs/import/setter.md +++ b/docs/import/setter.md @@ -13,7 +13,7 @@ Of course, you can also implement your own Setters. Its basically the same as wi Todo that, you need to implement the interface ```Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface``` and create a service ```yml -acme_bundle.data_definitions.my_interpter: +acme_bundle.data_definitions.my_setter: class: AcmeBundle\DataDefinitions\MySetter tags: - { name: data_definitions.setter, type: mysetter, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } diff --git a/etc/build/.gitkeep b/etc/build/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/features/cleaner/deleter.feature b/features/cleaner/deleter.feature index 30a680b3..3483f6b2 100644 --- a/features/cleaner/deleter.feature +++ b/features/cleaner/deleter.feature @@ -16,7 +16,7 @@ Feature: Adding a import with a cleaner And the import-definitions mapping is: | fromColumn | toColumn | primary | | name | name | true | - | published | o_published | false | + | published | published | false | And there is a file test.csv with content: """ name,published diff --git a/features/cleaner/none.feature b/features/cleaner/none.feature index 673c7b35..28aebe4b 100644 --- a/features/cleaner/none.feature +++ b/features/cleaner/none.feature @@ -16,7 +16,7 @@ Feature: Adding a import with a cleaner And the import-definitions mapping is: | fromColumn | toColumn | primary | | name | name | true | - | published | o_published | false | + | published | published | false | And there is a file test.csv with content: """ name,published diff --git a/features/cleaner/unpublisher.feature b/features/cleaner/unpublisher.feature index e9921243..b4838575 100644 --- a/features/cleaner/unpublisher.feature +++ b/features/cleaner/unpublisher.feature @@ -16,7 +16,7 @@ Feature: Adding a import with a cleaner And the import-definitions mapping is: | fromColumn | toColumn | primary | | name | name | true | - | published | o_published | false | + | published | published | false | And there is a file test.csv with content: """ name,published diff --git a/phpstan.neon b/phpstan.neon index c40882e5..da21aefc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,13 +1,10 @@ parameters: - autoload_files: - - %currentWorkingDirectory%/vendor/pimcore/pimcore/lib/helper-functions.php - reportUnmatchedIgnoredErrors: false symfony: container_xml_path: var/cache/dev/KernelDevDebugContainer.xml - excludes_analyse: + excludePaths: # Makes PHPStan crash - '**/DependencyInjection/Configuration.php' - '**/Migrations/Version*.php' diff --git a/public/app.php b/public/app.php deleted file mode 100644 index 2de934c4..00000000 --- a/public/app.php +++ /dev/null @@ -1,38 +0,0 @@ -handle($request); -$response->send(); - -$kernel->terminate($request, $response); diff --git a/src/BehatKernel.php b/src/BehatKernel.php new file mode 100644 index 00000000..4c78db11 --- /dev/null +++ b/src/BehatKernel.php @@ -0,0 +1,32 @@ +addBundle(new \Wvision\Bundle\DataDefinitionsBundle\DataDefinitionsBundle()); + $collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle()); + } + + public function boot(): void + { + parent::boot(); + + \Pimcore::setKernel($this); + } +} diff --git a/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php b/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php index 5015b475..202a8528 100644 --- a/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php +++ b/src/DataDefinitionsBundle/Cleaner/AbstractCleaner.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Cleaner; -use Exception; use Pimcore\Model\DataObject\Concrete; use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\Log; diff --git a/src/DataDefinitionsBundle/Cleaner/Deleter.php b/src/DataDefinitionsBundle/Cleaner/Deleter.php index adefd0c9..6ee8483b 100644 --- a/src/DataDefinitionsBundle/Cleaner/Deleter.php +++ b/src/DataDefinitionsBundle/Cleaner/Deleter.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Cleaner; -use Exception; use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; class Deleter extends AbstractCleaner diff --git a/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php b/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php index 9fecc625..792d75be 100644 --- a/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php +++ b/src/DataDefinitionsBundle/Command/AbstractImportDefinitionCommand.php @@ -19,8 +19,6 @@ use CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface; use CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager; use CoreShop\Component\Resource\Metadata\MetadataInterface; -use CoreShop\Component\Resource\Repository\RepositoryInterface; -use Doctrine\ORM\EntityManagerInterface; use InvalidArgumentException; use Pimcore\Console\AbstractCommand; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/DataDefinitionsBundle/Command/ExportCommand.php b/src/DataDefinitionsBundle/Command/ExportCommand.php index c3d95bb0..dbe1d666 100644 --- a/src/DataDefinitionsBundle/Command/ExportCommand.php +++ b/src/DataDefinitionsBundle/Command/ExportCommand.php @@ -52,17 +52,20 @@ protected function configure(): void $this ->setName('data-definitions:export') ->setDescription('Run a Data Definition Export.') - ->setHelp(<<setHelp( + <<%command.name% runs a Data Definition Export. EOT ) ->addOption( - 'definition', 'd', + 'definition', + 'd', InputOption::VALUE_REQUIRED, 'Import Definition ID or Name' ) ->addOption( - 'params', 'p', + 'params', + 'p', InputOption::VALUE_REQUIRED, 'JSON Encoded Params' ); @@ -73,22 +76,23 @@ protected function execute(InputInterface $input, OutputInterface $output) $eventDispatcher = $this->eventDispatcher; $params = json_decode($input->getOption('params'), true); + $definition = null; try { - $definition = $this->repository->find($input->getOption('definition')); - } catch (InvalidArgumentException $e) { $definition = $this->repository->findByName($input->getOption('definition')); - } - $progress = null; - $process = null; + } catch (InvalidArgumentException $e) { - if (!is_array($params)) { - $params = []; } if (!$definition instanceof ExportDefinitionInterface) { throw new Exception('Export Definition not found'); } + $progress = null; + + if (!is_array($params)) { + $params = []; + } + $imStatus = function (ExportDefinitionEvent $e) use (&$progress) { if ($progress instanceof ProgressBar) { $progress->setMessage($e->getSubject()); @@ -100,7 +104,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $total = $e->getSubject(); if ($total > 0) { $progress = new ProgressBar($output, $total); - $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% (%elapsed:6s%/%estimated:-6s%) %memory:6s%: %message%'); + $progress->setFormat( + ' %current%/%max% [%bar%] %percent:3s%% (%elapsed:6s%/%estimated:-6s%) %memory:6s%: %message%' + ); $progress->start(); } }; diff --git a/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php b/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php new file mode 100644 index 00000000..ac964c23 --- /dev/null +++ b/src/DataDefinitionsBundle/Command/ImportAsyncCommand.php @@ -0,0 +1,87 @@ +setName('data-definitions:async-import') + ->setDescription('Run a Data Definition Import Async.') + ->addOption( + 'definition', + 'd', + InputOption::VALUE_REQUIRED, + 'Import Definition ID or Name' + ) + ->addOption( + 'params', + 'p', + InputOption::VALUE_REQUIRED, + 'JSON Encoded Params' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $eventDispatcher = $this->eventDispatcher; + + $params = json_decode($input->getOption('params'), true); + + if (!isset($params['userId'])) { + $params['userId'] = 0; + } + + try { + $definition = $this->repository->find($input->getOption('definition')); + } catch (InvalidArgumentException $e) { + $definition = $this->repository->findByName($input->getOption('definition')); + } + + if (!$definition instanceof ImportDefinitionInterface) { + throw new Exception('Import Definition not found'); + } + + $this->importer->doImportAsync($definition, $params); + + return 0; + } +} diff --git a/src/DataDefinitionsBundle/Command/ImportCommand.php b/src/DataDefinitionsBundle/Command/ImportCommand.php index e67cecf6..2278bf3f 100644 --- a/src/DataDefinitionsBundle/Command/ImportCommand.php +++ b/src/DataDefinitionsBundle/Command/ImportCommand.php @@ -82,27 +82,27 @@ protected function execute(InputInterface $input, OutputInterface $output) $params['userId'] = 0; } + $definition = null; + try { - $definition = $this->repository->find($input->getOption('definition')); - } catch (InvalidArgumentException $e) { $definition = $this->repository->findByName($input->getOption('definition')); - } + } catch (InvalidArgumentException $e) { - $progress = null; - $process = null; - $countProgress = 0; - $startTime = time(); + } if (!$definition instanceof ImportDefinitionInterface) { throw new Exception('Import Definition not found'); } + $progress = null; + $countProgress = 0; + $startTime = time(); + $imStatus = function (ImportDefinitionEvent $e) use ($output, &$progress, &$countProgress, $startTime) { if ($progress instanceof ProgressBar) { $progress->setMessage($e->getSubject()); $progress->display(); - } - else { + } else { $output->writeln( sprintf( '%s (%s) (%s): %s', diff --git a/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php b/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php index f3dd4250..75dd7614 100644 --- a/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php +++ b/src/DataDefinitionsBundle/Command/ListExportDefinitionsCommand.php @@ -39,7 +39,8 @@ protected function configure(): void $this ->setName('data-definitions:list:exports') ->setDescription('List all Export Definitions.') - ->setHelp(<<setHelp( + <<%command.name% lists all Data Definitions for Exports. EOT ); diff --git a/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php b/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php index 77119fa9..db96ad39 100644 --- a/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php +++ b/src/DataDefinitionsBundle/Command/ListImportDefinitionsCommand.php @@ -39,7 +39,8 @@ protected function configure(): void $this ->setName('data-definitions:list:imports') ->setDescription('List all Import Definitions.') - ->setHelp(<<setHelp( + <<%command.name% lists all Data Definitions for Imports. EOT ); diff --git a/src/DataDefinitionsBundle/Context/Context.php b/src/DataDefinitionsBundle/Context/Context.php new file mode 100644 index 00000000..5a259ff4 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/Context.php @@ -0,0 +1,57 @@ +definition; + } + + public function getParams(): array + { + return $this->params; + } + + public function withConfiguration(array $configuration): self + { + $context = clone $this; + $context->setConfiguration($configuration); + + return $context; + } + + protected function setConfiguration(array $configuration): void + { + $this->configuration = $configuration; + } + + public function getConfiguration(): array + { + return $this->configuration; + } +} diff --git a/src/DataDefinitionsBundle/Context/ContextFactory.php b/src/DataDefinitionsBundle/Context/ContextFactory.php new file mode 100644 index 00000000..2549e894 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/ContextFactory.php @@ -0,0 +1,101 @@ +definition; + + return $definition; + } +} diff --git a/src/DataDefinitionsBundle/Context/FetcherContextInterface.php b/src/DataDefinitionsBundle/Context/FetcherContextInterface.php new file mode 100644 index 00000000..a7212142 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/FetcherContextInterface.php @@ -0,0 +1,24 @@ +dataRow; + } + + public function getDataSet(): ImportDataSetInterface + { + return $this->dataSet; + } + + public function getObject(): Concrete + { + return $this->object; + } +} diff --git a/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php b/src/DataDefinitionsBundle/Context/FilterContextInterface.php similarity index 67% rename from src/DataDefinitionsBundle/Model/DataSetAwareInterface.php rename to src/DataDefinitionsBundle/Context/FilterContextInterface.php index 84f93d13..a77800e8 100644 --- a/src/DataDefinitionsBundle/Model/DataSetAwareInterface.php +++ b/src/DataDefinitionsBundle/Context/FilterContextInterface.php @@ -14,13 +14,17 @@ declare(strict_types=1); -namespace Wvision\Bundle\DataDefinitionsBundle\Model; +namespace Wvision\Bundle\DataDefinitionsBundle\Context; +use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportDataSetInterface; -interface DataSetAwareInterface +interface FilterContextInterface extends ContextInterface { public function getDataSet(): ImportDataSetInterface; - public function setDataSet(ImportDataSetInterface $dataSet): void; + public function getDataRow(): array; + + public function getObject(): Concrete; } diff --git a/src/DataDefinitionsBundle/Context/GetterContext.php b/src/DataDefinitionsBundle/Context/GetterContext.php new file mode 100644 index 00000000..159f7cb2 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/GetterContext.php @@ -0,0 +1,44 @@ +object; + } + + public function getMapping(): ExportMapping + { + return $this->mapping; + } +} diff --git a/src/DataDefinitionsBundle/Context/GetterContextInterface.php b/src/DataDefinitionsBundle/Context/GetterContextInterface.php new file mode 100644 index 00000000..a92f6ebb --- /dev/null +++ b/src/DataDefinitionsBundle/Context/GetterContextInterface.php @@ -0,0 +1,28 @@ +dataRow; + } + + public function getDataSet(): ?ImportDataSetInterface + { + return $this->dataSet; + } + + public function getObject(): Concrete + { + return $this->object; + } + + + public function getValue(): mixed + { + return $this->value; + } + + public function getMapping(): MappingInterface + { + return $this->mapping; + } +} diff --git a/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php b/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php new file mode 100644 index 00000000..2d8629fc --- /dev/null +++ b/src/DataDefinitionsBundle/Context/InterpreterContextInterface.php @@ -0,0 +1,34 @@ +definition; + + return $definition; + } + + public function getDataRow(): array + { + return $this->dataRow; + } + + public function getDataSet(): ImportDataSetInterface + { + return $this->dataSet; + } + + public function getClass(): string + { + return $this->class; + } +} diff --git a/src/DataDefinitionsBundle/Context/LoaderContextInterface.php b/src/DataDefinitionsBundle/Context/LoaderContextInterface.php new file mode 100644 index 00000000..3dd61c11 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/LoaderContextInterface.php @@ -0,0 +1,31 @@ +dataRow; + } + + public function getDataSet(): ?ImportDataSetInterface + { + return $this->dataSet; + } + + public function getObject(): ?Concrete + { + return $this->object; + } +} diff --git a/src/DataDefinitionsBundle/Context/RunnerContextInterface.php b/src/DataDefinitionsBundle/Context/RunnerContextInterface.php new file mode 100644 index 00000000..af9948d9 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/RunnerContextInterface.php @@ -0,0 +1,30 @@ +object; + } + + public function getMapping(): ImportMapping + { + return $this->mapping; + } + + public function getDataRow(): array + { + return $this->dataRow; + } + + public function getDataSet(): ImportDataSetInterface + { + return $this->dataSet; + } + + public function getValue(): mixed + { + return $this->value; + } +} diff --git a/src/DataDefinitionsBundle/Context/SetterContextInterface.php b/src/DataDefinitionsBundle/Context/SetterContextInterface.php new file mode 100644 index 00000000..67969a78 --- /dev/null +++ b/src/DataDefinitionsBundle/Context/SetterContextInterface.php @@ -0,0 +1,35 @@ +isGrantedOr403(); + + $resources = $this->findOr404((string) $this->getParameterFromRequest($request, 'id')); + + return $this->viewHandler->handle(['data' => $resources, 'success' => true], ['group' => 'Detailed']); + } +} diff --git a/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php b/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php index 7d714406..9dd71c0c 100644 --- a/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php +++ b/src/DataDefinitionsBundle/Controller/ExportDefinitionController.php @@ -27,7 +27,7 @@ use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping\FromColumn; -class ExportDefinitionController extends ResourceController +class ExportDefinitionController extends AbstractDefinitionController { public function getConfigAction(): JsonResponse { @@ -48,8 +48,8 @@ public function getConfigAction(): JsonResponse 'fetchers' => array_keys($fetchers), 'import_rules' => [ 'conditions' => array_keys($importRuleConditions), - 'actions' => array_keys($importRuleActions) - ] + 'actions' => array_keys($importRuleActions), + ], ] ); } @@ -173,8 +173,13 @@ public function getColumnsAction(Request $request): JsonResponse $localizedField->setGroup('localizedfield.'.strtolower($language)); $localizedField->setType('localizedfields'); - $localizedField->setIdentifier(sprintf('%s~%s', $localizedField->getIdentifier(), - $language)); + $localizedField->setIdentifier( + sprintf( + '%s~%s', + $localizedField->getIdentifier(), + $language + ) + ); $localizedField->setGetter('localizedfield'); $localizedField->setConfig(['language' => $language]); $localizedField->setGetterConfig(['language' => $language]); @@ -194,7 +199,8 @@ public function getColumnsAction(Request $request): JsonResponse $classDefs = $brickDefinition->getClassDefinitions(); foreach ($classDefs as $classDef) { - if ($classDef['classname'] === $classDefinition->getName() && $classDef['fieldname'] === $field->getName()) { + if ($classDef['classname'] === $classDefinition->getName( + ) && $classDef['fieldname'] === $field->getName()) { $fields = $brickDefinition->getFieldDefinitions(); foreach ($fields as $brickField) { @@ -202,8 +208,14 @@ public function getColumnsAction(Request $request): JsonResponse $resultField->setGroup('objectbrick.'.$key); $resultField->setType('objectbricks'); - $resultField->setIdentifier(sprintf('objectbrick~%s~%s~%s', $field->getName(), - $key, $resultField->getIdentifier())); + $resultField->setIdentifier( + sprintf( + 'objectbrick~%s~%s~%s', + $field->getName(), + $key, + $resultField->getIdentifier() + ) + ); $resultField->setGetter('objectbrick'); $resultField->setConfig(['class' => $key]); $resultField->setType('objectbrick'); @@ -228,8 +240,14 @@ public function getColumnsAction(Request $request): JsonResponse $resultField->setGroup('fieldcollection.'.$type); $resultField->setType('fieldcollections'); - $resultField->setIdentifier(sprintf('fieldcollection~%s~%s~%s', $field->getName(), $type, - $resultField->getIdentifier())); + $resultField->setIdentifier( + sprintf( + 'fieldcollection~%s~%s~%s', + $field->getName(), + $type, + $resultField->getIdentifier() + ) + ); $resultField->setGetter('fieldcollection'); $resultField->setConfig(['class' => $type]); $resultField->setType('fieldcollection'); @@ -250,8 +268,10 @@ public function getColumnsAction(Request $request): JsonResponse $allowedGroupIds = $field->getAllowedGroupIds(); if ($allowedGroupIds) { - $list->setCondition('ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', - [$field->getStoreId()]); + $list->setCondition( + 'ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', + [$field->getStoreId()] + ); } else { $list->setCondition('storeId = ?', [$field->getStoreId()]); } @@ -271,10 +291,21 @@ public function getColumnsAction(Request $request): JsonResponse $keyConfig = DataObject\Classificationstore\KeyConfig::getById($keyId); $toColumn = new FromColumn(); - $toColumn->setGroup(sprintf('classificationstore - %s (%s)', $config->getName(), - $config->getId())); - $toColumn->setIdentifier(sprintf('classificationstore~%s~%s~%s', $field->getName(), - $keyConfig->getId(), $config->getId())); + $toColumn->setGroup( + sprintf( + 'classificationstore - %s (%s)', + $config->getName(), + $config->getId() + ) + ); + $toColumn->setIdentifier( + sprintf( + 'classificationstore~%s~%s~%s', + $field->getName(), + $keyConfig->getId(), + $config->getId() + ) + ); $toColumn->setType('classificationstore'); $toColumn->setFieldtype($keyConfig->getType()); $toColumn->setGetter('classificationstore'); @@ -385,36 +416,36 @@ protected function getFieldConfiguration(DataObject\ClassDefinition\Data $field, protected function getConfigProviders(): array { - return $this->container->getParameter('data_definitions.export_providers'); + return $this->getParameter('data_definitions.export_providers'); } protected function getConfigInterpreters(): array { - return $this->container->getParameter('data_definitions.interpreters'); + return $this->getParameter('data_definitions.interpreters'); } protected function getConfigRunners(): array { - return $this->container->getParameter('data_definitions.export_runners'); + return $this->getParameter('data_definitions.export_runners'); } protected function getConfigGetters(): array { - return $this->container->getParameter('data_definitions.getters'); + return $this->getParameter('data_definitions.getters'); } protected function getConfigFetchers(): array { - return $this->container->getParameter('data_definitions.fetchers'); + return $this->getParameter('data_definitions.fetchers'); } protected function getImportRuleConditions(): array { - return $this->container->getParameter('data_definitions.import_rule.conditions'); + return $this->getParameter('data_definitions.import_rule.conditions'); } protected function getImportRuleActions(): array { - return $this->container->getParameter('data_definitions.import_rule.actions'); + return $this->getParameter('data_definitions.import_rule.actions'); } } diff --git a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php index 16c3019e..220e31d1 100644 --- a/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php +++ b/src/DataDefinitionsBundle/Controller/ImportDefinitionController.php @@ -16,21 +16,23 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Controller; -use CoreShop\Bundle\ResourceBundle\Controller\ResourceController; +use CoreShop\Component\Registry\ServiceRegistryInterface; use Exception; use Pimcore\Model\DataObject; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Contracts\Service\Attribute\SubscribedService; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping\FromColumn; use Wvision\Bundle\DataDefinitionsBundle\Service\FieldSelection; use function is_array; -class ImportDefinitionController extends ResourceController +class ImportDefinitionController extends AbstractDefinitionController { public function getConfigAction(): JsonResponse { @@ -41,6 +43,7 @@ public function getConfigAction(): JsonResponse $setters = $this->getConfigSetters(); $filters = $this->getConfigFilters(); $runners = $this->getConfigRunners(); + $persisters = $this->getConfigPersisters(); $importRuleConditions = $this->getImportRuleConditions(); $importRuleActions = $this->getImportRuleActions(); @@ -52,10 +55,11 @@ public function getConfigAction(): JsonResponse 'setter' => array_keys($setters), 'filters' => array_keys($filters), 'runner' => array_keys($runners), + 'persister' => array_keys($persisters), 'import_rules' => [ 'conditions' => array_keys($importRuleConditions), - 'actions' => array_keys($importRuleActions) - ] + 'actions' => array_keys($importRuleActions), + ], ]); } @@ -66,7 +70,11 @@ public function testDataAction(Request $request): JsonResponse if ($definition instanceof ImportDefinitionInterface) { try { - if ($this->get('data_definitions.registry.provider')->get($definition->getProvider())->testData($definition->getConfiguration())) { + if ($this->container->get('data_definitions.registry.provider')->get( + $definition->getProvider() + )->testData( + $definition->getConfiguration() + )) { return $this->viewHandler->handle(['success' => true]); } } catch (Exception $ex) { @@ -88,7 +96,9 @@ public function getColumnsAction(Request $request): JsonResponse $customFromColumn->setLabel('Custom'); try { - $fromColumns = $this->get('data_definitions.registry.provider')->get($definition->getProvider())->getColumns($definition->getConfiguration()); + $fromColumns = $this->container->get('data_definitions.registry.provider')->get( + $definition->getProvider() + )->getColumns($definition->getConfiguration()); $fromColumns[] = $customFromColumn; } catch (Exception $e) { $fromColumns = []; @@ -100,7 +110,7 @@ public function getColumnsAction(Request $request): JsonResponse throw new NotFoundHttpException(); } - $toColumns = $this->get(FieldSelection::class)->getClassDefinition($classDefinition); + $toColumns = $this->container->get(FieldSelection::class)->getClassDefinition($classDefinition); $mappings = $definition->getMapping(); $mappingDefinition = []; $fromColumnsResult = []; @@ -191,8 +201,10 @@ public function exportAction(Request $request): Response $response = new Response(); $response->headers->set('Content-Type', 'application/json'); - $response->headers->set('Content-Disposition', - sprintf('attachment; filename="import-definition-%s.json"', $name)); + $response->headers->set( + 'Content-Disposition', + sprintf('attachment; filename="import-definition-%s.json"', $name) + ); $response->headers->set('Pragma', 'no-cache'); $response->headers->set('Expires', '0'); $response->headers->set('Content-Transfer-Encoding', 'binary'); @@ -255,48 +267,62 @@ public function duplicateAction(Request $request): JsonResponse return $this->viewHandler->handle(['success' => false]); } + public static function getSubscribedServices(): array + { + return parent::getSubscribedServices() + [ + FieldSelection::class, + new SubscribedService('data_definitions.registry.provider', ServiceRegistryInterface::class, attributes: new Autowire(service: 'data_definitions.registry.provider')) + ]; + } + + protected function getConfigProviders(): array { - return $this->container->getParameter('data_definitions.import_providers'); + return $this->getParameter('data_definitions.import_providers'); } protected function getConfigLoaders(): array { - return $this->container->getParameter('data_definitions.loaders'); + return $this->getParameter('data_definitions.loaders'); } protected function getConfigInterpreters(): array { - return $this->container->getParameter('data_definitions.interpreters'); + return $this->getParameter('data_definitions.interpreters'); } protected function getConfigCleaners(): array { - return $this->container->getParameter('data_definitions.cleaners'); + return $this->getParameter('data_definitions.cleaners'); } protected function getConfigSetters(): array { - return $this->container->getParameter('data_definitions.setters'); + return $this->getParameter('data_definitions.setters'); } protected function getConfigFilters(): array { - return $this->container->getParameter('data_definitions.filters'); + return $this->getParameter('data_definitions.filters'); } protected function getConfigRunners(): array { - return $this->container->getParameter('data_definitions.runners'); + return $this->getParameter('data_definitions.runners'); + } + + protected function getConfigPersisters(): array + { + return $this->getParameter('data_definitions.persisters'); } protected function getImportRuleConditions(): array { - return $this->container->getParameter('data_definitions.import_rule.conditions'); + return $this->getParameter('data_definitions.import_rule.conditions'); } protected function getImportRuleActions(): array { - return $this->container->getParameter('data_definitions.import_rule.actions'); + return $this->getParameter('data_definitions.import_rule.actions'); } } diff --git a/src/DataDefinitionsBundle/Controller/ImportRuleController.php b/src/DataDefinitionsBundle/Controller/ImportRuleController.php index 535f3467..ffa45046 100644 --- a/src/DataDefinitionsBundle/Controller/ImportRuleController.php +++ b/src/DataDefinitionsBundle/Controller/ImportRuleController.php @@ -16,13 +16,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; +use Pimcore\Bundle\AdminBundle\Controller\GDPR\AdminController; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Wvision\Bundle\DataDefinitionsBundle\Exception\SpoutException; use Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportRulesImportType; class ImportRuleController extends AdminController @@ -114,18 +113,19 @@ public function importAction(Request $request, FormFactoryInterface $formFactory $lastConfigIndex = $configIndex; $condition = [ 'type' => $configType, - 'configuration' => [] + 'configuration' => [], ]; - } - else if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { - if (null !== $condition && count($condition['configuration']) > 0) { - $conditions[] = $condition; + } else { + if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { + if (null !== $condition && count($condition['configuration']) > 0) { + $conditions[] = $condition; + } + + $condition = [ + 'type' => $configType, + 'configuration' => [], + ]; } - - $condition = [ - 'type' => $configType, - 'configuration' => [] - ]; } $condition['configuration'][$configKey] = $value; @@ -148,18 +148,19 @@ public function importAction(Request $request, FormFactoryInterface $formFactory $lastConfigIndex = $configIndex; $action = [ 'type' => $configType, - 'configuration' => [] + 'configuration' => [], ]; - } - else if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { - if (null !== $action && count($action['configuration']) > 0) { - $actions[] = $action; + } else { + if ($lastConfigType !== $configType || $lastConfigKey === $configKey || $lastConfigIndex !== $configIndex) { + if (null !== $action && count($action['configuration']) > 0) { + $actions[] = $action; + } + + $action = [ + 'type' => $configType, + 'configuration' => [], + ]; } - - $action = [ - 'type' => $configType, - 'configuration' => [] - ]; } $action['configuration'][$configKey] = $value; @@ -176,7 +177,17 @@ public function importAction(Request $request, FormFactoryInterface $formFactory $rule['actions'] = $actions; $rule['conditions'] = $conditions; - $rule['id'] = sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); + $rule['id'] = sprintf( + '%04X%04X-%04X-%04X-%04X-%04X%04X%04X', + mt_rand(0, 65535), + mt_rand(0, 65535), + mt_rand(0, 65535), + mt_rand(16384, 20479), + mt_rand(32768, 49151), + mt_rand(0, 65535), + mt_rand(0, 65535), + mt_rand(0, 65535) + ); $rules[] = $rule; } @@ -197,7 +208,7 @@ public function exportAction(Request $request): BinaryFileResponse $headers = [ 'name', - 'active' + 'active', ]; $headersCondition = []; $headersAction = []; @@ -210,7 +221,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $condition['type']; foreach ($condition['configuration'] as $key => $value) { - $conditionHeader = 'condition_' . $type . '___1___' . $key; + $conditionHeader = 'condition_'.$type.'___1___'.$key; if (!array_key_exists($conditionHeader, $countPerType)) { $countPerType[$conditionHeader] = 0; @@ -219,7 +230,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$conditionHeader]++; if ($countPerType[$conditionHeader] > 1) { - $conditionHeader = 'condition_' . $type . '___'.$countPerType[$conditionHeader].'___' . $key; + $conditionHeader = 'condition_'.$type.'___'.$countPerType[$conditionHeader].'___'.$key; } if (!in_array($conditionHeader, $headersCondition)) { @@ -232,7 +243,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $action['type']; foreach ($action['configuration'] as $key => $value) { - $actionHeader = 'action_' . $type . '___1___' . $key; + $actionHeader = 'action_'.$type.'___1___'.$key; if (!array_key_exists($actionHeader, $countPerType)) { $countPerType[$actionHeader] = 0; @@ -241,7 +252,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$actionHeader]++; if ($countPerType[$actionHeader] > 1) { - $actionHeader = 'action_' . $type . '___'.$countPerType[$actionHeader].'___' . $key; + $actionHeader = 'action_'.$type.'___'.$countPerType[$actionHeader].'___'.$key; } if (!in_array($actionHeader, $headersAction)) { @@ -266,7 +277,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $condition['type']; foreach ($condition['configuration'] as $key => $value) { - $conditionHeader = 'condition_' . $type . '___1___' . $key; + $conditionHeader = 'condition_'.$type.'___1___'.$key; if (!array_key_exists($conditionHeader, $countPerType)) { $countPerType[$conditionHeader] = 0; @@ -275,7 +286,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$conditionHeader]++; if ($countPerType[$conditionHeader] > 1) { - $conditionHeader = 'condition_' . $type . '___'.$countPerType[$conditionHeader].'___' . $key; + $conditionHeader = 'condition_'.$type.'___'.$countPerType[$conditionHeader].'___'.$key; } if (is_array($value)) { @@ -290,7 +301,7 @@ public function exportAction(Request $request): BinaryFileResponse $type = $action['type']; foreach ($action['configuration'] as $key => $value) { - $actionHeader = 'action_' . $type . '___1___' . $key; + $actionHeader = 'action_'.$type.'___1___'.$key; if (!array_key_exists($actionHeader, $countPerType)) { $countPerType[$actionHeader] = 0; @@ -299,7 +310,7 @@ public function exportAction(Request $request): BinaryFileResponse $countPerType[$actionHeader]++; if ($countPerType[$actionHeader] > 1) { - $actionHeader = 'action_' . $type . '___'.$countPerType[$actionHeader].'___' . $key; + $actionHeader = 'action_'.$type.'___'.$countPerType[$actionHeader].'___'.$key; } if (is_array($value)) { @@ -327,12 +338,16 @@ public function exportAction(Request $request): BinaryFileResponse $entry[$key] = $value; } - $result[] = $this->useSpoutLegacy ? $entry : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($entry); + $result[] = $this->useSpoutLegacy ? $entry : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( + $entry + ); } //merge all headers $headerValues = array_values(array_merge($headers, $headersCondition, $headersAction)); - $headers = $this->useSpoutLegacy ? $headerValues : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($headerValues); + $headers = $this->useSpoutLegacy ? $headerValues : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( + $headerValues + ); //write data $writer->addRow($headers); diff --git a/src/DataDefinitionsBundle/DataDefinitionsBundle.php b/src/DataDefinitionsBundle/DataDefinitionsBundle.php index df2c8ab7..fbb00edd 100644 --- a/src/DataDefinitionsBundle/DataDefinitionsBundle.php +++ b/src/DataDefinitionsBundle/DataDefinitionsBundle.php @@ -18,15 +18,14 @@ use Composer\InstalledVersions; use CoreShop\Bundle\ResourceBundle\AbstractResourceBundle; -use CoreShop\Bundle\ResourceBundle\ComposerPackageBundleInterface; use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle; use CoreShop\Bundle\RuleBundle\CoreShopRuleBundle; -use LogicException; +use Pimcore\Bundle\AdminBundle\PimcoreAdminBundle; +use Pimcore\Bundle\SimpleBackendSearchBundle\PimcoreSimpleBackendSearchBundle; +use Pimcore\Extension\Bundle\Installer\InstallerInterface; use Pimcore\Extension\Bundle\PimcoreBundleInterface; -use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; use Pimcore\HttpKernel\BundleCollection\BundleCollection; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\CleanerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportProviderRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportRunnerRegistryCompilerPass; @@ -37,16 +36,22 @@ use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ImportRuleConditionPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\InterpreterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\LoaderRegistryCompilerPass; +use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\PersisterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ProviderRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\RunnerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\SetterRegistryCompilerPass; -class DataDefinitionsBundle extends AbstractResourceBundle implements PimcoreBundleInterface +class DataDefinitionsBundle extends AbstractResourceBundle { public static function registerDependentBundles(BundleCollection $collection): void { parent::registerDependentBundles($collection); + $collection->addBundles([ + new PimcoreAdminBundle(), + new PimcoreSimpleBackendSearchBundle() + ]); + $collection->addBundles([ new CoreShopRuleBundle(), ], 3500); @@ -59,23 +64,24 @@ public function getSupportedDrivers(): array ]; } - public function build(ContainerBuilder $builder): void + public function build(ContainerBuilder $container): void { - parent::build($builder); - - $builder->addCompilerPass(new CleanerRegistryCompilerPass()); - $builder->addCompilerPass(new FilterRegistryCompilerPass()); - $builder->addCompilerPass(new InterpreterRegistryCompilerPass()); - $builder->addCompilerPass(new ProviderRegistryCompilerPass()); - $builder->addCompilerPass(new RunnerRegistryCompilerPass()); - $builder->addCompilerPass(new SetterRegistryCompilerPass()); - $builder->addCompilerPass(new LoaderRegistryCompilerPass()); - $builder->addCompilerPass(new GetterRegistryCompilerPass()); - $builder->addCompilerPass(new FetcherRegistryCompilerPass()); - $builder->addCompilerPass(new ExportProviderRegistryCompilerPass()); - $builder->addCompilerPass(new ExportRunnerRegistryCompilerPass()); - $builder->addCompilerPass(new ImportRuleConditionPass()); - $builder->addCompilerPass(new ImportRuleActionPass()); + parent::build($container); + + $container->addCompilerPass(new CleanerRegistryCompilerPass()); + $container->addCompilerPass(new FilterRegistryCompilerPass()); + $container->addCompilerPass(new InterpreterRegistryCompilerPass()); + $container->addCompilerPass(new ProviderRegistryCompilerPass()); + $container->addCompilerPass(new RunnerRegistryCompilerPass()); + $container->addCompilerPass(new SetterRegistryCompilerPass()); + $container->addCompilerPass(new LoaderRegistryCompilerPass()); + $container->addCompilerPass(new GetterRegistryCompilerPass()); + $container->addCompilerPass(new FetcherRegistryCompilerPass()); + $container->addCompilerPass(new ExportProviderRegistryCompilerPass()); + $container->addCompilerPass(new ExportRunnerRegistryCompilerPass()); + $container->addCompilerPass(new ImportRuleConditionPass()); + $container->addCompilerPass(new ImportRuleActionPass()); + $container->addCompilerPass(new PersisterRegistryCompilerPass()); } public function getVersion(): string @@ -97,12 +103,12 @@ public function getDescription(): string return 'Data Definitions allows you to create reusable Definitions for Importing all kinds of data into DataObjects.'; } - public function getInstaller() + public function getInstaller(): ?InstallerInterface { return $this->container->get(Installer::class); } - public function getAdminIframePath() + public function getAdminIframePath(): ?string { return null; } diff --git a/src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php b/src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php new file mode 100644 index 00000000..bd42ff99 --- /dev/null +++ b/src/DataDefinitionsBundle/DependencyInjection/Compiler/PersisterRegistryCompilerPass.php @@ -0,0 +1,21 @@ +getRootNode(); + ConfigurationHelper::addConfigLocationWithWriteTargetNodes($rootNode, [ + 'import_definitions' => '/var/config/import-definitions', + 'export_definitions' => '/var/config/export-definitions' + ]); + $rootNode ->children() ->scalarNode('driver')->defaultValue(CoreShopResourceBundle::DRIVER_PIMCORE)->end() ->end(); + $rootNode + ->children() + ->arrayNode('import_definitions') + ->normalizeKeys(false) + ->prototype('array') + ->children() + ->scalarNode('name')->end() + ->scalarNode('provider')->end() + ->scalarNode('class')->end() + ->scalarNode('runner')->end() + ->booleanNode('stopOnException')->end() + ->scalarNode('failureNotificationDocument')->end() + ->scalarNode('successNotificationDocument')->end() + ->scalarNode('loader')->end() + ->scalarNode('objectPath')->end() + ->scalarNode('cleaner')->end() + ->scalarNode('key')->end() + ->scalarNode('filter')->end() + ->booleanNode('renameExistingObjects')->end() + ->booleanNode('relocateExistingObjects')->end() + ->booleanNode('skipNewObjects')->end() + ->booleanNode('skipExistingObjects')->end() + ->booleanNode('createVersion')->end() + ->booleanNode('omitMandatoryCheck')->end() + ->booleanNode('forceLoadObject')->end() + ->variableNode('configuration')->end() + ->arrayNode('mapping') + ->prototype('array') + ->children() + ->scalarNode('primaryIdentifier')->end() + ->scalarNode('setter')->end() + ->variableNode('setterConfig')->end() + ->scalarNode('fromColumn')->end() + ->scalarNode('toColumn')->end() + ->scalarNode('interpreter')->end() + ->variableNode('interpreterConfig')->end() + ->end() + ->end() + ->end() + ->integerNode('creationDate')->end() + ->integerNode('modificationDate')->end() + ->end() + ->end() + ->end() + ->arrayNode('export_definitions') + ->normalizeKeys(false) + ->prototype('array') + ->children() + ->scalarNode('name')->end() + ->scalarNode('fetcher')->end() + ->variableNode('fetcherConfig')->end() + ->booleanNode('fetchUnpublished')->end() + ->scalarNode('provider')->end() + ->scalarNode('class')->end() + ->scalarNode('loader')->end() + ->variableNode('configuration')->end() + ->scalarNode('runner')->end() + ->booleanNode('stopOnException')->end() + ->scalarNode('failureNotificationDocument')->end() + ->scalarNode('successNotificationDocument')->end() + ->arrayNode('mapping') + ->prototype('array') + ->children() + ->scalarNode('primaryIdentifier')->end() + ->scalarNode('getter')->end() + ->variableNode('getterConfig')->end() + ->scalarNode('fromColumn')->end() + ->scalarNode('toColumn')->end() + ->scalarNode('interpreter')->end() + ->variableNode('interpreterConfig')->end() + ->end() + ->end() + ->end() + ->integerNode('creationDate')->end() + ->integerNode('modificationDate')->end() + ->end() + ->end() + ->end() + ->end(); + $this->addPimcoreResourcesSection($rootNode); $this->addModelsSection($rootNode); @@ -125,4 +212,4 @@ private function addPimcoreResourcesSection(ArrayNodeDefinition $node) ->end() ->end(); } -} +} \ No newline at end of file diff --git a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php index 50cdcb70..738f7f34 100644 --- a/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php +++ b/src/DataDefinitionsBundle/DependencyInjection/DataDefinitionsExtension.php @@ -17,9 +17,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\DependencyInjection; use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension; +use Pimcore\Config\LocationAwareConfigRepository; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Wvision\Bundle\DataDefinitionsBundle\Cleaner\CleanerInterface; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\CleanerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ExportProviderRegistryCompilerPass; @@ -29,6 +32,7 @@ use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\GetterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\InterpreterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\LoaderRegistryCompilerPass; +use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\PersisterRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\ProviderRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\RunnerRegistryCompilerPass; use Wvision\Bundle\DataDefinitionsBundle\DependencyInjection\Compiler\SetterRegistryCompilerPass; @@ -37,17 +41,18 @@ use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; use Wvision\Bundle\DataDefinitionsBundle\Loader\LoaderInterface; +use Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ExportProviderInterface; use Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\ExportRunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface; use Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface; -class DataDefinitionsExtension extends AbstractModelExtension +class DataDefinitionsExtension extends AbstractModelExtension implements PrependExtensionInterface { public function load(array $configs, ContainerBuilder $container) { - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); @@ -69,6 +74,10 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('services.yml'); + if (class_exists(\GuzzleHttp\Psr7\HttpFactory::class)) { + $loader->load('guzzle_psr7.yml'); + } + if (array_key_exists('ProcessManagerBundle', $bundles)) { $config['pimcore_admin']['js']['process_manager_import'] = '/bundles/datadefinitions/pimcore/js/process_manager/import_definitions.js'; $config['pimcore_admin']['js']['process_manager_export'] = '/bundles/datadefinitions/pimcore/js/process_manager/export_definitions.js'; @@ -112,5 +121,19 @@ public function load(array $configs, ContainerBuilder $container) $container ->registerForAutoconfiguration(SetterInterface::class) ->addTag(SetterRegistryCompilerPass::SETTER_TAG); + $container + ->registerForAutoconfiguration(PersisterInterface::class) + ->addTag(PersisterRegistryCompilerPass::PERSISTER_TAG); + + $container->setParameter('data_definitions.config_location', $config['config_location'] ?? []); + + $container->setParameter('data_definitions.import_definitions', $config['import_definitions']); + $container->setParameter('data_definitions.export_definitions', $config['export_definitions']); + } + + public function prepend(ContainerBuilder $container): void + { + LocationAwareConfigRepository::loadSymfonyConfigFiles($container, 'data_definitions', 'export_definitions'); + LocationAwareConfigRepository::loadSymfonyConfigFiles($container, 'data_definitions', 'import_definitions'); } } diff --git a/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php b/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php index d2a6336c..d30642be 100644 --- a/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php +++ b/src/DataDefinitionsBundle/Event/EventDispatcherInterface.php @@ -18,5 +18,10 @@ interface EventDispatcherInterface { - public function dispatch(DataDefinitionInterface $definition, string $eventName, $subject = null, array $params = []); + public function dispatch( + DataDefinitionInterface $definition, + string $eventName, + $subject = null, + array $params = [] + ); } diff --git a/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php b/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php index 77ba7c16..a715e296 100644 --- a/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php +++ b/src/DataDefinitionsBundle/Event/ImportDefinitionEvent.php @@ -32,7 +32,7 @@ public function __construct(ImportDefinitionInterface $definition, $subject = nu $this->options = $options; } - public function getDefinition() : ImportDefinitionInterface + public function getDefinition(): ImportDefinitionInterface { return $this->definition; } diff --git a/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php b/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php new file mode 100644 index 00000000..9b48546d --- /dev/null +++ b/src/DataDefinitionsBundle/EventListener/PimcoreSettingsListener.php @@ -0,0 +1,29 @@ +getSubject(); + + if ($subject instanceof ImportDefinition && !$subject->isWriteable()) { + throw new ConfigWriteException(); + } + + if ($subject instanceof ExportDefinition && !$subject->isWriteable()) { + throw new ConfigWriteException(); + } + } + + public static function getSubscribedEvents() + { + return [ + 'data_definitions.import_definition.pre_save' => 'definitionIsWritable', + 'data_definitions.export_definition.pre_save' => 'definitionIsWritable', + ]; + } +} diff --git a/src/DataDefinitionsBundle/Exception/InterpreterException.php b/src/DataDefinitionsBundle/Exception/InterpreterException.php index 816ba6d0..905268c1 100644 --- a/src/DataDefinitionsBundle/Exception/InterpreterException.php +++ b/src/DataDefinitionsBundle/Exception/InterpreterException.php @@ -23,24 +23,44 @@ class InterpreterException extends RuntimeException { - private function __construct(DataDefinitionInterface $definition, MappingInterface $mapping, array $params, $value, ?Throwable $previous = null) - { + private function __construct( + DataDefinitionInterface $definition, + MappingInterface $mapping, + array $params, + $value, + ?Throwable $previous = null + ) { parent::__construct($this->formatMessage($definition, $mapping, $params, $value, $previous), 0, $previous); } - public static function fromInterpreter(DataDefinitionInterface $definition, MappingInterface $mapping, array $params, $value, ?Throwable $previous = null): InterpreterException - { + public static function fromInterpreter( + DataDefinitionInterface $definition, + MappingInterface $mapping, + array $params, + $value, + ?Throwable $previous = null + ): InterpreterException { return new self($definition, $mapping, $params, $value, $previous); } - private function formatMessage(DataDefinitionInterface $definition, MappingInterface $mapping, array $params, $value, ?Throwable $previous = null): string - { + private function formatMessage( + DataDefinitionInterface $definition, + MappingInterface $mapping, + array $params, + $value, + ?Throwable $previous = null + ): string { $format = '%1$s, %2$s'; if ($previous !== null) { $format = '%1$s, %2$s: %3$s'; } - return sprintf($format, $this->formatDefinition($definition), $this->formatSource($mapping, $value, $params['row'] ?? null), $previous ? $previous->getMessage() : null); + return sprintf( + $format, + $this->formatDefinition($definition), + $this->formatSource($mapping, $value, $params['row'] ?? null), + $previous ? $previous->getMessage() : null + ); } private function formatDefinition(DataDefinitionInterface $definition): string @@ -55,7 +75,15 @@ private function formatSource(MappingInterface $mapping, $value, ?int $row = nul $format = 'from "%1$s" (row %5$d) to "%2$s" (interpreter "%3$s", config %4$s), got value %6$s'; } - return sprintf($format, $mapping->getFromColumn(), $mapping->getToColumn(), $mapping->getInterpreter(), var_export_pretty($mapping->getInterpreterConfig()), $row, $this->formatValue($value)); + return sprintf( + $format, + $mapping->getFromColumn(), + $mapping->getToColumn(), + $mapping->getInterpreter(), + var_export_pretty($mapping->getInterpreterConfig()), + $row, + $this->formatValue($value) + ); } private function formatValue($value): string diff --git a/src/DataDefinitionsBundle/Exporter/Exporter.php b/src/DataDefinitionsBundle/Exporter/Exporter.php index b75435e3..736fbc7a 100644 --- a/src/DataDefinitionsBundle/Exporter/Exporter.php +++ b/src/DataDefinitionsBundle/Exporter/Exporter.php @@ -24,8 +24,9 @@ use Pimcore\Model\DataObject\Concrete; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Event\ExportDefinitionEvent; -use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; use Wvision\Bundle\DataDefinitionsBundle\Exception\UnexpectedValueException; use Wvision\Bundle\DataDefinitionsBundle\Fetcher\FetcherInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\DynamicColumnGetterInterface; @@ -39,47 +40,36 @@ final class Exporter implements ExporterInterface { - private ServiceRegistryInterface$fetcherRegistry; - private ServiceRegistryInterface$runnerRegistry; - private ServiceRegistryInterface$interpreterRegistry; - private ServiceRegistryInterface$getterRegistry; - private ServiceRegistryInterface$exportProviderRegistry; - private EventDispatcherInterface$eventDispatcher; - private LoggerInterface$logger; - private array $exceptions = []; private bool $shouldStop = false; + private array $exceptions = []; public function __construct( - ServiceRegistryInterface $fetcherRegistry, - ServiceRegistryInterface $runnerRegistry, - ServiceRegistryInterface $interpreterRegistry, - ServiceRegistryInterface $getterRegistry, - ServiceRegistryInterface $exportProviderRegistry, - EventDispatcherInterface $eventDispatcher, - LoggerInterface $logger + private ServiceRegistryInterface $fetcherRegistry, + private ServiceRegistryInterface $runnerRegistry, + private ServiceRegistryInterface $interpreterRegistry, + private ServiceRegistryInterface $getterRegistry, + private ServiceRegistryInterface $exportProviderRegistry, + private ContextFactoryInterface $contextFactory, + private EventDispatcherInterface $eventDispatcher, + private LoggerInterface $logger ) { - $this->fetcherRegistry = $fetcherRegistry; - $this->runnerRegistry = $runnerRegistry; - $this->interpreterRegistry = $interpreterRegistry; - $this->getterRegistry = $getterRegistry; - $this->exportProviderRegistry = $exportProviderRegistry; - $this->eventDispatcher = $eventDispatcher; - $this->logger = $logger; + } public function doExport(ExportDefinitionInterface $definition, array $params) { + $fetcherContext = $this->contextFactory->createFetcherContext($definition, $params, is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : []); + $fetcher = $this->getFetcher($definition); $provider = $this->getProvider($definition); - $total = $fetcher->count($definition, $params, - is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : []); + $total = $fetcher->count($fetcherContext); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, $total, $params), 'data_definitions.export.total' ); - $this->runExport($definition, $params, $total, $fetcher, $provider); + $this->runExport($definition, $params, $total, $fetcherContext, $fetcher, $provider); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, null, $params), @@ -90,8 +80,12 @@ public function doExport(ExportDefinitionInterface $definition, array $params) private function getFetcher(ExportDefinitionInterface $definition): FetcherInterface { if (!$this->fetcherRegistry->has($definition->getFetcher())) { - throw new InvalidArgumentException(sprintf('Export Definition %s has no valid fetcher configured', - $definition->getName())); + throw new InvalidArgumentException( + sprintf( + 'Export Definition %s has no valid fetcher configured', + $definition->getName() + ) + ); } /** @var FetcherInterface $fetcher */ @@ -103,8 +97,12 @@ private function getFetcher(ExportDefinitionInterface $definition): FetcherInter private function getProvider(ExportDefinitionInterface $definition): ExportProviderInterface { if (!$this->exportProviderRegistry->has($definition->getProvider())) { - throw new InvalidArgumentException(sprintf('Definition %s has no valid export provider configured', - $definition->getName())); + throw new InvalidArgumentException( + sprintf( + 'Definition %s has no valid export provider configured', + $definition->getName() + ) + ); } return $this->exportProviderRegistry->get($definition->getProvider()); @@ -114,30 +112,28 @@ private function runExport( ExportDefinitionInterface $definition, $params, int $total, + FetcherContextInterface $fetcherContext, FetcherInterface $fetcher, ExportProviderInterface $provider ) { UnpublishedHelper::hideUnpublished( - function () use ($definition, $params, $total, $fetcher, $provider) { + function () use ($definition, $params, $total, $fetcher, $provider, $fetcherContext) { $count = 0; - $countToClean = 1000; $perLoop = 50; $perRun = ceil($total / $perLoop); for ($i = 0; $i < $perRun; $i++) { $objects = $fetcher->fetch( - $definition, - $params, + $fetcherContext, $perLoop, - $i * $perLoop, - is_array($definition->getFetcherConfig()) ? $definition->getFetcherConfig() : [] + $i * $perLoop ); foreach ($objects as $object) { try { $this->exportRow($definition, $object, $params, $provider); - if (($count + 1) % $countToClean === 0) { + if (($count + 1) % $perLoop === 0) { Pimcore::collectGarbage(); $this->logger->info('Clean Garbage'); $this->eventDispatcher->dispatch( @@ -153,7 +149,9 @@ function () use ($definition, $params, $total, $fetcher, $provider) { $this->exceptions[] = $ex; $this->eventDispatcher->dispatch( - new ExportDefinitionEvent($definition, sprintf('Error: %s', $ex->getMessage()), $params), + new ExportDefinitionEvent( + $definition, sprintf('Error: %s', $ex->getMessage()), $params + ), 'data_definitions.export.status' ); @@ -173,6 +171,7 @@ function () use ($definition, $params, $total, $fetcher, $provider) { new ExportDefinitionEvent($definition, 'Process has been stopped.', $params), 'data_definitions.export.status' ); + return; } @@ -192,6 +191,7 @@ private function exportRow( $data = []; $runner = null; + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, null, $object); $this->eventDispatcher->dispatch( new ExportDefinitionEvent($definition, sprintf('Export Object %s', $object->getId()), $params), @@ -207,7 +207,7 @@ private function exportRow( } if ($runner instanceof ExportRunnerInterface) { - $data = $runner->exportPreRun($object, $data, $definition, $params); + $data = $runner->exportPreRun($runnerContext); } $this->logger->info(sprintf('Export Object: %s', $object->getRealFullPath())); @@ -247,7 +247,7 @@ private function exportRow( ); if ($runner instanceof ExportRunnerInterface) { - $data = $runner->exportPostRun($object, $data, $definition, $params); + $data = $runner->exportPostRun($runnerContext); } return $data; @@ -264,9 +264,10 @@ private function getObjectValue( $value = null; if (null !== $getter) { - $value = $getter->get($object, $map, $data); + $getterContext = $this->contextFactory->createGetterContext($definition, $params, $object, $map); + $value = $getter->get($getterContext); } else { - $getter = 'get' . ucfirst($map->getFromColumn()); + $getter = 'get'.ucfirst($map->getFromColumn()); if (method_exists($object, $getter)) { $value = $object->$getter(); @@ -278,18 +279,25 @@ private function getObjectValue( if ($interpreter instanceof InterpreterInterface) { try { - $value = $interpreter->interpret( - $object, - $value, - $map, - $data, + $context = $this->contextFactory->createInterpreterContext( $definition, $params, - $map->getInterpreterConfig() + $map->getInterpreterConfig(), + $data, + null, + $object, + $value, + $map + ); + $value = $interpreter->interpret($context); + } catch (UnexpectedValueException $ex) { + $this->logger->info( + sprintf( + 'Unexpected Value from Interpreter "%s" with message "%s"', + $map->getInterpreter(), + $ex->getMessage() + ) ); - } - catch (UnexpectedValueException $ex) { - $this->logger->info(sprintf('Unexpected Value from Interpreter "%s" with message "%s"', $map->getInterpreter(), $ex->getMessage())); } } @@ -311,7 +319,7 @@ private function fetchGetter(ExportMapping $map): ?GetterInterface return null; } - public function stop() : void + public function stop(): void { $this->shouldStop = true; } diff --git a/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php b/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php index 8a552a3f..53ace9d6 100644 --- a/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php +++ b/src/DataDefinitionsBundle/Fetcher/FetcherInterface.php @@ -16,18 +16,16 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Fetcher; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; interface FetcherInterface { public function fetch( - ExportDefinitionInterface $definition, - array $params, + FetcherContextInterface $context, int $limit, - int $offset, - array $configuration + int $offset ); - public function count(ExportDefinitionInterface $definition, array $params, array $configuration): int; + public function count(FetcherContextInterface $context): int; } diff --git a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php index 14aa78c6..6dfb67a8 100644 --- a/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php +++ b/src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php @@ -19,26 +19,34 @@ use InvalidArgumentException; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Concrete; +use Pimcore\Model\DataObject\Listing; +use Wvision\Bundle\DataDefinitionsBundle\Context\FetcherContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; class ObjectsFetcher implements FetcherInterface { - public function fetch(ExportDefinitionInterface $definition, array $params, int $limit, int $offset, array $configuration) + protected Listing $list; + + public function fetch(FetcherContextInterface $context, int $limit, int $offset) { - $list = $this->getClassListing($definition, $params); + $list = $this->getClassListing($context->getDefinition(), $context->getParams()); $list->setLimit($limit); $list->setOffset($offset); return $list->load(); } - public function count(ExportDefinitionInterface $definition, array $params, array $configuration): int + public function count(FetcherContextInterface $context): int { - return $this->getClassListing($definition, $params)->getTotalCount(); + return $this->getClassListing($context->getDefinition(), $context->getParams())->getTotalCount(); } - private function getClassListing(ExportDefinitionInterface $definition, array $params) + private function getClassListing(ExportDefinitionInterface $definition, array $params): Listing { + if (isset($this->list)) { + return $this->list; + } + $class = $definition->getClass(); $classDefinition = ClassDefinition::getByName($class); if (!$classDefinition instanceof ClassDefinition) { @@ -56,42 +64,44 @@ private function getClassListing(ExportDefinitionInterface $definition, array $p if (null !== $rootNode) { $quotedPath = $list->quote($rootNode->getRealFullPath()); - $quotedWildcardPath = $list->quote(str_replace('//', '/', $rootNode->getRealFullPath() . '/') . '%'); - $conditionFilters[] = '(o_path = ' . $quotedPath . ' OR o_path LIKE ' . $quotedWildcardPath . ')'; + $quotedWildcardPath = $list->quote(str_replace('//', '/', $rootNode->getRealFullPath().'/').'%'); + $conditionFilters[] = '(o_path = '.$quotedPath.' OR o_path LIKE '.$quotedWildcardPath.')'; } } - if ($params['query']) { + if (isset($params['query'])) { $query = $this->filterQueryParam($params['query']); if (!empty($query)) { - $conditionFilters[] = 'oo_id IN (SELECT id FROM search_backend_data WHERE MATCH (`data`,`properties`) AGAINST (' . $list->quote($query) . ' IN BOOLEAN MODE))'; + $conditionFilters[] = 'oo_id IN (SELECT id FROM search_backend_data WHERE MATCH (`data`,`properties`) AGAINST ('.$list->quote( + $query + ).' IN BOOLEAN MODE))'; } } - if ($params['only_direct_children'] == 'true' && null !== $rootNode) { - $conditionFilters[] = 'o_parentId = ' . $rootNode->getId(); + if (isset($params['only_direct_children']) && $params['only_direct_children'] == 'true' && null !== $rootNode) { + $conditionFilters[] = 'o_parentId = '.$rootNode->getId(); } - if ($params['condition']) { - $conditionFilters[] = '(' . $params['condition'] . ')'; + if (isset($params['condition'])) { + $conditionFilters[] = '('.$params['condition'].')'; } - if ($params['ids']) { + if (isset($params['ids'])) { $quotedIds = []; foreach ($params['ids'] as $id) { $quotedIds[] = $list->quote($id); } if (!empty($quotedIds)) { - $conditionFilters[] = 'oo_id IN (' . implode(',', $quotedIds) . ')'; + $conditionFilters[] = 'oo_id IN ('.implode(',', $quotedIds).')'; } } $list->setCondition(implode(' AND ', $conditionFilters)); // ensure a stable sort across pages - $list->setOrderKey('o_id'); + $list->setOrderKey('id'); $list->setOrder('asc'); - return $list; + return $this->list = $list; } protected function filterQueryParam(string $query) diff --git a/src/DataDefinitionsBundle/Filter/FilterInterface.php b/src/DataDefinitionsBundle/Filter/FilterInterface.php index 6ea05c37..1162d9c0 100644 --- a/src/DataDefinitionsBundle/Filter/FilterInterface.php +++ b/src/DataDefinitionsBundle/Filter/FilterInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Filter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\FilterContextInterface; interface FilterInterface { - public function filter(DataDefinitionInterface $definition, array $data, Concrete $object): bool; + public function filter(FilterContextInterface $context): bool; } diff --git a/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php b/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php index 7f571797..7ffa436f 100644 --- a/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php +++ b/src/DataDefinitionsBundle/Form/Type/ExportDefinitionType.php @@ -134,7 +134,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addConfigurationFields(FormInterface $form, string $configurationType): void { @@ -143,7 +143,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getRegistryIdentifier(FormInterface $form, $data = null): ?string @@ -161,7 +161,7 @@ protected function getRegistryIdentifier(FormInterface $form, $data = null): ?st /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addFetcherConfigurationFields(FormInterface $form, string $configurationType): void { @@ -170,7 +170,7 @@ protected function addFetcherConfigurationFields(FormInterface $form, string $co /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getFetcherRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php b/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php index 79c7fdd7..61b42e9b 100644 --- a/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php +++ b/src/DataDefinitionsBundle/Form/Type/ExportMappingType.php @@ -110,7 +110,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addGetterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -119,7 +119,7 @@ protected function addGetterConfigurationFields(FormInterface $form, string $con /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addInterpreterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -129,7 +129,7 @@ protected function addInterpreterConfigurationFields(FormInterface $form, string /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getGetterRegistryIdentifier(FormInterface $form, $data = null): ?string @@ -143,7 +143,7 @@ protected function getGetterRegistryIdentifier(FormInterface $form, $data = null /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getInterpreterRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php b/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php index 8b39f37a..2ecd4cf3 100644 --- a/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php +++ b/src/DataDefinitionsBundle/Form/Type/ExportProvider/CsvProviderType.php @@ -26,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('delimiter', TextType::class) - ->add('enclosure', TextType::class); + ->add('enclosure', TextType::class) + ->add('escape', TextType::class, ['empty_data' => '']); } } diff --git a/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php b/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php index 342ada00..d0f738ed 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportDefinitionType.php @@ -49,6 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('cleaner', CleanerChoiceType::class) ->add('filter', FilterChoiceType::class) ->add('runner', RunnerChoiceType::class) + ->add('persister', PersisterChoiceType::class) ->add('name', TextType::class) ->add('objectPath', TextType::class) ->add('key', TextType::class) @@ -104,7 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addConfigurationFields(FormInterface $form, string $configurationType): void { @@ -113,7 +114,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php b/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php index aecf6c52..7d84e355 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportMappingType.php @@ -114,7 +114,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addSetterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -123,7 +123,7 @@ protected function addSetterConfigurationFields(FormInterface $form, string $con /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addInterpreterConfigurationFields(FormInterface $form, string $configurationType): void { @@ -132,7 +132,7 @@ protected function addInterpreterConfigurationFields(FormInterface $form, string /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getSetterRegistryIdentifier(FormInterface $form, $data = null): ?string @@ -146,7 +146,7 @@ protected function getSetterRegistryIdentifier(FormInterface $form, $data = null /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * @return string|null */ protected function getInterpreterRegistryIdentifier(FormInterface $form, $data = null): ?string diff --git a/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php b/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php index fefaf60e..05409c8c 100644 --- a/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php +++ b/src/DataDefinitionsBundle/Form/Type/ImportRulesImportType.php @@ -31,10 +31,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'constraints' => [ new File([ 'mimeTypes' => [ - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' - ] - ]) - ] + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + ], + ]), + ], ]); } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php index 8c615b5f..e06c8d1a 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetUrlInterpreterType.php @@ -28,6 +28,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('path', TextType::class) ->add('deduplicate_by_url', CheckboxType::class) + ->add('deduplicate_by_hash', CheckboxType::class) + ->add('use_content_disposition', CheckboxType::class) ->add('relocate_existing_objects', CheckboxType::class) ->add('rename_existing_objects', CheckboxType::class); } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php index 03471ced..ced41619 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/AssetsUrlInterpreterType.php @@ -28,6 +28,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('path', TextType::class) ->add('deduplicate_by_url', CheckboxType::class) + ->add('deduplicate_by_hash', CheckboxType::class) + ->add('use_content_disposition', CheckboxType::class) ->add('relocate_existing_objects', CheckboxType::class) ->add('rename_existing_objects', CheckboxType::class); } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php index 08b7df33..aff2ee11 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/CarbonInterpreterType.php @@ -25,7 +25,6 @@ final class CarbonInterpreterType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('date_format', TextType::class) - ; + ->add('date_format', TextType::class); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php index 6c711399..1ff387fe 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/MoneyInterpreterType.php @@ -18,18 +18,20 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('isFloat', CheckboxType::class) ->add('currency', CurrencyChoiceType::class) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { - if (isset($value['currency']) && $value['currency'] instanceof CurrencyInterface) { - $value['currency'] = $value['currency']->getId(); - } + if (isset($value['currency']) && $value['currency'] instanceof CurrencyInterface) { + $value['currency'] = $value['currency']->getId(); + } - return $value; - } - )); + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php index 8c2fa978..1a24d4e8 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/CoreShop/StoresInterpreterType.php @@ -32,29 +32,31 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('stores', StoreChoiceType::class, [ 'multiple' => true, ]) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { - $resolvedValues = []; - - if (!is_array($value) || - !array_key_exists('stores', $value) || - !$value['stores'] instanceof ArrayCollection) { - return []; - } + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { + $resolvedValues = []; + + if (!is_array($value) || + !array_key_exists('stores', $value) || + !$value['stores'] instanceof ArrayCollection) { + return []; + } - foreach ($value['stores'] as $val) { - if ($val instanceof StoreInterface) { - $resolvedValues[] = $val->getId(); + foreach ($value['stores'] as $val) { + if ($val instanceof StoreInterface) { + $resolvedValues[] = $val->getId(); + } } - } - $value['stores'] = $resolvedValues; + $value['stores'] = $resolvedValues; - return $value; - } - )); + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php index 53de6c54..b5a3301c 100644 --- a/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/InterpreterType.php @@ -89,7 +89,7 @@ public function configureOptions(OptionsResolver $resolver): void /** * @param FormInterface $form - * @param string $configurationType + * @param string $configurationType */ protected function addConfigurationFields(FormInterface $form, string $configurationType): void { @@ -98,7 +98,7 @@ protected function addConfigurationFields(FormInterface $form, string $configura /** * @param FormInterface $form - * @param mixed $data + * @param mixed $data * * @return string|null */ diff --git a/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php b/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php new file mode 100644 index 00000000..7922be43 --- /dev/null +++ b/src/DataDefinitionsBundle/Form/Type/Interpreter/TypeCastingInterpreterType.php @@ -0,0 +1,38 @@ +add('toType', ChoiceType::class, [ + 'choices' => [ + TypeCastingInterpreter::TYPE_INT => TypeCastingInterpreter::TYPE_INT, + TypeCastingInterpreter::TYPE_FLOAT => TypeCastingInterpreter::TYPE_FLOAT, + TypeCastingInterpreter::TYPE_STRING => TypeCastingInterpreter::TYPE_STRING, + TypeCastingInterpreter::TYPE_BOOLEAN => TypeCastingInterpreter::TYPE_BOOLEAN, + ], + ]); + } +} diff --git a/src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php b/src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php new file mode 100644 index 00000000..08560172 --- /dev/null +++ b/src/DataDefinitionsBundle/Form/Type/PersisterChoiceType.php @@ -0,0 +1,31 @@ +persisters = $persisters; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'choices' => array_flip($this->persisters), + ]); + } + + public function getParent(): ?string + { + return ChoiceType::class; + } +} diff --git a/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php b/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php index 2b019a37..2782e22c 100644 --- a/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php +++ b/src/DataDefinitionsBundle/Form/Type/ProcessManager/ExportDefinitionObjectStartupForm.php @@ -28,22 +28,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('root', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('query', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('only_direct_children', CheckboxType::class, [ - 'required' => false + 'required' => false, ]) ->add('condition', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('ids', CollectionType::class, [ 'allow_add' => true, 'entry_type' => TextType::class, - 'required' => false - ]) - ; + 'required' => false, + ]); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php index 8fedb4b9..ae3db1e0 100644 --- a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StorePriceSetterType.php @@ -32,29 +32,31 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('stores', StoreChoiceType::class, [ 'multiple' => true, ]) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { - $resolvedValues = []; - - if (!is_array($value) || - !array_key_exists('stores', $value) || - !$value['stores'] instanceof ArrayCollection) { - return []; - } + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { + $resolvedValues = []; + + if (!is_array($value) || + !array_key_exists('stores', $value) || + !$value['stores'] instanceof ArrayCollection) { + return []; + } - foreach ($value['stores'] as $val) { - if ($val instanceof StoreInterface) { - $resolvedValues[] = $val->getId(); + foreach ($value['stores'] as $val) { + if ($val instanceof StoreInterface) { + $resolvedValues[] = $val->getId(); + } } - } - $value['stores'] = $resolvedValues; + $value['stores'] = $resolvedValues; - return $value; - } - )); + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php index 7d5d8938..d2cc097e 100644 --- a/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php +++ b/src/DataDefinitionsBundle/Form/Type/Setter/CoreShop/StoreValuesSetterType.php @@ -34,29 +34,31 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => true, ]) ->add('type', TextType::class) - ->addModelTransformer(new CallbackTransformer( - function ($value) { - return $value; - }, - function ($value) { - $resolvedValues = []; - - if (!is_array($value) || - !array_key_exists('stores', $value) || - !$value['stores'] instanceof ArrayCollection) { - return []; - } + ->addModelTransformer( + new CallbackTransformer( + function ($value) { + return $value; + }, + function ($value) { + $resolvedValues = []; - foreach ($value['stores'] as $val) { - if ($val instanceof StoreInterface) { - $resolvedValues[] = $val->getId(); + if (!is_array($value) || + !array_key_exists('stores', $value) || + !$value['stores'] instanceof ArrayCollection) { + return []; } - } - $value['stores'] = $resolvedValues; + foreach ($value['stores'] as $val) { + if ($val instanceof StoreInterface) { + $resolvedValues[] = $val->getId(); + } + } - return $value; - } - )); + $value['stores'] = $resolvedValues; + + return $value; + } + ) + ); } } diff --git a/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php b/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php index c4e53b9b..5f095e24 100644 --- a/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php +++ b/src/DataDefinitionsBundle/Getter/DynamicColumnGetterInterface.php @@ -16,8 +16,7 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Getter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; interface DynamicColumnGetterInterface extends GetterInterface { @@ -31,5 +30,5 @@ interface DynamicColumnGetterInterface extends GetterInterface * with other columns from the definition and to always return * exactly the same keys in exactly the same order for each object. */ - public function get(Concrete $object, ExportMapping $map, ?array $data): array; + public function get(GetterContextInterface $context): array; } diff --git a/src/DataDefinitionsBundle/Getter/GetterInterface.php b/src/DataDefinitionsBundle/Getter/GetterInterface.php index becfa52c..f086d11d 100644 --- a/src/DataDefinitionsBundle/Getter/GetterInterface.php +++ b/src/DataDefinitionsBundle/Getter/GetterInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Getter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; interface GetterInterface { - public function get(Concrete $object, ExportMapping $map, ?array $data); + public function get(GetterContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php b/src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php new file mode 100644 index 00000000..8a1cca58 --- /dev/null +++ b/src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php @@ -0,0 +1,26 @@ +providerRegistry = $providerRegistry; - $this->filterRegistry = $filterRegistry; - $this->runnerRegistry = $runnerRegistry; - $this->interpreterRegistry = $interpreterRegistry; - $this->setterRegistry = $setterRegistry; - $this->cleanerRegistry = $cleanerRegistry; - $this->loaderRegistry = $loaderRegistry; - $this->eventDispatcher = $eventDispatcher; - $this->logger = $logger; - $this->modelFactory = $modelFactory; - $this->expressionLanguage = $expressionLanguage; + + } + + public function doImportRowAsync(ImportDefinitionInterface $definition, array $row, array $params): void + { + if ($definition->getCreateVersion()) { + Version::enable(); + } else { + Version::disable(); + } + + $dataSet = new ArrayImportDataSet($row); + $runner = null; + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, $row, $dataSet, null); + + if ($definition->getRunner()) { + /** + * @var RunnerInterface $runner + */ + $runner = $this->runnerRegistry->get($definition->getRunner()); + } + + if ($runner instanceof ImportStartFinishRunnerInterface) { + $runner->startImport($runnerContext); + } + + $filter = null; + $filterType = $definition->getFilter(); + if ($filterType) { + /** + * @var FilterInterface $filter + */ + $filter = $this->filterRegistry->get($filterType); + } + + + $object = $this->importRow( + $definition, + $row, + $dataSet, + $params, + $filter, + $runner + ); + } + + public function doImportAsync(ImportDefinitionInterface $definition, array $params): void + { + /** @var ImportDataSetInterface|array $data */ + $data = $this->getData($definition, $params); + + foreach ($data as $row) { + $this->bus->dispatch( + new ImportRowMessage( + $definition->getId(), + $row, + $params, + ) + ); + } } public function doImport(ImportDefinitionInterface $definition, $params): array @@ -108,26 +155,45 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $filter = $this->filterRegistry->get($filterType); } + /** @var ImportDataSetInterface|array $data */ $data = $this->getData($definition, $params); - if ((\is_countable($data) || $data instanceof Countable) && \count($data) > 0) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.total', \count($data), $params); + $runner = null; + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, null, $data, null); + + if ($definition->getRunner()) { + /** + * @var RunnerInterface $runner + */ + $runner = $this->runnerRegistry->get($definition->getRunner()); + } + + + if ((\is_countable($data) || $data instanceof Countable) && ($count = \count($data)) > 0) { + $this->eventDispatcher->dispatch($definition, 'data_definitions.import.total', $count, $params); } - [$objectIds, $exceptions] = $this->runImport($definition, $params, $filter, $data); + if ($runner instanceof ImportStartFinishRunnerInterface) { + $runner->startImport($runnerContext); + } + + [$objectIds, $exceptions] = $this->runImport($definition, $params, $filter, $runner, $data); + + if ($runner instanceof ImportStartFinishRunnerInterface) { + $runner->finishImport($runnerContext); + } $cleanerType = $definition->getCleaner(); if ($cleanerType) { $cleaner = $this->cleanerRegistry->get($cleanerType); $this->logger->info(sprintf('Running Cleaner "%s"', $cleanerType)); - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - sprintf('Running Cleaner "%s"', $cleanerType)); - - if ($cleaner instanceof DataSetAwareInterface) { - $cleaner->setDataSet($data); - } + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + sprintf('Running Cleaner "%s"', $cleanerType) + ); if ($cleaner instanceof ParamsAwareInterface) { $cleaner->setParams($params); @@ -140,8 +206,11 @@ public function doImport(ImportDefinitionInterface $definition, $params): array $cleaner->cleanup($definition, $objectIds); $this->logger->info(sprintf('Finished Cleaner "%s"', $cleanerType)); - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - sprintf('Finished Cleaner "%s"', $cleanerType)); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + sprintf('Finished Cleaner "%s"', $cleanerType) + ); } if (count($exceptions) > 0) { @@ -157,12 +226,25 @@ public function doImport(ImportDefinitionInterface $definition, $params): array public function processSuccessfullImport(ImportDefinitionInterface $definition, $params, $objectIds, $exceptions) { - $this->sendDocument($definition, Document::getById($definition->getSuccessNotificationDocument()), $objectIds, $exceptions); + if (!is_int($definition->getSuccessNotificationDocument())) { + return; + } + + $this->sendDocument( + $definition, + Document::getById($definition->getSuccessNotificationDocument()), + $objectIds, + $exceptions + ); $this->eventDispatcher->dispatch($definition, 'data_definitions.import.success', $params); } public function processFailedImport(ImportDefinitionInterface $definition, $params, $objectIds, $exceptions) { + if (!is_int($definition->getFailureNotificationDocument())) { + return; + } + $this->sendDocument( $definition, Document::getById($definition->getFailureNotificationDocument()), @@ -172,7 +254,7 @@ public function processFailedImport(ImportDefinitionInterface $definition, $para $this->eventDispatcher->dispatch($definition, 'data_definitions.import.failure', $params); } - public function stop() : void + public function stop(): void { $this->shouldStop = true; } @@ -182,8 +264,7 @@ private function sendDocument( ?Document $document, array $objectIds, array $exceptions - ) - { + ) { if ($document instanceof Document) { $params = [ 'exceptions' => $exceptions, @@ -217,15 +298,15 @@ private function runImport( ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null, - ImportDataSetInterface $dataSet = null - ): array - { + RunnerInterface $runner = null, + ImportDataSetInterface $dataSet = null, + ): array { if (null === $dataSet) { $dataSet = new ImportDataSet(new \EmptyIterator()); } $count = 0; - $countToClean = 1000; + $countToClean = 50; $objectIds = []; $exceptions = []; @@ -235,38 +316,57 @@ private function runImport( } try { - $object = $this->importRow($definition, $row, $dataSet, array_merge($params, ['row' => $count]), $filter); + $object = $this->importRow( + $definition, + $row, + $dataSet, + array_merge($params, ['row' => $count]), + $filter, + $runner + ); if ($object instanceof Concrete) { $objectIds[] = $object->getId(); } - - if (($count + 1) % $countToClean === 0) { - Pimcore::collectGarbage(); - $this->logger->info('Clean Garbage'); - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Collect Garbage', - $params); - } - - $count++; } catch (Throwable $ex) { $this->logger->error($ex); $exceptions[] = $ex; - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - sprintf('Error: %s', $ex->getMessage()), $params); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.failure', + sprintf('Error: %s', $ex->getMessage()), + $params + ); if ($definition->getStopOnException()) { throw $ex; } + } finally { + if (($count + 1) % $countToClean === 0) { + Pimcore::collectGarbage(); + $this->logger->info('Clean Garbage'); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Collect Garbage', + $params + ); + } + + $count++; } $this->eventDispatcher->dispatch($definition, 'data_definitions.import.progress', '', $params); if ($this->shouldStop) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', - 'Process has been stopped.'); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Process has been stopped.' + ); + return [$objectIds, $exceptions]; } } @@ -279,38 +379,49 @@ private function importRow( array $data, ImportDataSetInterface $dataSet, array $params, - FilterInterface $filter = null - ): ?Concrete - { - $runner = null; - - $object = $this->getObject($definition, $data, $params); + FilterInterface $filter = null, + RunnerInterface $runner = null, + ): ?Concrete { + $object = $this->getObject($definition, $data, $dataSet, $params); if (null !== $object && !$object->getId()) { if ($definition->getSkipNewObjects()) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Ignoring new Object', - $params); + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Ignoring new Object', + $params + ); return null; } - } else if ($definition->getSkipExistingObjects()) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Ignoring existing Object', - $params); + } else { + if ($definition->getSkipExistingObjects()) { + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Ignoring existing Object', + $params + ); - return null; + return null; + } } if ($filter instanceof FilterInterface) { - if ($filter instanceof DataSetAwareInterface) { - $filter->setDataSet($dataSet); - } - if ($filter instanceof LoggerAwareInterface) { $filter->setLogger($this->logger); } - if (!$filter->filter($definition, $data, $object)) { - $this->eventDispatcher->dispatch($definition, 'data_definitions.import.status', 'Filtered Object', $params); + $context = $this->contextFactory->createFilterContext($definition, $params, $data, $dataSet, $object); + + if (!$filter->filter($context)) { + $this->eventDispatcher->dispatch( + $definition, + 'data_definitions.import.status', + 'Filtered Object', + $params + ); return null; } @@ -329,21 +440,14 @@ private function importRow( $params ); - if ($definition->getRunner()) { - $runner = $this->runnerRegistry->get($definition->getRunner()); - } - + $runnerContext = $this->contextFactory->createRunnerContext($definition, $params, $data, $dataSet, $object); if ($runner instanceof RunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } - $runner->preRun($object, $data, $definition, $params); + $runner->preRun($runnerContext); } $this->logger->info(sprintf('Imported Object: %s', $object->getRealFullPath())); @@ -360,21 +464,20 @@ private function importRow( $shouldSave = true; if ($runner instanceof SaveRunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } - $shouldSave = $runner->shouldSaveObject($object, $data, $definition, $params); + $shouldSave = $runner->shouldSaveObject($runnerContext); } if ($shouldSave) { + $params['versionNote'] = sprintf('%s - %s', $definition->getId(), $definition->getName()); + $object->setUserModification($params['userId'] ?? 0); - $object->setOmitMandatoryCheck($definition->getOmitMandatoryCheck()); - $object->save(); + $object->setOmitMandatoryCheck($definition->getOmitMandatoryCheck() ?: false); + + $this->saveObject($object, $definition, $params); $this->eventDispatcher->dispatch( $definition, @@ -405,15 +508,11 @@ private function importRow( ); if ($runner instanceof RunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } - $runner->postRun($object, $data, $definition, $params); + $runner->postRun($runnerContext); } return $object; @@ -433,8 +532,8 @@ private function setObjectValue( try { $interpreter = $this->interpreterRegistry->get($map->getInterpreter()); - if ($interpreter instanceof DataSetAwareInterface) { - $interpreter->setDataSet($dataSet); + if (!$interpreter instanceof InterpreterInterface) { + return; } if ($interpreter instanceof LoggerAwareInterface) { @@ -442,18 +541,25 @@ private function setObjectValue( } try { - $value = $interpreter->interpret( - $object, - $value, - $map, - $data, + $context = $this->contextFactory->createInterpreterContext( $definition, $params, - $map->getInterpreterConfig() ?? [] + $map->getInterpreterConfig() ?? [], + $data, + $dataSet, + $object, + $value, + $map + ); + $value = $interpreter->interpret($context); + } catch (UnexpectedValueException $ex) { + $this->logger->info( + sprintf( + 'Unexpected Value from Interpreter "%s" with message "%s"', + $map->getInterpreter(), + $ex->getMessage() + ) ); - } - catch (UnexpectedValueException $ex) { - $this->logger->info(sprintf('Unexpected Value from Interpreter "%s" with message "%s"', $map->getInterpreter(), $ex->getMessage())); } } catch (DoNotSetException $ex) { @@ -469,10 +575,6 @@ private function setObjectValue( $shouldSetField = true; if ($runner instanceof SetterRunnerInterface) { - if ($runner instanceof DataSetAwareInterface) { - $runner->setDataSet($dataSet); - } - if ($runner instanceof LoggerAwareInterface) { $runner->setLogger($this->logger); } @@ -486,25 +588,34 @@ private function setObjectValue( if ($map->getSetter()) { $setter = $this->setterRegistry->get($map->getSetter()); + $setterContext = $this->contextFactory->createSetterContext( + $definition, + $params, + $object, + $map, + $data, + $dataSet, + $value + ); if ($setter instanceof SetterInterface) { - if ($setter instanceof DataSetAwareInterface) { - $setter->setDataSet($dataSet); - } - if ($setter instanceof LoggerAwareInterface) { $setter->setLogger($this->logger); } - $setter->set($object, $value, $map, $data); + $setter->set($setterContext); } } else { $object->setValue($map->getToColumn(), $value); } } - private function getObject(ImportDefinitionInterface $definition, $data, $params): Concrete - { + private function getObject( + ImportDefinitionInterface $definition, + $data, + ImportDataSetInterface $dataSet, + $params + ): Concrete { $class = $definition->getClass(); $classObject = '\Pimcore\Model\DataObject\\'.ucfirst($class); $classDefinition = ClassDefinition::getByName($class); @@ -521,8 +632,8 @@ private function getObject(ImportDefinitionInterface $definition, $data, $params } else { $loader = $this->loaderRegistry->get('primary_key'); } - - $obj = $loader->load($class, $data, $definition, $params); + $loaderContext = $this->contextFactory->createLoaderContext($definition, $params, $data, $dataSet, $class); + $obj = $loader->load($loaderContext); if (null === $obj) { $classImplementation = $this->modelFactory->getClassNameFor($classObject) ?? $classObject; @@ -552,7 +663,7 @@ private function getObject(ImportDefinitionInterface $definition, $data, $params return $obj; } -private function createPath(ImportDefinitionInterface $definition, array $data): string + private function createPath(ImportDefinitionInterface $definition, array $data): string { if (!$definition->getObjectPath()) { return ''; @@ -577,4 +688,23 @@ private function createKey(ImportDefinitionInterface $definition, array $data): return $definition->getKey(); } + + private function saveObject(Concrete $object, ImportDefinitionInterface $definition, array $params): void + { + $persister = null; + + if ($definition->getPersister()) { + $persister = $this->persisterRegistry->get($definition->getPersister()); + } + + if (!$persister instanceof PersisterInterface) { + $persister = $this->persisterRegistry->get('persister'); + } + + if ($persister instanceof LoggerAwareInterface) { + $persister->setLogger($this->logger); + } + + $persister->persist($object, $definition, $params); + } } diff --git a/src/DataDefinitionsBundle/Installer.php b/src/DataDefinitionsBundle/Installer.php index 0f316a60..6585c3c2 100644 --- a/src/DataDefinitionsBundle/Installer.php +++ b/src/DataDefinitionsBundle/Installer.php @@ -18,7 +18,6 @@ use Pimcore; use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller; -use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; class Installer extends SettingsStoreAwareInstaller diff --git a/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php index c2863646..b1271b9a 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetByPathInterpreter.php @@ -17,22 +17,13 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Pimcore\Model\Asset; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class AssetByPathInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $assetFullPath = $configuration['path'] . '/' . $value; + public function interpret(InterpreterContextInterface $context): mixed + { + $assetFullPath = $context->getConfiguration()['path'].'/'.$context->getValue(); return Asset::getByPath($assetFullPath); } diff --git a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php index ad1913f5..7f11653d 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetUrlInterpreter.php @@ -17,147 +17,158 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Doctrine\DBAL\Query\QueryBuilder; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\TransferException; use Pimcore\File; -use Pimcore\Http\Exception\ResponseException; use Pimcore\Model\Asset; -use Pimcore\Model\DataObject\Concrete; -use Pimcore\Tool as PimcoreTool; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; - -class AssetUrlInterpreter implements InterpreterInterface, DataSetAwareInterface -{ - use DataSetAwareTrait; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; +class AssetUrlInterpreter implements InterpreterInterface +{ protected const METADATA_ORIGIN_URL = 'origin_url'; - protected Client $httpClient; + protected const METADATA_ORIGIN_HASH = 'origin_hash'; + protected \Psr\Http\Client\ClientInterface $httpClient; + protected \Psr\Http\Message\RequestFactoryInterface $requestFactory; - public function __construct(Client $httpClient) - { + public function __construct( + \Psr\Http\Client\ClientInterface $httpClient, + \Psr\Http\Message\RequestFactoryInterface $requestFactory + ) { $this->httpClient = $httpClient; + $this->requestFactory = $requestFactory; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $path = $configuration['path']; - - if (filter_var($value, FILTER_VALIDATE_URL)) { - $asset = null; - $filename = $this->getFileName($value); - - if ($configuration['deduplicate_by_url']) { - if ($asset = $this->getDuplicatedAsset($value)) { - $filename = $asset->getFilename(); - $assetPath = $asset->getPath(); - } else { - $assetPath = $path; - } - } - else { - $assetPath = $path; - } + public function interpret(InterpreterContextInterface $context): mixed + { + $path = $context->getConfiguration()['path']; + $url = $context->getValue(); - $parent = Asset\Service::createFolderByPath($assetPath); + if (filter_var($url, FILTER_VALIDATE_URL) === false) { + throw new \InvalidArgumentException(sprintf('Provided asset URL value %1$s is not a valid URL', $url)); + } + $parent = Asset\Service::createFolderByPath($path); + $filename = $this->getFileName($url, $context->getConfiguration()['use_content_disposition'] ?? false); - if (!$asset instanceof Asset) { - // Download - $fileData = $this->getFileContents($value); + $asset = null; + if ($context->getConfiguration()['deduplicate_by_url'] ?? false) { + $asset = $this->deduplicateAssetByUrl($url); + } - if ($fileData) { - $asset = Asset::create($parent->getId(), [ - 'filename' => $filename, - 'data' => $fileData - ], false); - $asset->addMetadata(self::METADATA_ORIGIN_URL, 'input', $value); - $asset->save(); - } - } else { - $save = false; + $fileHash = null; + $fileData = null; + if ($asset === null) { + $fileData = $this->getFileContents($url); + $fileHash = md5($fileData); - if ($configuration['relocate_existing_objects'] && $asset->getParent() !== $parent) { - $asset->setParent($parent); - $save = true; - } + if ($context->getConfiguration()['deduplicate_by_hash'] ?? false) { + $asset = $this->deduplicateAssetByHash($fileHash); + } + } - if ($configuration['rename_existing_objects'] && $asset->getFilename() !== $filename) { - $asset->setFilename($filename); - $save = true; - } + if ($asset === null) { + // asset doesn't exist already + $asset = Asset::create($parent->getId(), [ + 'filename' => $filename, + 'data' => $fileData, + ], false); + } - if ($save) { - $asset->save(); - } - } + $save = false; + $currentUrl = $asset->getMetadata(self::METADATA_ORIGIN_URL) ?? ''; + if (strpos($currentUrl, $url) === false) { + $url = $currentUrl ? $currentUrl .'|'. $url : $url; + $asset->addMetadata(self::METADATA_ORIGIN_URL, 'input', $url); + $save = true; + } - return $asset; + // $fileHash might not be available here if we deduplicated by URL + if ($fileHash !== null && $asset->getMetadata(self::METADATA_ORIGIN_HASH) !== $fileHash) { + $asset->addMetadata(self::METADATA_ORIGIN_HASH, 'input', $fileHash); + $save = true; + } + if ($context->getConfiguration()['relocate_existing_objects'] ?? false && $asset->getParent() !== $parent) { + $asset->setParent($parent); + $save = true; + } + if ($context->getConfiguration()['rename_existing_objects'] ?? false && $asset->getFilename() !== $filename) { + $asset->setFilename($filename); + $save = true; } - return null; + if ($save) { + $asset->save(); + } + + return $asset; } - private function getFileName(string $url) : ?string + private function getFileName(string $url, bool $useContentDisposition = false): ?string { $filename = null; - try { - $response = $this->httpClient->request("HEAD", $url); - $headers = $response->getHeaders(); - - if ( - isset($headers["Content-Disposition"]) && - preg_match( - '/^.*?filename=(?[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m', - current($headers["Content-Disposition"]), - $match - ) - ) { - $filename = trim($match['f'], ' ";'); + if ($useContentDisposition) { + try { + $request = $this->requestFactory->createRequest('HEAD', $url); + $response = $this->httpClient->sendRequest($request); + $headers = $response->getHeaders(); + + if ( + isset($headers["Content-Disposition"]) && + preg_match( + '/^.*?filename=(?[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m', + current($headers["Content-Disposition"]), + $match + ) + ) { + $filename = trim($match['f'], ' ";'); + } + } catch (\Psr\Http\Client\ClientExceptionInterface $exception) { } - } catch (ResponseException $exception) { } - - if (!$filename) { - $filename = File::getValidFilename(basename($url)); + if ($filename === null) { + $filename = basename($url); } - return $filename; + return File::getValidFilename($filename); } - protected function getFileContents(string $value): ?string + protected function getFileContents(string $value): string { try { - $response = $this->httpClient->request('GET', $value); - } catch (TransferException $ex) { - $response = null; + $request = $this->requestFactory->createRequest('GET', $value); + $response = $this->httpClient->sendRequest($request); + } catch (\Psr\Http\Client\ClientExceptionInterface $ex) { + throw new \RuntimeException('Unable to download asset from URL '.$value); } - if ($response && $response->getStatusCode() === 200) { - return (string) $response->getBody(); + if ($response->getStatusCode() === 200) { + return (string)$response->getBody(); } - return null; + throw new \RuntimeException('Unable to download asset from URL '.$value); + } + + private function deduplicateAssetByUrl(string $value): ?Asset + { + return $this->deduplicateAsset(self::METADATA_ORIGIN_URL, $value, true); + } + + private function deduplicateAssetByHash(string $value): ?Asset + { + return $this->deduplicateAsset(self::METADATA_ORIGIN_HASH, $value); } - private function getDuplicatedAsset(string $value) : ?Asset + private function deduplicateAsset(string $name, string $value, bool $fuzzy = false) { $listing = new Asset\Listing(); $listing->onCreateQueryBuilder( function (QueryBuilder $select) { - $select->join('assets_metadata AS am', 'id = am.cid', 'cid'); + $select->join('assets', 'assets_metadata', 'am', 'id = am.cid'); } ); - $listing->addConditionParam('am.name = ?', static::METADATA_ORIGIN_URL); - $listing->addConditionParam('am.data = ?', $value); + $listing->addConditionParam('am.name = ?', $name); + if ($fuzzy) { + $listing->addConditionParam('am.data LIKE ?', '%'. $value .'%'); + } else { + $listing->addConditionParam('am.data = ?', $value); + } $listing->setLimit(1); $listing->setOrder(['creationDate', 'desc']); diff --git a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php index 763cb826..48f79ec7 100644 --- a/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/AssetsUrlInterpreter.php @@ -16,24 +16,26 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContext; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class AssetsUrlInterpreter extends AssetUrlInterpreter { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { $assets = []; - foreach ((array)$value as $item) { - $asset = parent::interpret($object, $item, $map, $data, $definition, $params, $configuration); + foreach ((array)$context->getValue() as $item) { + $childContext = new InterpreterContext( + $context->getDefinition(), + $context->getParams(), + $context->getConfiguration(), + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $item, + $context->getMapping() + ); + $asset = parent::interpret($childContext); if ($asset) { $assets[] = $asset; diff --git a/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php index f185f9f2..1f07cd58 100644 --- a/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CarbonInterpreter.php @@ -17,32 +17,19 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Carbon\Carbon; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class CarbonInterpreter implements InterpreterInterface, DataSetAwareInterface +class CarbonInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - if ($value) { - $format = $configuration['date_format']; + public function interpret(InterpreterContextInterface $context): bool|null|\Carbon\Carbon + { + if ($context->getValue()) { + $format = $context->getConfiguration()['date_format']; if (!empty($format)) { - return Carbon::createFromFormat($format, $value); + return Carbon::createFromFormat($format, $context->getValue()); } - return new Carbon($value); + return new Carbon($context->getValue()); } return null; diff --git a/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php index accce3fc..6c07d48d 100644 --- a/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CheckboxInterpreter.php @@ -16,33 +16,20 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class CheckboxInterpreter implements InterpreterInterface, DataSetAwareInterface +class CheckboxInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - if (is_string($value)) { - if ($value === "") { + public function interpret(InterpreterContextInterface $context): ?bool + { + if (is_string($context->getValue())) { + if ($context->getValue() === "") { return null; } - return filter_var(strtolower($value), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + return filter_var(strtolower($context->getValue()), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } - return ((bool)$value); + return ((bool)$context->getValue()); } } diff --git a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php index 9c39499f..6b907899 100644 --- a/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ConditionalInterpreter.php @@ -17,71 +17,62 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use CoreShop\Component\Registry\ServiceRegistryInterface; -use Pimcore\Model\DataObject\Concrete; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class ConditionalInterpreter implements InterpreterInterface, DataSetAwareInterface +class ConditionalInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - private ServiceRegistryInterface $interpreterRegistry; - protected ExpressionLanguage $expressionLanguage; - protected ContainerInterface $container; - public function __construct( - ServiceRegistryInterface $interpreterRegistry, - ExpressionLanguage $expressionLanguage, - ContainerInterface $container + protected ServiceRegistryInterface $interpreterRegistry, + protected ExpressionLanguage $expressionLanguage, + protected ContainerInterface $container, + protected ContextFactoryInterface $contextFactory ) { - $this->interpreterRegistry = $interpreterRegistry; - $this->expressionLanguage = $expressionLanguage; - $this->container = $container; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { + public function interpret(InterpreterContextInterface $context): mixed + { $params = [ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'definition' => $definition, - 'params' => $params, - 'configuration' => $configuration, + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'data_set' => $context->getDataSet(), + 'definition' => $context->getDefinition(), + 'params' => $context->getParams(), + 'configuration' => $context->getConfiguration(), 'container' => $this->container, ]; - $condition = $configuration['condition']; + $condition = $context->getConfiguration()['condition']; if ($this->expressionLanguage->evaluate($condition, $params)) { - $interpreter = $configuration['true_interpreter']; + $interpreter = $context->getConfiguration()['true_interpreter']; } else { - $interpreter = $configuration['false_interpreter']; + $interpreter = $context->getConfiguration()['false_interpreter']; } $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); if (!$interpreterObject instanceof InterpreterInterface) { - return $value; + return $context->getValue(); } - if ($interpreterObject instanceof DataSetAwareInterface) { - $interpreterObject->setDataSet($this->getDataSet()); - } + $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); + + $newContext = $this->contextFactory->createInterpreterContext( + $context->getDefinition(), + $context->getParams(), + $interpreter['interpreterConfig'], + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $context->getValue(), + $context->getMapping() + ); - return $interpreterObject->interpret($object, $value, $map, $data, $definition, $params, - $interpreter['interpreterConfig']); + return $interpreterObject->interpret($newContext); } } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php index 194336a8..bf967024 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/CurrencyInterpreter.php @@ -12,13 +12,13 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ +declare(strict_types=1); + namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; use CoreShop\Component\Currency\Repository\CurrencyRepositoryInterface; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; final class CurrencyInterpreter implements InterpreterInterface { @@ -29,16 +29,9 @@ public function __construct(CurrencyRepositoryInterface $currencyRepository) $this->currencyRepository = $currencyRepository; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - return $this->currencyRepository->getByCode($value); + public function interpret(InterpreterContextInterface $context): mixed + { + return $this->currencyRepository->getByCode($context->getValue()); } } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php index 0a544726..363df633 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/MoneyInterpreter.php @@ -1,17 +1,26 @@ currencyRepository = $currencyRepository; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $value = $this->getValue($value, $configuration); - $currency = $this->resolveCurrency($value, $configuration); + public function interpret(InterpreterContextInterface $context): mixed + { + $value = $this->getValue((string)$context->getValue(), $context); + $currency = $this->resolveCurrency((string)$value, $context); if (null === $currency) { return null; @@ -40,20 +42,14 @@ public function interpret( return new Money($value, $currency); } - - /** - * @param $value - * @param $configuration - * - * @return int - */ - private function getValue($value, $configuration) + + private function getValue(string $value, InterpreterContextInterface $context): int { - $inputIsFloat = $configuration['isFloat']; + $inputIsFloat = $context->getConfiguration()['isFloat']; $value = preg_replace("/[^0-9,.]+/", "", $value); - if (is_string($value)) { + if (\is_string($value)) { $value = str_replace(',', '.', $value); $value = (float)$value; } @@ -65,13 +61,7 @@ private function getValue($value, $configuration) return (int)$value; } - /** - * @param string $value - * @param array $configuration - * - * @return CurrencyInterface|null - */ - private function resolveCurrency($value, $configuration) + private function resolveCurrency(string $value, InterpreterContextInterface$context): ?CurrencyInterface { $currency = null; @@ -81,8 +71,8 @@ private function resolveCurrency($value, $configuration) $currency = $this->currencyRepository->getByCode($currencyCode); } - if ($currency === null && isset($configuration['currency']) && null !== $configuration['currency']) { - $currency = $this->currencyRepository->find($configuration['currency']); + if ($currency === null && isset($context->getConfiguration()['currency']) && null !== $context->getConfiguration()['currency']) { + $currency = $this->currencyRepository->find($context->getConfiguration()['currency']); } return $currency; diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php index e01d422e..8ca7b85c 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/PriceInterpreter.php @@ -12,28 +12,21 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ +declare(strict_types=1); + namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; -use function is_string; final class PriceInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $inputIsFloat = $configuration['isFloat']; - - if (is_string($value)) { + public function interpret(InterpreterContextInterface $context): mixed + { + $inputIsFloat = $context->getConfiguration()['isFloat']; + $value = $context->getValue(); + + if (\is_string($value)) { $value = str_replace(',', '.', $value); $value = (float)$value; } diff --git a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php index 0317b760..3615a72f 100644 --- a/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/CoreShop/StoresInterpreter.php @@ -12,25 +12,18 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ +declare(strict_types=1); + namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; final class StoresInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - return $configuration['stores']; + public function interpret(InterpreterContextInterface $context): mixed + { + return $context->getConfiguration()['stores']; } } diff --git a/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php index 4bda73e2..0d4a4a20 100644 --- a/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DefaultValueInterpreter.php @@ -16,25 +16,12 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class DefaultValueInterpreter implements InterpreterInterface, DataSetAwareInterface +class DefaultValueInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - return $configuration['value']; + public function interpret(InterpreterContextInterface $context): mixed + { + return $context->getConfiguration()['value']; } } diff --git a/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php index 374ec9b2..09bf4536 100644 --- a/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DefinitionInterpreter.php @@ -18,11 +18,9 @@ use CoreShop\Component\Resource\Repository\RepositoryInterface; use Pimcore\Model\DataObject; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class DefinitionInterpreter implements InterpreterInterface { @@ -35,22 +33,14 @@ public function __construct(RepositoryInterface $definitionRepository, ImporterI $this->importer = $importer; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $subDefinition = $this->definitionRepository->find($configuration['definition']); + public function interpret(InterpreterContextInterface $context): mixed { + $subDefinition = $this->definitionRepository->find($context->getConfiguration()['definition']); if (!$subDefinition instanceof ImportDefinitionInterface) { return null; } - $imported = $this->importer->doImport($subDefinition, ['data' => [$data], 'child' => true]); + $imported = $this->importer->doImport($subDefinition, ['data' => [$context->getDataRow()], 'child' => true]); if (count($imported) === 1) { return DataObject::getById($imported[0]); diff --git a/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php b/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php index 5f744ab6..ed32d7fb 100644 --- a/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/DoNotSetOnEmptyInterpreter.php @@ -16,34 +16,21 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; -class DoNotSetOnEmptyInterpreter implements InterpreterInterface, DataSetAwareInterface +class DoNotSetOnEmptyInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - if ($value === "" || $value === null) { + public function interpret(InterpreterContextInterface $context): mixed + { + if ($context->getValue() === "" || $context->getValue() === null) { throw new DoNotSetException(); } - if (is_array($value) && count($value) === 0) { + if (is_array($context->getValue()) && count($context->getValue()) === 0) { throw new DoNotSetException(); } - return $value; + return $context->getValue(); } } diff --git a/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php index a2dc158d..cb6de4d6 100644 --- a/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ExpressionInterpreter.php @@ -16,20 +16,14 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Throwable; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Exception\InterpreterException; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; -class ExpressionInterpreter implements InterpreterInterface, DataSetAwareInterface +class ExpressionInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - protected ExpressionLanguage $expressionLanguage; protected ContainerInterface $container; @@ -39,30 +33,29 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt $this->container = $container; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $expression = $configuration['expression']; + public function interpret(InterpreterContextInterface $context): mixed { + $expression = $context->getConfiguration()['expression']; try { return $this->expressionLanguage->evaluate($expression, [ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'definition' => $definition, - 'params' => $params, - 'configuration' => $configuration, + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'data_set' => $context->getDataSet(), + 'definition' => $context->getDefinition(), + 'params' => $context->getParams(), + 'configuration' => $context->getConfiguration(), 'container' => $this->container, ]); } catch (Throwable $exception) { - throw InterpreterException::fromInterpreter($definition, $map, $params, $value, $exception); + throw InterpreterException::fromInterpreter( + $context->getDefinition(), + $context->getMapping(), + $context->getParams(), + $context->getValue(), + $exception + ); } } } diff --git a/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php index 0a3fe42e..1156fa91 100644 --- a/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ExternalImageInterpreter.php @@ -16,30 +16,25 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\ExternalImage; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class ExternalImageInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - if (($definition instanceof ExportDefinitionInterface) && $value instanceof ExternalImage) { - return $value->getUrl(); + public function interpret(InterpreterContextInterface $context): mixed + { + if (($context->getDefinition() instanceof ExportDefinitionInterface) && $context->getValue( + ) instanceof ExternalImage) { + return $context->getValue()->getUrl(); } - if (($definition instanceof ImportDefinitionInterface) && filter_var($value, FILTER_VALIDATE_URL)) { - return new ExternalImage($value); + if (($context->getDefinition() instanceof ImportDefinitionInterface) && filter_var( + $context->getValue(), + FILTER_VALIDATE_URL + )) { + return new ExternalImage($context->getValue()); } return null; diff --git a/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php b/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php index 3ee42ab1..0dd719e7 100644 --- a/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/HrefInterpreter.php @@ -19,28 +19,16 @@ use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\Element\Service; use Pimcore\Tool; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class HrefInterpreter implements InterpreterInterface, DataSetAwareInterface +class HrefInterpreter implements InterpreterInterface { - use DataSetAwareTrait; + public function interpret(InterpreterContextInterface $context): mixed + { + $type = $context->getConfiguration()['type'] ?: 'object'; + $objectClass = $context->getConfiguration()['class']; - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $type = $configuration['type'] ?: 'object'; - $objectClass = $configuration['class']; - - if (!$value) { + if (!$context->getValue()) { return null; } @@ -55,7 +43,7 @@ public function interpret( $class = new $class(); if ($class instanceof Concrete) { - $ret = $class::getById($value); + $ret = $class::getById($context->getValue()); if ($ret instanceof Concrete) { return $ret; @@ -63,7 +51,7 @@ public function interpret( } } } else { - return Service::getElementById($type, $value); + return Service::getElementById($type, $context->getValue()); } return null; diff --git a/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php index 49732f55..5b9f4d7b 100644 --- a/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ImportRuleInterpreter.php @@ -16,44 +16,29 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use CoreShop\Component\Rule\Condition\RuleValidationProcessorInterface; use CoreShop\Component\Rule\Model\Action; use CoreShop\Component\Rule\Model\Condition; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Rules\Model\ImportRule; use Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface; use Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface; -class ImportRuleInterpreter implements InterpreterInterface, DataSetAwareInterface +class ImportRuleInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - protected RuleApplierInterface $ruleProcessor; protected ImportRuleValidationProcessorInterface $ruleValidationProcessor; public function __construct( ImportRuleValidationProcessorInterface $ruleValidationProcessor, RuleApplierInterface $ruleProcessor - ) - { + ) { $this->ruleValidationProcessor = $ruleValidationProcessor; $this->ruleProcessor = $ruleProcessor; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $rules = $configuration['rules']; + public function interpret(InterpreterContextInterface $context): mixed + { + $rules = $context->getConfiguration()['rules']; $ruleObjects = []; foreach ($rules as $rule) { @@ -81,19 +66,26 @@ public function interpret( } $params = [ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'params' => $params, - 'dataSet' => $this->getDataSet() + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'params' => $context->getParams(), + 'data_set' => $context->getDataSet(), ]; + $value = $context->getValue(); + foreach ($ruleObjects as $rule) { - if ($this->ruleValidationProcessor->isImportRuleValid($definition, $object, $rule, $params)) { + if ($this->ruleValidationProcessor->isImportRuleValid( + $context->getDefinition(), + $context->getObject(), + $rule, + $params + )) { $value = $this->ruleProcessor->applyRule( $rule, - $object, + $context->getObject(), $value, $params ); diff --git a/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php b/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php index 75a7310c..72e37ba5 100644 --- a/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php +++ b/src/DataDefinitionsBundle/Interpreter/InterpreterInterface.php @@ -16,20 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Exception\DoNotSetException; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; interface InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ); + public function interpret(InterpreterContextInterface $context): mixed; } diff --git a/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php b/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php index 2a8d795a..e928fdfb 100644 --- a/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/IteratorInterpreter.php @@ -17,50 +17,46 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use CoreShop\Component\Registry\ServiceRegistryInterface; -use Pimcore\Model\DataObject\Concrete; use Webmozart\Assert\Assert; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -final class IteratorInterpreter implements InterpreterInterface, DataSetAwareInterface +final class IteratorInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - private ServiceRegistryInterface $interpreterRegistry; - - public function __construct(ServiceRegistryInterface $interpreterRegistry) - { - $this->interpreterRegistry = $interpreterRegistry; + public function __construct( + private ServiceRegistryInterface $interpreterRegistry, + private ContextFactoryInterface $contextFactory + ) { } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - if (null === $value) { + public function interpret(InterpreterContextInterface $context): mixed + { + if (null === $context->getValue()) { return []; } - Assert::isArray($value, 'IteratorInterpreter can only be used with array values'); + Assert::isArray($context->getValue(), 'IteratorInterpreter can only be used with array values'); - $interpreter = $configuration['interpreter']; + $interpreter = $context->getConfiguration()['interpreter']; $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); - if ($interpreterObject instanceof DataSetAwareInterface) { - $interpreterObject->setDataSet($this->getDataSet()); - } - - foreach ($value as &$val) { - $val = $interpreterObject->interpret($object, $val, $map, $data, $definition, $params, - $interpreter['interpreterConfig']); + $value = $context->getValue(); + $result = []; + + foreach ($value as $val) { + $context = $this->contextFactory->createInterpreterContext( + $context->getDefinition(), + $context->getParams(), + $interpreter['interpreterConfig'], + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $val, + $context->getMapping() + ); + + $result[] = $interpreterObject->interpret($context); } - return $value; + return $result; } } diff --git a/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php b/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php index 31fd6068..933b4816 100644 --- a/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/LinkInterpreter.php @@ -16,40 +16,31 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\Link; use Pimcore\Model\Element\ElementInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class LinkInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - if (($definition instanceof ExportDefinitionInterface) && $value instanceof Link) { - return $value->getHref(); + public function interpret(InterpreterContextInterface $context): mixed + { + if (($context->getDefinition() instanceof ExportDefinitionInterface) && $context->getValue() instanceof Link) { + return $context->getValue()->getHref(); } - if (($definition instanceof ImportDefinitionInterface)) { + if (($context->getDefinition() instanceof ImportDefinitionInterface)) { $link = new Link(); - if (filter_var($value, FILTER_VALIDATE_URL)) { - $link->setDirect($value); + if (filter_var($context->getValue(), FILTER_VALIDATE_URL)) { + $link->setDirect($context->getValue()); } - $link->setText($value); + $link->setText($context->getValue()); - if ($value instanceof ElementInterface) { - $link->setElement($value); + if ($context->getValue() instanceof ElementInterface) { + $link->setElement($context->getValue()); } return $link; diff --git a/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php index fd9b7e29..9cd7a39f 100644 --- a/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MappingInterpreter.php @@ -16,26 +16,13 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class MappingInterpreter implements InterpreterInterface, DataSetAwareInterface +class MappingInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $interpreterMap = $configuration['mapping']; + public function interpret(InterpreterContextInterface $context): mixed + { + $interpreterMap = $context->getConfiguration()['mapping']; $resolvedMap = []; if (!is_array($interpreterMap)) { @@ -46,14 +33,14 @@ public function interpret( $resolvedMap[$itemMap['from']] = $itemMap['to']; } - if (array_key_exists($value, $resolvedMap)) { - return $resolvedMap[$value]; + if (array_key_exists($context->getValue(), $resolvedMap)) { + return $resolvedMap[$context->getValue()]; } - if ($configuration['return_null_when_not_found']) { + if ($context->getConfiguration()['return_null_when_not_found']) { return null; } - return $value; + return $context->getValue(); } } diff --git a/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php index da7ed6c3..1c53100a 100644 --- a/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MetadataInterpreter.php @@ -16,36 +16,27 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; use Pimcore\Model\DataObject\Data\ElementMetadata; use Pimcore\Model\DataObject\Data\ObjectMetadata; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class MetadataInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $class = "\\Pimcore\\Model\\DataObject\\Data\\" . $configuration['class']; - $fieldname = $map->getToColumn(); + public function interpret(InterpreterContextInterface $context): mixed + { + $class = "\\Pimcore\\Model\\DataObject\\Data\\".$context->getConfiguration()['class']; + $fieldname = $context->getMapping()->getToColumn(); - $metadata = $configuration['metadata']; - $metadata = json_decode($metadata, true); + $metadata = $context->getConfiguration()['metadata']; + $metadata = json_decode($metadata, true, 512, JSON_THROW_ON_ERROR); if (!is_array($metadata)) { $metadata = []; } /** @var ElementMetadata|ObjectMetadata $elementMetadata */ - $elementMetadata = new $class($fieldname, array_keys($metadata), $value); + $elementMetadata = new $class($fieldname, array_keys($metadata), $context->getValue()); foreach ($metadata as $metadataKey => $metadataValue) { - $setter = 'set' . ucfirst($metadataKey); + $setter = 'set'.ucfirst($metadataKey); $elementMetadata->$setter($metadataValue); } diff --git a/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php b/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php index e7dc5353..68bae641 100644 --- a/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/MultiHrefInterpreter.php @@ -18,25 +18,13 @@ use Pimcore\Model\DataObject\Concrete; use Pimcore\Tool; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class MultiHrefInterpreter implements InterpreterInterface, DataSetAwareInterface +class MultiHrefInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $objectClass = $configuration['class']; + public function interpret(InterpreterContextInterface $context): mixed + { + $objectClass = $context->getConfiguration()['class']; $class = 'Pimcore\Model\DataObject\\'.ucfirst($objectClass); @@ -44,7 +32,7 @@ public function interpret( $class = new $class(); if ($class instanceof Concrete) { - $ret = $class::getById($value); + $ret = $class::getById($context->getValue()); if ($ret instanceof Concrete) { return [$ret]; @@ -52,6 +40,6 @@ public function interpret( } } - return $value; + return $context->getValue(); } } diff --git a/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php b/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php index 769c38d8..8ba7bea4 100644 --- a/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/NestedInterpreter.php @@ -17,45 +17,39 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use CoreShop\Component\Registry\ServiceRegistryInterface; -use Pimcore\Model\DataObject\Concrete; use Webmozart\Assert\Assert; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -final class NestedInterpreter implements InterpreterInterface, DataSetAwareInterface +final class NestedInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - private ServiceRegistryInterface $interpreterRegistry; + public function __construct( + private ServiceRegistryInterface $interpreterRegistry, + private ContextFactoryInterface $contextFactory + ) { + } - public function __construct(ServiceRegistryInterface $interpreterRegistry) + public function interpret(InterpreterContextInterface $context): mixed { - $this->interpreterRegistry = $interpreterRegistry; - } + Assert::keyExists($context->getConfiguration(), 'interpreters'); + Assert::isArray($context->getConfiguration()['interpreters'], 'Interpreter Config needs to be array'); - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - Assert::keyExists($configuration, 'interpreters'); - Assert::isArray($configuration['interpreters'], 'Interpreter Config needs to be array'); + $value = $context->getValue(); - foreach ($configuration['interpreters'] as $interpreter) { + foreach ($context->getConfiguration()['interpreters'] as $interpreter) { $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); - - if ($interpreterObject instanceof DataSetAwareInterface) { - $interpreterObject->setDataSet($this->getDataSet()); - } - - $value = $interpreterObject->interpret($object, $value, $map, $data, $definition, $params, - $interpreter['interpreterConfig']); + $newContext = $this->contextFactory->createInterpreterContext( + $context->getDefinition(), + $context->getParams(), + $interpreter['interpreterConfig'], + $context->getDataRow(), + $context->getDataSet(), + $context->getObject(), + $value, + $context->getMapping() + ); + + $value = $interpreterObject->interpret($newContext); } return $value; diff --git a/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php b/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php index bf56ec7d..d2cb8b6e 100644 --- a/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/ObjectResolverInterpreter.php @@ -16,34 +16,25 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Listing; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class ObjectResolverInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - $data, - DataDefinitionInterface $definition, - $params, - $configuration - ) { - if (!$value) { + public function interpret(InterpreterContextInterface $context): mixed + { + if (!$context->getValue()) { return null; } - $class = 'Pimcore\Model\DataObject\\'.ucfirst($configuration['class']); - $lookup = 'getBy'.ucfirst($configuration['field']); + $class = 'Pimcore\Model\DataObject\\'.ucfirst($context->getConfiguration()['class']); + $lookup = 'getBy'.ucfirst($context->getConfiguration()['field']); /** * @var Listing $listing */ - $listing = $class::$lookup($value); - $listing->setUnpublished($configuration['match_unpublished']); + $listing = $class::$lookup($context->getValue()); + $listing->setUnpublished($context->getConfiguration()['match_unpublished']); if ($listing->count() === 1) { return $listing->current(); diff --git a/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php b/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php index 1d4a73de..686e46d6 100644 --- a/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/QuantityValueInterpreter.php @@ -16,28 +16,15 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\QuantityValue; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class QuantityValueInterpreter implements InterpreterInterface, DataSetAwareInterface +class QuantityValueInterpreter implements InterpreterInterface { - use DataSetAwareTrait; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $value = $value !== '' ? $value : null; - $unit = $configuration['unit']; + public function interpret(InterpreterContextInterface $context): mixed + { + $value = $context->getValue() !== '' ? $context->getValue() : null; + $unit = $context->getConfiguration()['unit']; return new QuantityValue($value, $unit); } diff --git a/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php b/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php index 355f5b9e..ad3604d4 100644 --- a/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/SpecificObjectInterpreter.php @@ -17,22 +17,13 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use Pimcore\Model\DataObject; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class SpecificObjectInterpreter implements InterpreterInterface { - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $objectId = $configuration['objectId']; + public function interpret(InterpreterContextInterface $context): mixed + { + $objectId = $context->getConfiguration()['objectId']; return DataObject::getById($objectId); } diff --git a/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php index 00b87eed..ac9c5058 100644 --- a/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TwigInterpreter.php @@ -16,10 +16,8 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; -use Pimcore\Model\DataObject\Concrete; use Twig\Environment; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; class TwigInterpreter implements InterpreterInterface { @@ -30,23 +28,17 @@ public function __construct(Environment $twig) $this->twig = $twig; } - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - return $this->twig->createTemplate($configuration['template'])->render([ - 'value' => $value, - 'object' => $object, - 'map' => $map, - 'data' => $data, - 'definition' => $definition, - 'params' => $params, - 'configuration' => $configuration, + public function interpret(InterpreterContextInterface $context): mixed + { + return $this->twig->createTemplate($context->getConfiguration()['template'])->render([ + 'value' => $context->getValue(), + 'object' => $context->getObject(), + 'map' => $context->getMapping(), + 'data' => $context->getDataRow(), + 'data_set' => $context->getDataSet(), + 'definition' => $context->getDefinition(), + 'params' => $context->getParams(), + 'configuration' => $context->getConfiguration(), ]); } } diff --git a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php index 628a7ee7..94840c79 100644 --- a/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php +++ b/src/DataDefinitionsBundle/Interpreter/TypeCastingInterpreter.php @@ -17,38 +17,28 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Interpreter; use InvalidArgumentException; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataSetAwareTrait; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\InterpreterContextInterface; -class TypeCastingInterpreter implements InterpreterInterface, DataSetAwareInterface +class TypeCastingInterpreter implements InterpreterInterface { - use DataSetAwareTrait; + public const TYPE_INT = 'int'; + public const TYPE_FLOAT = 'float'; + public const TYPE_STRING = 'string'; + public const TYPE_BOOLEAN = 'boolean'; - protected const TYPE_INT = 'int'; - protected const TYPE_STRING = 'string'; - protected const TYPE_BOOLEAN = 'boolean'; - - public function interpret( - Concrete $object, - $value, - MappingInterface $map, - array $data, - DataDefinitionInterface $definition, - array $params, - array $configuration - ) { - $type = $configuration['toType']; + public function interpret(InterpreterContextInterface $context): mixed + { + $type = $context->getConfiguration()['toType']; switch ($type) { case static::TYPE_INT: - return (int)$value; + return (int)$context->getValue(); + case static::TYPE_FLOAT: + return (float)$context->getValue(); case static::TYPE_STRING: - return (string)$value; + return (string)$context->getValue(); case static::TYPE_BOOLEAN: - return (boolean)$value; + return (boolean)$context->getValue(); } throw new InvalidArgumentException(sprintf('Not valid type cast given, given %s', $type)); diff --git a/src/DataDefinitionsBundle/Loader/LoaderInterface.php b/src/DataDefinitionsBundle/Loader/LoaderInterface.php index 962a9a4a..be0d92f6 100644 --- a/src/DataDefinitionsBundle/Loader/LoaderInterface.php +++ b/src/DataDefinitionsBundle/Loader/LoaderInterface.php @@ -17,9 +17,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Loader; use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\LoaderContextInterface; interface LoaderInterface { - public function load(string $class, array $data, ImportDefinitionInterface $definition, array $params): ?Concrete; + public function load(LoaderContextInterface $context): ?Concrete; } diff --git a/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php b/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php index 8c76689d..5f1aec88 100644 --- a/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php +++ b/src/DataDefinitionsBundle/Loader/PrimaryKeyLoader.php @@ -20,17 +20,16 @@ use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Listing; -use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\LoaderContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use function count; class PrimaryKeyLoader implements LoaderInterface { - public function load(string $class, array $data, ImportDefinitionInterface $definition, array $params): ?Concrete + public function load(LoaderContextInterface $context): ?Concrete { - $classObject = '\Pimcore\Model\DataObject\\'.ucfirst($class); - $classList = '\Pimcore\Model\DataObject\\'.ucfirst($class).'\Listing'; + $classObject = '\Pimcore\Model\DataObject\\'.ucfirst($context->getClass()); + $classList = '\Pimcore\Model\DataObject\\'.ucfirst($context->getClass()).'\Listing'; $list = new $classList(); @@ -38,13 +37,13 @@ public function load(string $class, array $data, ImportDefinitionInterface $defi /** * @var ImportMapping[] $mapping */ - $mapping = $definition->getMapping(); + $mapping = $context->getDefinition()->getMapping(); $condition = []; $conditionValues = []; foreach ($mapping as $map) { if ($map->getPrimaryIdentifier()) { $condition[] = '`'.$map->getToColumn().'` = ?'; - $conditionValues[] = $data[$map->getFromColumn()]; + $conditionValues[] = $context->getDataRow()[$map->getFromColumn()]; } } @@ -69,7 +68,7 @@ public function load(string $class, array $data, ImportDefinitionInterface $defi if (count($objectData) === 1) { $obj = $objectData[0]; - if ($definition->getForceLoadObject()) { + if ($context->getDefinition()->getForceLoadObject()) { $obj = DataObject::getById($obj->getId(), true); if (!$obj instanceof $classObject) { diff --git a/src/DataDefinitionsBundle/Messenger/ImportRowMessage.php b/src/DataDefinitionsBundle/Messenger/ImportRowMessage.php new file mode 100644 index 00000000..e821d42a --- /dev/null +++ b/src/DataDefinitionsBundle/Messenger/ImportRowMessage.php @@ -0,0 +1,46 @@ +definitionId = $definitionId; + $this->data = $data; + $this->params = $params; + } + + public function getDefinitionId(): int + { + return $this->definitionId; + } + + public function getData(): array + { + return $this->data; + } + + public function getParams(): array + { + return $this->params; + } +} diff --git a/src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php b/src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php new file mode 100644 index 00000000..12d8baeb --- /dev/null +++ b/src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php @@ -0,0 +1,44 @@ +getDefinitionId()); + + if (!$definition) { + throw new \InvalidArgumentException('Invalid definition id'); + } + + $this->importer->doImportRowAsync( + $definition, + $message->getData(), + $message->getParams(), + ); + } +} diff --git a/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php b/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php index c55dbb31..b534767d 100644 --- a/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php +++ b/src/DataDefinitionsBundle/Model/AbstractDataDefinition.php @@ -18,10 +18,16 @@ use Pimcore\Model\AbstractModel; +/** + * @method bool isWriteable() + * @method string getWriteTarget() + * @method void save() + * @method void delete() + */ abstract class AbstractDataDefinition extends AbstractModel implements DataDefinitionInterface { /** - * @var int + * @var int|string|null */ public $id; @@ -80,7 +86,7 @@ abstract class AbstractDataDefinition extends AbstractModel implements DataDefin */ public $successNotificationDocument; - public function getId() + public function getId(): int|string|null { return $this->id; } @@ -128,6 +134,8 @@ public function getName() public function setName($name) { $this->name = $name; + + $this->setId($name); } public function getMapping() diff --git a/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php b/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php index addc6fe6..429ba971 100644 --- a/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php +++ b/src/DataDefinitionsBundle/Model/DataDefinitionInterface.php @@ -20,10 +20,6 @@ interface DataDefinitionInterface extends ResourceInterface { - /** - * @return mixed - */ - public function getId(); /** * @param int $id diff --git a/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php b/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php index 139a5a5a..930f2e10 100644 --- a/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php +++ b/src/DataDefinitionsBundle/Model/DataSetAwareTrait.php @@ -20,14 +20,14 @@ trait DataSetAwareTrait { - protected ImportDataSetInterface $dataSet; + protected ?ImportDataSetInterface $dataSet = null; - public function getDataSet(): ImportDataSetInterface + public function getDataSet(): ?ImportDataSetInterface { - return $this->dataSet; + return $this->dataSet ?? null; } - public function setDataSet(ImportDataSetInterface $dataSet): void + public function setDataSet(?ImportDataSetInterface $dataSet): void { $this->dataSet = $dataSet; } diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition.php b/src/DataDefinitionsBundle/Model/ExportDefinition.php index 7b1b6c5f..8edb9ef9 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition.php @@ -16,6 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model; +/** + * @method ExportDefinition\Dao getDao() + */ class ExportDefinition extends AbstractDataDefinition implements ExportDefinitionInterface { /** @@ -33,7 +36,12 @@ class ExportDefinition extends AbstractDataDefinition implements ExportDefinitio */ public $fetchUnpublished = false; - public static function getById($id) + public static function getById(string $name) + { + return static::getByName($name); + } + + public static function getByName($id) { $definitionEntry = new ExportDefinition(); $definitionEntry->setId((int)$id); @@ -41,7 +49,7 @@ public static function getById($id) * @var \Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition\Dao|\Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition\Dao */ $dao = $definitionEntry->getDao(); - $dao->getById($id); + $dao->getByName($id); return $definitionEntry; } diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php index 865d01c0..f88fa881 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Dao.php @@ -24,45 +24,28 @@ use function in_array; use function is_array; -class Dao extends Model\Dao\PhpArrayTable +class Dao extends Model\Dao\PimcoreLocationAwareConfigDao { - /** - * Configure Configuration File - */ - public function configure() - { - parent::configure(); - $this->setFile('exportdefinitions'); - } + private const CONFIG_KEY = 'export_definitions'; /** - * Get Configuration By Id - * - * @param null $id - * @throws Exception + * Configure Configuration File */ - public function getById($id = null) + public function configure(): void { - if ($id !== null) { - $this->model->setId($id); - } + $config = \Pimcore::getContainer()->getParameter('data_definitions.config_location'); + $definitions = \Pimcore::getContainer()->getParameter('data_definitions.export_definitions'); - $data = $this->db->getById($this->model->getId()); + $storageConfig = $config[self::CONFIG_KEY]; - if (isset($data['id'])) { - $this->assignVariablesToModel($data); - } else { - throw new InvalidArgumentException(sprintf('Export Definition with id: %s does not exist', - $this->model->getId())); - } + parent::configure([ + 'containerConfig' => $definitions, + 'settingsStoreScope' => 'data_definitions', + 'storageConfig' => $storageConfig, + ]); } - /** - * @param array $data - * @return void - * @throws Exception - */ - protected function assignVariablesToModel($data) + protected function assignVariablesToModel($data): void { parent::assignVariablesToModel($data); @@ -90,23 +73,26 @@ protected function assignVariablesToModel($data) * @param null $name * @throws Exception */ - public function getByName($name = null) + public function getByName(string $id = null): void { - if ($name !== null) { - $this->model->setName($name); + if ($id != null) { + $this->model->setName($id); } - $name = $this->model->getName(); + $data = $this->getDataByName($this->model->getName()); - $data = $this->db->fetchAll(function ($row) use ($name) { - return $row['name'] === $name; - }); + if ($data && $id != null) { + $data['id'] = $id; + } - if ($data[0]['id'] && count($data)) { - $this->assignVariablesToModel($data[0]); + if ($data) { + $this->assignVariablesToModel($data); + $this->model->setName($data['id']); } else { - throw new InvalidArgumentException(sprintf('Definition with name: %s does not exist', - $this->model->getName())); + throw new Model\Exception\NotFoundException(sprintf( + 'Thumbnail with ID "%s" does not exist.', + $this->model->getName() + )); } } @@ -123,56 +109,58 @@ public function save() } $this->model->setModificationDate($ts); - try { - $dataRaw = get_object_vars($this->model); - $data = []; - $allowedProperties = [ - 'id', - 'name', - 'provider', - 'class', - 'configuration', - 'creationDate', - 'modificationDate', - 'mapping', - 'runner', - 'stopOnException', - 'fetchUnpublished', - 'failureNotificationDocument', - 'successNotificationDocument', - 'fetcher', - 'fetcherConfig', - ]; - - foreach ($dataRaw as $key => $value) { - if (in_array($key, $allowedProperties, true)) { - if ($key === 'providerConfiguration') { - if ($value) { - $data[$key] = get_object_vars($value); - } - } elseif ($key === 'mapping') { - if ($value) { - $data[$key] = array(); - - if (is_array($value)) { - foreach ($value as $map) { - $data[$key][] = get_object_vars($map); - } + $dataRaw = get_object_vars($this->model); + $data = []; + $allowedProperties = [ + 'name', + 'provider', + 'class', + 'configuration', + 'creationDate', + 'modificationDate', + 'mapping', + 'runner', + 'stopOnException', + 'fetchUnpublished', + 'failureNotificationDocument', + 'successNotificationDocument', + 'fetcher', + 'fetcherConfig', + ]; + + foreach ($dataRaw as $key => $value) { + if (in_array($key, $allowedProperties, true)) { + if ($key === 'providerConfiguration') { + if ($value) { + $data[$key] = get_object_vars($value); + } + } elseif ($key === 'mapping') { + if ($value) { + $data[$key] = array(); + + if (is_array($value)) { + foreach ($value as $map) { + $data[$key][] = get_object_vars($map); } } - } else { - $data[$key] = $value; } + } else { + $data[$key] = $value; } } - $this->db->insertOrUpdate($data, $this->model->getId()); - } catch (Exception $e) { - throw $e; } + $this->saveData($this->model->getName(), $data); + } - if (!$this->model->getId()) { - $this->model->setId($this->db->getLastInsertId()); - } + protected function prepareDataStructureForYaml(string $id, mixed $data): mixed + { + return [ + 'data_definitions' => [ + 'export_definitions' => [ + $id => $data, + ], + ], + ]; } /** @@ -181,6 +169,6 @@ public function save() */ public function delete() { - $this->db->delete($this->model->getId()); + $this->deleteData($this->model->getName()); } } diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php index fa97d043..19c8b1e0 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing.php @@ -17,11 +17,21 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition; use Exception; -use Pimcore\Model; +use Pimcore\Model\AbstractModel; +use Pimcore\Model\Listing\CallableFilterListingInterface; +use Pimcore\Model\Listing\CallableOrderListingInterface; +use Pimcore\Model\Listing\Traits\FilterListingTrait; +use Pimcore\Model\Listing\Traits\OrderListingTrait; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; -class Listing extends Model\Listing\JsonListing +/** + * @method loadList() + */ +class Listing extends AbstractModel implements CallableFilterListingInterface, CallableOrderListingInterface { + use FilterListingTrait; + use OrderListingTrait; + /** * Contains the results of the list. * They are all an instance of Configuration. @@ -34,10 +44,10 @@ class Listing extends Model\Listing\JsonListing * @return ExportDefinitionInterface[] * @throws Exception */ - public function getObjects(): ?array + public function getObjects() { if (null === $this->definitions) { - $this->load(); + $this->loadList(); } return $this->definitions; diff --git a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php index 315bc1a6..71b22167 100644 --- a/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/ExportDefinition/Listing/Dao.php @@ -16,52 +16,31 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition\Listing; -use Exception; -use Pimcore; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition; use function count; -class Dao extends Pimcore\Model\Dao\PhpArrayTable +class Dao extends ExportDefinition\Dao { - /** - * Configure - */ - public function configure() + public function loadList(): array { - parent::configure(); - $this->setFile('exportdefinitions'); - } - - /** - * Loads a list of Definitions for the specified parameters, returns an array of Definitions elements. - * - * @return array - * @throws Exception - */ - public function load() - { - $routesData = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - $routes = array(); - foreach ($routesData as $routeData) { - $routes[] = ExportDefinition::getById($routeData['id']); + $definitions = []; + foreach ($this->loadIdList() as $name) { + $definitions[] = ExportDefinition::getByName($name); } - $this->model->setObjects($routes); + if ($this->model->getFilter()) { + $definitions = array_filter($definitions, $this->model->getFilter()); + } + if ($this->model->getOrder()) { + usort($definitions, $this->model->getOrder()); + } + $this->model->setObjects($definitions); - return $routes; + return $definitions; } - /** - * Get total count - * - * @return int - * @throws Exception - */ - public function getTotalCount() + public function getTotalCount(): int { - $data = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - return count($data); + return count($this->loadList()); } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition.php b/src/DataDefinitionsBundle/Model/ImportDefinition.php index 55e70a88..86ec2f14 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition.php @@ -16,6 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model; +/** + * @method ImportDefinition\Dao getDao() + */ class ImportDefinition extends AbstractDataDefinition implements ImportDefinitionInterface { /** @@ -78,7 +81,17 @@ class ImportDefinition extends AbstractDataDefinition implements ImportDefinitio */ public $forceLoadObject = false; - public static function getById($id) + /** + * @var string + */ + public $persister; + + public static function getById(string $name) + { + return static::getByName($name); + } + + public static function getByName($id) { $definitionEntry = new ImportDefinition(); $definitionEntry->setId((int)$id); @@ -86,7 +99,7 @@ public static function getById($id) * @var \Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition\Dao|\Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition\Dao */ $dao = $definitionEntry->getDao(); - $dao->getById($id); + $dao->getByName($id); return $definitionEntry; } @@ -210,4 +223,14 @@ public function setForceLoadObject($forceLoadObject) { $this->forceLoadObject = $forceLoadObject; } + + public function getPersister() + { + return $this->persister; + } + + public function setPersister($persister) + { + $this->persister = $persister; + } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php index 15bdcfa9..e2698ef7 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Dao.php @@ -17,52 +17,33 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; use Exception; -use InvalidArgumentException; use Pimcore\Model; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; -use function count; use function in_array; use function is_array; -class Dao extends Model\Dao\PhpArrayTable +class Dao extends Model\Dao\PimcoreLocationAwareConfigDao { - /** - * Configure Configuration File - */ - public function configure() - { - parent::configure(); - $this->setFile('importdefinitions'); - } + private const CONFIG_KEY = 'import_definitions'; /** - * Get Configuration By Id - * - * @param null $id - * @throws Exception + * Configure Configuration File */ - public function getById($id = null) + public function configure(): void { - if ($id !== null) { - $this->model->setId($id); - } + $config = \Pimcore::getContainer()->getParameter('data_definitions.config_location'); + $definitions = \Pimcore::getContainer()->getParameter('data_definitions.import_definitions'); - $data = $this->db->getById($this->model->getId()); + $storageConfig = $config[self::CONFIG_KEY]; - if (isset($data['id'])) { - $this->assignVariablesToModel($data); - } else { - throw new InvalidArgumentException(sprintf('Definition with id: %s does not exist', - $this->model->getId())); - } + parent::configure([ + 'containerConfig' => $definitions, + 'settingsStoreScope' => 'data_definitions', + 'storageConfig' => $storageConfig, + ]); } - /** - * @param array $data - * @return void - * @throws Exception - */ - protected function assignVariablesToModel($data) + protected function assignVariablesToModel($data): void { parent::assignVariablesToModel($data); @@ -90,23 +71,26 @@ protected function assignVariablesToModel($data) * @param null $name * @throws Exception */ - public function getByName($name = null) + public function getByName(string $id = null): void { - if ($name !== null) { - $this->model->setName($name); + if ($id != null) { + $this->model->setName($id); } - $name = $this->model->getName(); + $data = $this->getDataByName($this->model->getName()); - $data = $this->db->fetchAll(function ($row) use ($name) { - return $row['name'] === $name; - }); + if ($data && $id != null) { + $data['id'] = $id; + } - if (isset($data[0]['id']) && count($data)) { - $this->assignVariablesToModel($data[0]); + if ($data) { + $this->assignVariablesToModel($data); + $this->model->setName($data['id']); } else { - throw new InvalidArgumentException(sprintf('Definition with name: %s does not exist', - $this->model->getName())); + throw new Model\Exception\NotFoundException(sprintf( + 'Thumbnail with ID "%s" does not exist.', + $this->model->getName() + )); } } @@ -123,68 +107,70 @@ public function save() } $this->model->setModificationDate($ts); - try { - $dataRaw = get_object_vars($this->model); - $data = []; - $allowedProperties = [ - 'id', - 'name', - 'provider', - 'class', - 'configuration', - 'creationDate', - 'modificationDate', - 'mapping', - 'objectPath', - 'cleaner', - 'key', - 'renameExistingObjects', - 'relocateExistingObjects', - 'filter', - 'runner', - 'createVersion', - 'stopOnException', - 'omitMandatoryCheck', - 'failureNotificationDocument', - 'successNotificationDocument', - 'skipExistingObjects', - 'skipNewObjects', - 'forceLoadObject', - 'loader', - 'fetcher', - 'persister', - ]; - - foreach ($dataRaw as $key => $value) { - if (in_array($key, $allowedProperties, true)) { - if ($key === 'providerConfiguration') { - if ($value) { - $data[$key] = get_object_vars($value); - } - } elseif ($key === 'mapping') { - if ($value) { - $data[$key] = array(); - - if (is_array($value)) { - foreach ($value as $map) { - $data[$key][] = get_object_vars($map); - } + $dataRaw = get_object_vars($this->model); + $data = []; + $allowedProperties = [ + 'name', + 'provider', + 'class', + 'configuration', + 'creationDate', + 'modificationDate', + 'mapping', + 'objectPath', + 'cleaner', + 'key', + 'renameExistingObjects', + 'relocateExistingObjects', + 'filter', + 'runner', + 'createVersion', + 'stopOnException', + 'omitMandatoryCheck', + 'failureNotificationDocument', + 'successNotificationDocument', + 'skipExistingObjects', + 'skipNewObjects', + 'forceLoadObject', + 'loader', + 'fetcher', + 'persister', + ]; + + foreach ($dataRaw as $key => $value) { + if (in_array($key, $allowedProperties, true)) { + if ($key === 'providerConfiguration') { + if ($value) { + $data[$key] = get_object_vars($value); + } + } elseif ($key === 'mapping') { + if ($value) { + $data[$key] = array(); + + if (is_array($value)) { + foreach ($value as $map) { + $data[$key][] = get_object_vars($map); } } - } else { - $data[$key] = $value; } + } else { + $data[$key] = $value; } } - - $this->db->insertOrUpdate($data, $this->model->getId()); - } catch (Exception $e) { - throw $e; } - if (!$this->model->getId()) { - $this->model->setId($this->db->getLastInsertId()); - } + $this->saveData($this->model->getName(), $data); + } + + protected function prepareDataStructureForYaml(string $id, mixed $data): mixed + { + return [ + 'data_definitions' => [ + 'import_definitions' => [ + $id => $data, + ], + ], + ]; } /** @@ -193,6 +179,6 @@ public function save() */ public function delete() { - $this->db->delete($this->model->getId()); + $this->deleteData($this->model->getName()); } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php index fe5abf2b..cbec7d43 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing.php @@ -18,10 +18,21 @@ use Exception; use Pimcore\Model; +use Pimcore\Model\AbstractModel; +use Pimcore\Model\Listing\CallableFilterListingInterface; +use Pimcore\Model\Listing\CallableOrderListingInterface; +use Pimcore\Model\Listing\Traits\FilterListingTrait; +use Pimcore\Model\Listing\Traits\OrderListingTrait; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; -class Listing extends Model\Listing\JsonListing +/** + * @method loadList() + */ +class Listing extends AbstractModel implements CallableFilterListingInterface, CallableOrderListingInterface { + use FilterListingTrait; + use OrderListingTrait; + /** * Contains the results of the list. * They are all an instance of Configuration. @@ -37,7 +48,7 @@ class Listing extends Model\Listing\JsonListing public function getObjects() { if (null === $this->definitions) { - $this->load(); + $this->loadList(); } return $this->definitions; diff --git a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php index c587dd33..02e5b73b 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinition/Listing/Dao.php @@ -18,50 +18,32 @@ use Exception; use Pimcore; +use Pimcore\Bundle\StaticRoutesBundle\Model\Staticroute; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; use function count; -class Dao extends Pimcore\Model\Dao\PhpArrayTable +class Dao extends ImportDefinition\Dao { - /** - * Configure - */ - public function configure() + public function loadList(): array { - parent::configure(); - $this->setFile('importdefinitions'); - } - - /** - * Loads a list of Definitions for the specified parameters, returns an array of Definitions elements. - * - * @return array - * @throws Exception - */ - public function load() - { - $routesData = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - $routes = array(); - foreach ($routesData as $routeData) { - $routes[] = ImportDefinition::getById($routeData['id']); + $definitions = []; + foreach ($this->loadIdList() as $name) { + $definitions[] = ImportDefinition::getByName($name); } - $this->model->setObjects($routes); + if ($this->model->getFilter()) { + $definitions = array_filter($definitions, $this->model->getFilter()); + } + if ($this->model->getOrder()) { + usort($definitions, $this->model->getOrder()); + } + $this->model->setObjects($definitions); - return $routes; + return $definitions; } - /** - * Get total count - * - * @return int - * @throws Exception - */ - public function getTotalCount() + public function getTotalCount(): int { - $data = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); - - return count($data); + return count($this->loadList()); } } diff --git a/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php b/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php index d6124256..814fd49c 100644 --- a/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php +++ b/src/DataDefinitionsBundle/Model/ImportDefinitionInterface.php @@ -137,4 +137,14 @@ public function getCreateVersion(); * @param boolean $createVersion */ public function setCreateVersion($createVersion); + + /** + * @return mixed + */ + public function getPersister(); + + /** + * @param string $persister + */ + public function setPersister($persister); } diff --git a/src/DataDefinitionsBundle/Model/Log/Dao.php b/src/DataDefinitionsBundle/Model/Log/Dao.php index e1e35e91..596ec91d 100644 --- a/src/DataDefinitionsBundle/Model/Log/Dao.php +++ b/src/DataDefinitionsBundle/Model/Log/Dao.php @@ -40,7 +40,7 @@ public function getById($id = null) $this->model->setId($id); } - $data = $this->db->fetchRow('SELECT * FROM '.$this->tableName.' WHERE id = ?', $this->model->getId()); + $data = $this->db->fetchAssociative('SELECT * FROM '.$this->tableName.' WHERE id = ?', [$this->model->getId()]); if (!$data['id']) { throw new InvalidArgumentException(sprintf('Object with the ID %s does not exist', $this->model->getId())); diff --git a/src/DataDefinitionsBundle/Model/Log/Listing.php b/src/DataDefinitionsBundle/Model/Log/Listing.php index dad59131..eef5296b 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing.php @@ -18,18 +18,13 @@ use Exception; use Pimcore\Model; -use Wvision\Bundle\DataDefinitionsBundle\Model\Log; use Pimcore\Model\Paginator\PaginateListingInterface; +use Wvision\Bundle\DataDefinitionsBundle\Model\Log; use function in_array; class Listing extends Model\Listing\AbstractListing implements PaginateListingInterface { - /** - * List of Logs. - * - * @var array - */ - public $data; + public ?array $data; /** * @var string @@ -48,7 +43,7 @@ class Listing extends Model\Listing\AbstractListing implements PaginateListingIn * * @return bool */ - public function isValidOrderKey($key) + public function isValidOrderKey($key): bool { return in_array($key, $this->validOrderKeys, true); } @@ -79,10 +74,10 @@ public function setObjects($data) /** * Get total count * - * @return mixed + * @return int * @throws Exception */ - public function count() + public function count(): int { return $this->getTotalCount(); } @@ -92,10 +87,10 @@ public function count() * * @param int $offset * @param int $itemCountPerPage - * @return mixed + * @return array * @throws Exception */ - public function getItems($offset, $itemCountPerPage) + public function getItems($offset, $itemCountPerPage): array { $this->setOffset($offset); $this->setLimit($itemCountPerPage); @@ -142,7 +137,7 @@ public function getLocale() * * @throws Exception */ - public function rewind() + public function rewind(): void { $this->getData(); reset($this->data); @@ -154,7 +149,7 @@ public function rewind() * @return mixed * @throws Exception */ - public function current() + public function current(): mixed { $this->getData(); @@ -164,10 +159,10 @@ public function current() /** * Key * - * @return mixed + * @return int|string|null * @throws Exception */ - public function key() + public function key(): int|string|null { $this->getData(); @@ -177,14 +172,14 @@ public function key() /** * Next * - * @return mixed + * @return void * @throws Exception */ - public function next() + public function next(): void { $this->getData(); - return next($this->data); + next($this->data); } /** @@ -193,7 +188,7 @@ public function next() * @return bool * @throws Exception */ - public function valid() + public function valid(): bool { $this->getData(); diff --git a/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php b/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php index 7a195c51..3d15e660 100644 --- a/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php +++ b/src/DataDefinitionsBundle/Model/Log/Listing/Dao.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Model\Log\Listing; -use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder; use Exception; use Pimcore\Model\Listing; @@ -50,7 +49,7 @@ protected function getTableName() * @return Log[] * @throws Exception */ - public function load() + public function load(): array { // load id's $list = $this->loadIdList(); @@ -86,13 +85,16 @@ public function getQueryBuilder(...$columns): DoctrineQueryBuilder public function loadIdList() { $queryBuilder = $this->getQueryBuilder(['id']); - $assetIds = $this->db->fetchCol((string) $queryBuilder, $this->model->getConditionVariables(), $this->model->getConditionVariableTypes()); + $assetIds = $this->db->fetchFirstColumn( + (string)$queryBuilder, + $this->model->getConditionVariables(), + $this->model->getConditionVariableTypes() + ); return array_map('intval', $assetIds); } - /** * Get Count * @@ -101,8 +103,10 @@ public function loadIdList() */ public function getCount(): int { - return (int)$this->db->fetchOne('SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition().$this->getOffsetLimit(), - $this->model->getConditionVariables()); + return (int)$this->db->fetchOne( + 'SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition().$this->getOffsetLimit(), + [$this->model->getConditionVariables()] + ); } /** @@ -113,7 +117,9 @@ public function getCount(): int */ public function getTotalCount(): int { - return (int)$this->db->fetchOne('SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition(), - $this->model->getConditionVariables()); + return (int)$this->db->fetchOne( + 'SELECT COUNT(*) as amount FROM '.$this->getTableName().$this->getCondition(), + [$this->model->getConditionVariables()] + ); } } diff --git a/src/DataDefinitionsBundle/Persister/Persister.php b/src/DataDefinitionsBundle/Persister/Persister.php new file mode 100644 index 00000000..81ce3c18 --- /dev/null +++ b/src/DataDefinitionsBundle/Persister/Persister.php @@ -0,0 +1,20 @@ +save(); + } +} diff --git a/src/DataDefinitionsBundle/Persister/PersisterInterface.php b/src/DataDefinitionsBundle/Persister/PersisterInterface.php new file mode 100644 index 00000000..28965240 --- /dev/null +++ b/src/DataDefinitionsBundle/Persister/PersisterInterface.php @@ -0,0 +1,13 @@ +process; } @@ -60,14 +77,14 @@ public function getProcess() : ProcessInterface /** * @param DefinitionEventInterface $event */ - public function onTotalEvent(DefinitionEventInterface $event) : void + public function onTotalEvent(DefinitionEventInterface $event): void { if (null === $this->process) { $date = Carbon::now(); $this->process = $this->processFactory->createProcess( sprintf( - static::PROCESS_NAME . ' (%s): %s', + static::PROCESS_NAME.' (%s): %s', $date->formatLocalized('%A %d %B %Y'), $event->getDefinition()->getName() ), @@ -90,9 +107,20 @@ public function onTotalEvent(DefinitionEventInterface $event) : void /** * @return void */ - public function onProgressEvent() : void + public function onProgressEvent(DefinitionEventInterface $event): void { if ($this->process) { + $now = new \DateTimeImmutable(); + $this->lastProgressStepsCount++; + if ($this->lastProgressAt instanceof \DateTimeInterface) { + $diff = $now->getTimestamp() - $this->lastProgressAt->getTimestamp(); + + if (self::PROCESS_PROGRESS_THROTTLE_SECONDS > $diff) { + return; + } + } + $this->lastProgressAt = $now; + if ($this->process->getStoppable()) { $this->process = $this->repository->find($this->process->getId()); } @@ -102,9 +130,11 @@ public function onProgressEvent() : void $this->process->setStatus(ProcessManagerBundle::STATUS_STOPPED); } - $this->process->progress(); + $this->process->progress($this->lastProgressStepsCount); $this->process->save(); + $this->lastProgressStepsCount = 0; + $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_PROGRESS); } } @@ -112,27 +142,40 @@ public function onProgressEvent() : void /** * @param DefinitionEventInterface $event */ - public function onStatusEvent(DefinitionEventInterface $event) : void + public function onStatusEvent(DefinitionEventInterface $event): void { if ($this->process) { + $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_STATUS.$event->getSubject()); + + $now = new \DateTimeImmutable(); + if ($this->lastStatusAt instanceof \DateTimeInterface) { + $diff = $now->getTimestamp() - $this->lastStatusAt->getTimestamp(); + + if (self::PROCESS_PROGRESS_THROTTLE_SECONDS > $diff) { + return; + } + } + $this->lastStatusAt = $now; + if ($this->process->getStoppable()) { $this->process = $this->repository->find($this->process->getId()); } $this->process->setMessage($event->getSubject()); $this->process->save(); - - $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_STATUS.$event->getSubject()); } } /** * @param DefinitionEventInterface $event */ - public function onFinishedEvent(DefinitionEventInterface $event) : void + public function onFinishedEvent(DefinitionEventInterface $event): void { if ($this->process) { if ($this->process->getStatus() === ProcessManagerBundle::STATUS_RUNNING) { + $this->process->setProgress($this->process->getTotal()); + $this->process->setMessage($event->getSubject()); $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED); + $this->process->setCompleted(time()); $this->process->save(); } $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_FINISHED.$event->getSubject()); @@ -142,7 +185,7 @@ public function onFinishedEvent(DefinitionEventInterface $event) : void /** * @param DefinitionEventInterface $event */ - public function onFailureEvent(DefinitionEventInterface $event) : void + public function onFailureEvent(DefinitionEventInterface $event): void { if ($this->process) { if ($event->getDefinition()->getStopOnException()) { @@ -150,7 +193,12 @@ public function onFailureEvent(DefinitionEventInterface $event) : void } else { $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED_WITH_EXCEPTIONS); } + $this->process->setCompleted(time()); $this->process->save(); + + if (is_string($event->getSubject())) { + $this->processLogger->info($this->process, ImportDefinitionsReport::EVENT_STATUS_ERROR.$event->getSubject()); + } } } } diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php index 2f16a63c..e168e0e6 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactGenerationProviderInterface.php @@ -22,10 +22,10 @@ interface ArtifactGenerationProviderInterface { /** - * @param array $configuration + * @param array $configuration * @param ExportDefinitionInterface $definition - * @param $params + * @param array $params * @return Asset */ - public function generateArtifact(array $configuration, ExportDefinitionInterface $definition, $params): ?Asset; + public function generateArtifact(array $configuration, ExportDefinitionInterface $definition, array $params): ?Asset; } diff --git a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php index f5c1d7a0..1a945d78 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php +++ b/src/DataDefinitionsBundle/ProcessManager/ArtifactProviderTrait.php @@ -23,7 +23,7 @@ trait ArtifactProviderTrait { public function generateArtifact($configuration, ExportDefinitionInterface $definition, $params): ?Asset { - if (!$params['artifact']) { + if (!isset($params['artifact'])) { return null; } @@ -45,7 +45,9 @@ public function generateArtifact($configuration, ExportDefinitionInterface $defi $artifact->setFilename(Asset\Service::getUniqueKey($artifact)); $artifact->save(); - fclose($stream); + if (is_resource($stream)) { + fclose($stream); + } return $artifact; } @@ -55,5 +57,9 @@ public function generateArtifact($configuration, ExportDefinitionInterface $defi * @param ExportDefinitionInterface $definition * @param array $params */ - abstract public function provideArtifactStream(array $configuration, ExportDefinitionInterface $definition, array $params); + abstract public function provideArtifactStream( + array $configuration, + ExportDefinitionInterface $definition, + array $params + ); } diff --git a/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php b/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php new file mode 100644 index 00000000..495a64ca --- /dev/null +++ b/src/DataDefinitionsBundle/ProcessManager/DataDefinitionProcessTrait.php @@ -0,0 +1,49 @@ +getSettings(); + if (isset($settings['params'])) { + $params = array_replace(json_decode($settings['params'], true), $params); + } + + $currentUser = Admin::getCurrentUser(); + + if ($currentUser && !isset($params['userId'])) { + $params['userId'] = $currentUser->getId(); + } + + $settings['command'] = [ + $type, + '-d', + $settings['definition'], + '-p', + json_encode($params), + ]; + + $executable->setSettings($settings); + + return parent::run($executable, $params); + } +} diff --git a/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php b/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php index 70413ecf..376f558c 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php +++ b/src/DataDefinitionsBundle/ProcessManager/ExportDefinitionProcess.php @@ -21,25 +21,10 @@ final class ExportDefinitionProcess extends Pimcore { - public function run(ExecutableInterface $executable, array $params = null): int - { - $settings = $executable->getSettings(); - if (isset($settings['params'])) { - $settings['params'] = array_replace(json_decode($settings['params'], true), (array)$params); - } else { - $settings['params'] = (array)$params; - } - - $settings['command'] = [ - 'data-definitions:export', - '-d', - $settings['definition'], - '-p', - json_encode($settings['params']), - ]; + use DataDefinitionProcessTrait; - $executable->setSettings($settings); - - return parent::run($executable, $params); + public function run(ExecutableInterface $executable, array $params = []): int + { + return $this->runDefinition('data-definitions:export', $executable, $params); } } diff --git a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php index e4869b6b..995e5e2f 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php +++ b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionProcess.php @@ -22,27 +22,10 @@ final class ImportDefinitionProcess extends Pimcore { - public function run(ExecutableInterface $executable, array $params = null): int - { - $settings = $executable->getSettings(); - $params = json_decode($settings['params'], true); - - $currentUser = Admin::getCurrentUser(); - - if ($currentUser && !isset($params['userId'])) { - $params['userId'] = $currentUser->getId(); - } + use DataDefinitionProcessTrait; - $settings['command'] = [ - 'data-definitions:import', - '-d', - $settings['definition'], - '-p', - json_encode($params), - ]; - - $executable->setSettings($settings); - - return parent::run($executable); + public function run(ExecutableInterface $executable, array $params = []): int + { + return $this->runDefinition('data-definitions:import', $executable, $params); } } diff --git a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php index 4f3d06a9..e3d4ae31 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php +++ b/src/DataDefinitionsBundle/ProcessManager/ImportDefinitionsReport.php @@ -200,7 +200,10 @@ protected function checkForError($line, &$result): bool { $pos = strpos($line, self::EVENT_STATUS_ERROR); if (false !== $pos) { - $result['productStatus'][$result['currentObject']]['error'] = substr($line, $pos + strlen(self::EVENT_STATUS_ERROR)); + $result['productStatus'][$result['currentObject']]['error'] = substr( + $line, + $pos + strlen(self::EVENT_STATUS_ERROR) + ); return true; } diff --git a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php index 3243ce16..a496cab4 100644 --- a/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php +++ b/src/DataDefinitionsBundle/ProcessManager/ProcessManagerExportListener.php @@ -27,16 +27,19 @@ final class ProcessManagerExportListener extends AbstractProcessManagerListener private $providerRegistry; - public function setProviderRegistry(ServiceRegistryInterface $providerRegistry) : void + public function setProviderRegistry(ServiceRegistryInterface $providerRegistry): void { $this->providerRegistry = $providerRegistry; } - public function onFinishedEvent(DefinitionEventInterface $event) : void + public function onFinishedEvent(DefinitionEventInterface $event): void { if (null !== $this->process) { if ($this->process->getStatus() == ProcessManagerBundle::STATUS_RUNNING) { + $this->process->setProgress($this->process->getTotal()); + $this->process->setMessage($event->getSubject()); $this->process->setStatus(ProcessManagerBundle::STATUS_COMPLETED); + $this->process->setCompleted(time()); $this->process->save(); } $definition = $event->getDefinition(); diff --git a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php index b7afb518..4454f059 100644 --- a/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php +++ b/src/DataDefinitionsBundle/Provider/AbstractFileProvider.php @@ -16,14 +16,79 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; +use Pimcore\File; +use Pimcore\Helper\LongRunningHelper; +use Pimcore\Model\Asset; +use Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator; + abstract class AbstractFileProvider { - protected function getFile(string $file): string + public function __construct( + protected StorageLocator $storageLocator, + protected LongRunningHelper $longRunningHelper, + ) + { + } + + protected function getFile(array $params): string { // if (!str_starts_with($file, '/')) { // $file = sprintf('%s/%s', PIMCORE_PROJECT_ROOT, $file); // } - return $file; + if (isset($params['asset'])) { + $asset = Asset::getByPath($params['asset']); + + if (!$asset) { + throw new \RuntimeException(sprintf('Asset "%s" not found', $params['asset'])); + } + + return $this->createTemporaryFileFromStream($asset->getStream()); + } + + if (isset($params['storage'], $params['file'])) { + $storage = $this->storageLocator->getStorage($params['storage']); + + if (!$storage->fileExists($params['file'])) { + throw new \RuntimeException(sprintf('File "%s" in Storage "%s" not found', $params['file'], $params['storage'])); + } + + return $this->createTemporaryFileFromStream($storage->readStream($params['file'])); + } + + if (isset($params['file'])) { + return $params['file']; + } + + throw new \RuntimeException('No file or asset given'); + } + + protected function createTemporaryFileFromStream($stream) + { + if (is_string($stream)) { + $src = fopen($stream, 'rb'); + $fileExtension = pathinfo($stream, PATHINFO_EXTENSION); + } else { + $src = $stream; + $streamMeta = stream_get_meta_data($src); + $fileExtension = pathinfo($streamMeta['uri'], PATHINFO_EXTENSION); + } + + $tmpFilePath = File::getLocalTempFilePath($fileExtension); + + $dest = fopen($tmpFilePath, 'wb', false, File::getContext()); + if (!$dest) { + throw new \Exception(sprintf('Unable to create temporary file in %s', $tmpFilePath)); + } + + stream_copy_to_stream($src, $dest); + fclose($dest); + + $this->longRunningHelper->addTmpFilePath($tmpFilePath); + register_shutdown_function(static function () use ($tmpFilePath) { + @unlink($tmpFilePath); + }); + + return $tmpFilePath; } } diff --git a/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php b/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php index 3b4531c7..5d83a1b3 100644 --- a/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php +++ b/src/DataDefinitionsBundle/Provider/AbstractSqlProvider.php @@ -55,8 +55,12 @@ public function getColumns(array $configuration): array return $returnColumns; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $db = $this->getDb($configuration); return new ArrayImportDataSet($db->fetchAllAssociative($configuration['query'])); diff --git a/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php b/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php index d1976821..2ed01cb5 100644 --- a/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php +++ b/src/DataDefinitionsBundle/Provider/ArrayImportDataSet.php @@ -35,7 +35,7 @@ public function __construct(array $data) * @return mixed Can return any type. * @since 5.0.0 */ - public function current() + public function current(): mixed { return ($this->iterator->current()); } @@ -46,7 +46,7 @@ public function current() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function next() + public function next(): void { $this->iterator->next(); } @@ -57,7 +57,7 @@ public function next() * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -69,7 +69,7 @@ public function key() * Returns true on success or false on failure. * @since 5.0.0 */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -80,7 +80,7 @@ public function valid() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function rewind() + public function rewind(): void { $this->iterator->rewind(); } @@ -94,7 +94,7 @@ public function rewind() * The return value is cast to an integer. * @since 5.1.0 */ - public function count() + public function count(): int { return count($this->data); } diff --git a/src/DataDefinitionsBundle/Provider/CsvProvider.php b/src/DataDefinitionsBundle/Provider/CsvProvider.php index edb4f5a6..e0c67f82 100644 --- a/src/DataDefinitionsBundle/Provider/CsvProvider.php +++ b/src/DataDefinitionsBundle/Provider/CsvProvider.php @@ -41,7 +41,7 @@ public function testData(array $configuration): bool public function getColumns(array $configuration): array { - $csvHeaders = (string) $configuration['csvHeaders']; + $csvHeaders = (string)$configuration['csvHeaders']; $csvExample = $configuration['csvExample']; $delimiter = $configuration['delimiter']; $enclosure = $configuration['enclosure']; @@ -52,7 +52,7 @@ public function getColumns(array $configuration): array if (count($rows) > 0) { $headerRow = $rows[0]; - $headers = str_getcsv($headerRow, $delimiter, $enclosure ?: chr(8)); + $headers = str_getcsv($headerRow, $delimiter ?? ',', $enclosure ?: chr(8)); if (count($headers) > 0) { //First line are the headers @@ -73,8 +73,12 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { $csvHeaders = $configuration['csvHeaders']; $delimiter = $configuration['delimiter']; $enclosure = $configuration['enclosure']; @@ -82,7 +86,7 @@ public function getData(array $configuration, ImportDefinitionInterface $definit $offset = $params['offset'] ?? null; $limit = $params['limit'] ?? null; - $file = $this->getFile($params['file']); + $file = $this->getFile($params); $csv = Reader::createFromPath($file, 'r'); $csv->setDelimiter($delimiter); @@ -128,19 +132,26 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); + $file = $this->getFile($params); $headers = count($this->exportData) > 0 ? array_keys($this->exportData[0]) : []; $writer = Writer::createFromPath($file, 'w+'); $writer->setDelimiter($configuration['delimiter']); $writer->setEnclosure($configuration['enclosure']); + if (isset($configuration['escape'])) { + $writer->setEscape($configuration['escape']); + } $writer->insertOne($headers); $writer->insertAll($this->exportData); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $this->exportData[] = $data; } @@ -153,6 +164,9 @@ public function provideArtifactStream(array $configuration, ExportDefinitionInte $writer = Writer::createFromStream($stream); $writer->setDelimiter($configuration['delimiter']); $writer->setEnclosure($configuration['enclosure']); + if (isset($configuration['escape'])) { + $writer->setEscape($configuration['escape']); + } $writer->insertOne($headers); $writer->insertAll($this->exportData); diff --git a/src/DataDefinitionsBundle/Provider/ExcelProvider.php b/src/DataDefinitionsBundle/Provider/ExcelProvider.php index 19fd1bd1..522c2063 100644 --- a/src/DataDefinitionsBundle/Provider/ExcelProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExcelProvider.php @@ -17,13 +17,10 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; use Box\Spout\Common\Entity\Row; -use Box\Spout\Common\Exception\IOException; use Box\Spout\Reader\ReaderInterface; -use Box\Spout\Writer\Exception\WriterNotOpenedException; use Box\Spout\Writer\WriterInterface; use Pimcore\Model\Asset; use Pimcore\Tool\Storage; -use Wvision\Bundle\DataDefinitionsBundle\Exception\SpoutException; use Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; @@ -70,9 +67,13 @@ public function getColumns(array $configuration): array return []; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { - $file = $this->getFile($params['file']); + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { + $file = $this->getFile($params); $reader = $this->createReader($file); $sheetIterator = $reader->getSheetIterator(); @@ -105,10 +106,14 @@ public function getData(array $configuration, ImportDefinitionInterface $definit }); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $headers = null; - if (null === $this->writer) { + if (!isset($this->writer)) { $headers = array_keys($data); } $writer = $this->getWriter(); @@ -119,7 +124,11 @@ public function addExportData(array $data, array $configuration, ExportDefinitio $data[$key] = (string)$item; } } - $writer->addRow($this->useSpoutLegacy ? array_values($data) : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray(array_values($data))); + $writer->addRow( + $this->useSpoutLegacy ? array_values( + $data + ) : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray(array_values($data)) + ); } public function exportData(array $configuration, ExportDefinitionInterface $definition, array $params): void @@ -131,8 +140,9 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); - rename($this->getExportPath(), $file); + $file = $this->getFile($params); + copy($this->getExportPath(), $file); + unlink($this->getExportPath()); } public function provideArtifactStream($configuration, ExportDefinitionInterface $definition, $params) @@ -150,7 +160,7 @@ private function createReader($path): ReaderInterface private function getWriter(): WriterInterface { - if (null === $this->writer) { + if (!isset($this->writer)) { $this->writer = $this->getXlsxWriter(); $this->writer->openToFile($this->getExportPath()); } @@ -160,7 +170,7 @@ private function getWriter(): WriterInterface private function getExportPath(): string { - if (null === $this->exportPath) { + if (!isset($this->exportPath)) { $this->exportPath = tempnam(sys_get_temp_dir(), 'excel_export_provider'); } @@ -190,7 +200,11 @@ private function buildColumns($row): array private function addHeaders(?array $headers, WriterInterface $writer): void { if (null !== $headers) { - $writer->addRow($this->useSpoutLegacy ? $headers : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($headers)); + $writer->addRow( + $this->useSpoutLegacy ? $headers : \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( + $headers + ) + ); } } diff --git a/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php b/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php index c3f87be7..65efcf52 100644 --- a/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php +++ b/src/DataDefinitionsBundle/Provider/ExportProviderInterface.php @@ -20,7 +20,12 @@ interface ExportProviderInterface { - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void; + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void; public function exportData(array $configuration, ExportDefinitionInterface $definition, array $params): void; } diff --git a/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php b/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php index 7dab6f8f..60922972 100644 --- a/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php +++ b/src/DataDefinitionsBundle/Provider/ExternalSqlProvider.php @@ -19,7 +19,6 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; -use Doctrine\DBAL\Exception; class ExternalSqlProvider extends AbstractSqlProvider { diff --git a/src/DataDefinitionsBundle/Provider/ImportDataSet.php b/src/DataDefinitionsBundle/Provider/ImportDataSet.php index ce8ebcac..5e987bbb 100644 --- a/src/DataDefinitionsBundle/Provider/ImportDataSet.php +++ b/src/DataDefinitionsBundle/Provider/ImportDataSet.php @@ -45,7 +45,7 @@ public function __construct(Iterator $iterator, Closure $processor = null) * @return mixed Can return any type. * @since 5.0.0 */ - public function current() + public function current(): mixed { return ($this->processor)($this->iterator->current()); } @@ -56,7 +56,7 @@ public function current() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function next() + public function next(): void { $this->iterator->next(); } @@ -67,7 +67,7 @@ public function next() * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -79,7 +79,7 @@ public function key() * Returns true on success or false on failure. * @since 5.0.0 */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -90,7 +90,7 @@ public function valid() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function rewind() + public function rewind(): void { $this->iterator->rewind(); } @@ -104,7 +104,7 @@ public function rewind() * The return value is cast to an integer. * @since 5.1.0 */ - public function count() + public function count(): int { if (false === $this->countAll) { $this->rewind(); diff --git a/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php b/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php index f8ca2180..44905556 100644 --- a/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php +++ b/src/DataDefinitionsBundle/Provider/ImportDataSetInterface.php @@ -16,7 +16,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; -use Countable; use Iterator; interface ImportDataSetInterface extends Iterator diff --git a/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php b/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php index 94da6ca9..f328865c 100644 --- a/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php +++ b/src/DataDefinitionsBundle/Provider/ImportProviderInterface.php @@ -25,5 +25,10 @@ public function testData(array $configuration): bool; public function getColumns(array $configuration): array; - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface; + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface; } diff --git a/src/DataDefinitionsBundle/Provider/JsonProvider.php b/src/DataDefinitionsBundle/Provider/JsonProvider.php index 645f1319..7c08f6f9 100644 --- a/src/DataDefinitionsBundle/Provider/JsonProvider.php +++ b/src/DataDefinitionsBundle/Provider/JsonProvider.php @@ -81,9 +81,13 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { - $file = $this->getFile($params['file']); + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { + $file = $this->getFile($params); if (file_exists($file)) { $json = file_get_contents($file); @@ -96,13 +100,21 @@ public function getData(array $configuration, ImportDefinitionInterface $definit public function exportData(array $configuration, ExportDefinitionInterface $definition, array $params): void { - $file = $this->getFile($params['file']); + if (!array_key_exists('file', $params)) { + return; + } + + $file = $this->getFile($params); file_put_contents($file, json_encode($this->exportData)); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $this->exportData[] = $data; } diff --git a/src/DataDefinitionsBundle/Provider/RawProvider.php b/src/DataDefinitionsBundle/Provider/RawProvider.php index 46c2351b..6bd88618 100644 --- a/src/DataDefinitionsBundle/Provider/RawProvider.php +++ b/src/DataDefinitionsBundle/Provider/RawProvider.php @@ -51,8 +51,12 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { return new ArrayImportDataSet($params['data']); } } diff --git a/src/DataDefinitionsBundle/Provider/SqlProvider.php b/src/DataDefinitionsBundle/Provider/SqlProvider.php index b6803472..79353b17 100644 --- a/src/DataDefinitionsBundle/Provider/SqlProvider.php +++ b/src/DataDefinitionsBundle/Provider/SqlProvider.php @@ -17,7 +17,6 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Provider; use Doctrine\DBAL\Connection; -use Pimcore\Db; class SqlProvider extends AbstractSqlProvider { diff --git a/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php b/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php index 52b6d36b..adbaf66b 100644 --- a/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php +++ b/src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php @@ -33,7 +33,7 @@ public function __construct(\Traversable $iterator) * @return mixed Can return any type. * @since 5.0.0 */ - public function current() + public function current(): mixed { return ($this->iterator->current()); } @@ -44,7 +44,7 @@ public function current() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function next() + public function next(): void { $this->iterator->next(); } @@ -55,7 +55,7 @@ public function next() * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -67,7 +67,7 @@ public function key() * Returns true on success or false on failure. * @since 5.0.0 */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -78,7 +78,7 @@ public function valid() * @return void Any returned value is ignored. * @since 5.0.0 */ - public function rewind() + public function rewind(): void { $this->iterator->rewind(); } diff --git a/src/DataDefinitionsBundle/Provider/XmlProvider.php b/src/DataDefinitionsBundle/Provider/XmlProvider.php index 6bb49571..92f679dd 100755 --- a/src/DataDefinitionsBundle/Provider/XmlProvider.php +++ b/src/DataDefinitionsBundle/Provider/XmlProvider.php @@ -85,16 +85,24 @@ public function getColumns(array $configuration): array return $returnHeaders; } - public function getData(array $configuration, ImportDefinitionInterface $definition, array $params, FilterInterface $filter = null): ImportDataSetInterface - { - $file = $this->getFile($params['file']); + public function getData( + array $configuration, + ImportDefinitionInterface $definition, + array $params, + FilterInterface $filter = null + ): ImportDataSetInterface { + $file = $this->getFile($params); $xml = file_get_contents($file); return new ArrayImportDataSet($this->convertXmlToArray($xml, $configuration['xPath'])); } - public function addExportData(array $data, array $configuration, ExportDefinitionInterface $definition, array $params): void - { + public function addExportData( + array $data, + array $configuration, + ExportDefinitionInterface $definition, + array $params + ): void { $writer = $this->getXMLWriter(); $writer->startElement('object'); @@ -127,12 +135,20 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi throw new RuntimeException(sprintf('Passed XSLT file "%1$s" not found', $path)); } - $extension = File::getFileExtension($configuration['xsltPath']); + $extension = pathinfo($configuration['xsltPath'], PATHINFO_EXTENSION); $workingPath = File::getLocalTempFilePath($extension); file_put_contents($workingPath, $storage->read($path)); $this->exportPath = tempnam(sys_get_temp_dir(), 'xml_export_xslt_transformation'); - $cmd = sprintf('xsltproc -v %1$s %2$s > %3$s', $workingPath, $dataPath, $this->getExportPath()); + $cmd = [ + 'xsltproc', + '-v', + '--noout', + '--output', + $this->getExportPath(), + $workingPath, + $dataPath, + ]; $process = new Process($cmd); $process->setTimeout(null); $process->run(); @@ -150,8 +166,9 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi return; } - $file = $this->getFile($params['file']); - rename($this->getExportPath(), $file); + $file = $this->getFile($params); + copy($this->getExportPath(), $file); + unlink($this->getExportPath()); } public function provideArtifactStream($configuration, ExportDefinitionInterface $definition, $params) @@ -161,7 +178,7 @@ public function provideArtifactStream($configuration, ExportDefinitionInterface private function getXMLWriter(): XMLWriter { - if (null === $this->writer) { + if (!isset($this->writer)) { $this->writer = new XMLWriter(); $this->writer->openMemory(); $this->writer->setIndent(true); @@ -176,7 +193,7 @@ private function getXMLWriter(): XMLWriter private function getExportPath(): string { - if (null === $this->exportPath) { + if (!isset($this->exportPath)) { $this->exportPath = tempnam(sys_get_temp_dir(), 'xml_export_provider'); } @@ -196,12 +213,13 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', $key); + $writer->writeAttribute('key', (string)$key); } if (is_string($data)) { $writer->writeCdata($data); } else { - $writer->text($data); + // TODO: should be more elaborate/exact for "non-string" scalar values + $writer->text((string)$data); } $writer->endElement(); } else { @@ -211,7 +229,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', $key); + $writer->writeAttribute('key', (string)$key); } $this->serializeCollection($writer, $data); $writer->endElement(); @@ -222,7 +240,7 @@ private function serialize(XMLWriter $writer, ?string $name, $data, ?int $key = $writer->writeAttribute('name', $name); } if (null !== $key) { - $writer->writeAttribute('key', $key); + $writer->writeAttribute('key', (string)$key); } $writer->writeCdata((string)$data); $writer->endElement(); diff --git a/src/DataDefinitionsBundle/Resources/config/coreshop.yml b/src/DataDefinitionsBundle/Resources/config/coreshop.yml index 9e23de49..c469353e 100644 --- a/src/DataDefinitionsBundle/Resources/config/coreshop.yml +++ b/src/DataDefinitionsBundle/Resources/config/coreshop.yml @@ -1,36 +1,36 @@ services: - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\PriceInterpreter: - tags: - - { name: data_definitions.interpreter, type: coreshop_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\PriceInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\PriceInterpreter: + tags: + - { name: data_definitions.interpreter, type: coreshop_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\PriceInterpreterType } - Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StorePriceSetter: - arguments: - - '@coreshop.repository.store' - tags: - - { name: data_definitions.setter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } - - { name: data_definitions.getter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } + Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StorePriceSetter: + arguments: + - '@coreshop.repository.store' + tags: + - { name: data_definitions.setter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } + - { name: data_definitions.getter, type: coreshop_store_price, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StorePriceSetterType } - importdefinitions.coreshop.setter.store_values: '@Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter' - Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter: - arguments: - - '@coreshop.repository.store' - tags: - - { name: data_definitions.setter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } - - { name: data_definitions.getter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } + importdefinitions.coreshop.setter.store_values: '@Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter' + Wvision\Bundle\DataDefinitionsBundle\Setter\CoreShop\StoreValuesSetter: + arguments: + - '@coreshop.repository.store' + tags: + - { name: data_definitions.setter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } + - { name: data_definitions.getter, type: coreshop_store_values, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\CoreShop\StoreValuesSetterType } - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\StoresInterpreter: - tags: - - { name: data_definitions.interpreter, type: coreshop_stores, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\StoresInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\StoresInterpreter: + tags: + - { name: data_definitions.interpreter, type: coreshop_stores, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\StoresInterpreterType } - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\CurrencyInterpreter: - arguments: - - '@coreshop.repository.currency' - tags: - - { name: data_definitions.interpreter, type: coreshop_currency, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\CurrencyInterpreter: + arguments: + - '@coreshop.repository.currency' + tags: + - { name: data_definitions.interpreter, type: coreshop_currency, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } - Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\MoneyInterpreter: - arguments: - - '@coreshop.repository.currency' - tags: - - { name: data_definitions.interpreter, type: coreshop_money, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\MoneyInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\CoreShop\MoneyInterpreter: + arguments: + - '@coreshop.repository.currency' + tags: + - { name: data_definitions.interpreter, type: coreshop_money, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CoreShop\MoneyInterpreterType } diff --git a/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml b/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml new file mode 100644 index 00000000..ad117d12 --- /dev/null +++ b/src/DataDefinitionsBundle/Resources/config/guzzle_psr7.yml @@ -0,0 +1,3 @@ +services: + GuzzleHttp\Psr7\HttpFactory: ~ + Psr\Http\Message\RequestFactoryInterface: '@GuzzleHttp\Psr7\HttpFactory' diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml index ada2b364..65440c89 100644 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/config.yml @@ -1,77 +1,85 @@ +imports: + - { resource: messenger.yml } + jms_serializer: - metadata: - directories: - data-definitions: - namespace_prefix: "DataDefinitionsBundle" - path: "@DataDefinitionsBundle/Resources/config/serializer" + metadata: + directories: + data-definitions: + namespace_prefix: "DataDefinitionsBundle" + path: "@DataDefinitionsBundle/Resources/config/serializer" data_definitions: - pimcore_admin: - js: - startup: '/bundles/datadefinitions/pimcore/js/startup.js' - definition_abstract_item: '/bundles/datadefinitions/pimcore/js/definition/abstractItem.js' - import_definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' - import_definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' - import_definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' - export_definition_panel: '/bundles/datadefinitions/pimcore/js/export/panel.js' - export_definition_item: '/bundles/datadefinitions/pimcore/js/export/item.js' - export_definition_config: '/bundles/datadefinitions/pimcore/js/export/configDialog.js' - export_definition_fields: '/bundles/datadefinitions/pimcore/js/export/fields.js' - import_provider_abstract: '/bundles/datadefinitions/pimcore/js/provider/abstractprovider.js' - import_provider_csv: '/bundles/datadefinitions/pimcore/js/provider/csv.js' - import_provider_excel: '/bundles/datadefinitions/pimcore/js/provider/excel.js' - import_provider_sql: '/bundles/datadefinitions/pimcore/js/provider/sql.js' - import_provider_external_sql: '/bundles/datadefinitions/pimcore/js/provider/externalSql.js' - import_provider_json: '/bundles/datadefinitions/pimcore/js/provider/json.js' - import_provider_xml: '/bundles/datadefinitions/pimcore/js/provider/xml.js' - import_provider_raw: '/bundles/datadefinitions/pimcore/js/provider/raw.js' - export_provider_abstract: '/bundles/datadefinitions/pimcore/js/export_provider/abstractprovider.js' - export_provider_csv: '/bundles/datadefinitions/pimcore/js/export_provider/csv.js' - export_provider_xml: '/bundles/datadefinitions/pimcore/js/export_provider/xml.js' - resource_definition: '/bundles/datadefinitions/pimcore/js/resource/definition.js' - definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' - definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' - definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' - interpreter_abstract: '/bundles/datadefinitions/pimcore/js/interpreters/abstract.js' - interpreter_href: '/bundles/datadefinitions/pimcore/js/interpreters/href.js' - interpreter_multihref: '/bundles/datadefinitions/pimcore/js/interpreters/multihref.js' - interpreter_defaultvalue: '/bundles/datadefinitions/pimcore/js/interpreters/defaultvalue.js' - interpreter_specificobject: '/bundles/datadefinitions/pimcore/js/interpreters/specificobject.js' - interpreter_assetbypath: '/bundles/datadefinitions/pimcore/js/interpreters/assetbypath.js' - interpreter_asseturl: '/bundles/datadefinitions/pimcore/js/interpreters/asseturl.js' - interpreter_assetsurl: '/bundles/datadefinitions/pimcore/js/interpreters/assetsurl.js' - interpreter_quantityvalue: '/bundles/datadefinitions/pimcore/js/interpreters/quantityvalue.js' - interpreter_nested: '/bundles/datadefinitions/pimcore/js/interpreters/nested.js' - interpreter_nested_container: '/bundles/datadefinitions/pimcore/js/interpreters/nestedcontainer.js' - interpreter_empty: '/bundles/datadefinitions/pimcore/js/interpreters/empty.js' - interpreter_expression: '/bundles/datadefinitions/pimcore/js/interpreters/expression.js' - interpreter_object_resolver: '/bundles/datadefinitions/pimcore/js/interpreters/objectresolver.js' - interpreter_mapping: '/bundles/datadefinitions/pimcore/js/interpreters/mapping.js' - interpreter_iterator: '/bundles/datadefinitions/pimcore/js/interpreters/iterator.js' - interpreter_definition: '/bundles/datadefinitions/pimcore/js/interpreters/definition.js' - interpreter_conditional: '/bundles/datadefinitions/pimcore/js/interpreters/conditional.js' - interpreter_twig: '/bundles/datadefinitions/pimcore/js/interpreters/twig.js' - interpreter_carbon: '/bundles/datadefinitions/pimcore/js/interpreters/carbon.js' - interpreter_metadata: '/bundles/datadefinitions/pimcore/js/interpreters/metadata.js' - setter_abstract: '/bundles/datadefinitions/pimcore/js/setters/abstract.js' - setter_fieldcollection: '/bundles/datadefinitions/pimcore/js/setters/fieldcollection.js' - setter_objectbrick: '/bundles/datadefinitions/pimcore/js/setters/objectbrick.js' - setter_classificationstore: '/bundles/datadefinitions/pimcore/js/setters/classificationstore.js' - setter_localizedfield: '/bundles/datadefinitions/pimcore/js/setters/localizedfield.js' - getter_fieldcollection: '/bundles/datadefinitions/pimcore/js/getters/fieldcollection.js' - getter_objectbrick: '/bundles/datadefinitions/pimcore/js/getters/objectbrick.js' - getter_classificationstore: '/bundles/datadefinitions/pimcore/js/getters/classificationstore.js' - getter_localizedfield: '/bundles/datadefinitions/pimcore/js/getters/localizedfield.js' - fetcher_abstract: '/bundles/datadefinitions/pimcore/js/fetchers/abstract.js' - fetcher_objects: '/bundles/datadefinitions/pimcore/js/fetchers/objects.js' - fuse: '/bundles/datadefinitions/pimcore/js/automap/fuse.min.js' - import_rule_action: '/bundles/datadefinitions/pimcore/js/import_rule/action.js' - import_rule_condition: '/bundles/datadefinitions/pimcore/js/import_rule/condition.js' - import_rule_item: '/bundles/datadefinitions/pimcore/js/import_rule/item.js' - import_rule_panel: '/bundles/datadefinitions/pimcore/js/import_rule/panel.js' - import_rules_interpreter: '/bundles/datadefinitions/pimcore/js/interpreters/import_rule.js' - import_rules_condition_expression: '/bundles/datadefinitions/pimcore/js/import_rule/conditions/expression.js' - import_rules_action_expression: '/bundles/datadefinitions/pimcore/js/import_rule/actions/expression.js' - import_rules_action_object: '/bundles/datadefinitions/pimcore/js/import_rule/actions/object.js' - css: - data_definition: '/bundles/datadefinitions/pimcore/css/datadefinition.css' + pimcore_admin: + js: + startup: '/bundles/datadefinitions/pimcore/js/startup.js' + definition_abstract_item: '/bundles/datadefinitions/pimcore/js/definition/abstractItem.js' + import_definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' + import_definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' + import_definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' + export_definition_panel: '/bundles/datadefinitions/pimcore/js/export/panel.js' + export_definition_item: '/bundles/datadefinitions/pimcore/js/export/item.js' + export_definition_config: '/bundles/datadefinitions/pimcore/js/export/configDialog.js' + export_definition_fields: '/bundles/datadefinitions/pimcore/js/export/fields.js' + import_provider_abstract: '/bundles/datadefinitions/pimcore/js/provider/abstractprovider.js' + import_provider_csv: '/bundles/datadefinitions/pimcore/js/provider/csv.js' + import_provider_excel: '/bundles/datadefinitions/pimcore/js/provider/excel.js' + import_provider_sql: '/bundles/datadefinitions/pimcore/js/provider/sql.js' + import_provider_external_sql: '/bundles/datadefinitions/pimcore/js/provider/externalSql.js' + import_provider_json: '/bundles/datadefinitions/pimcore/js/provider/json.js' + import_provider_xml: '/bundles/datadefinitions/pimcore/js/provider/xml.js' + import_provider_raw: '/bundles/datadefinitions/pimcore/js/provider/raw.js' + export_provider_abstract: '/bundles/datadefinitions/pimcore/js/export_provider/abstractprovider.js' + export_provider_csv: '/bundles/datadefinitions/pimcore/js/export_provider/csv.js' + export_provider_xml: '/bundles/datadefinitions/pimcore/js/export_provider/xml.js' + resource_definition: '/bundles/datadefinitions/pimcore/js/resource/definition.js' + definition_panel: '/bundles/datadefinitions/pimcore/js/import/panel.js' + definition_item: '/bundles/datadefinitions/pimcore/js/import/item.js' + definition_config: '/bundles/datadefinitions/pimcore/js/import/configDialog.js' + interpreter_abstract: '/bundles/datadefinitions/pimcore/js/interpreters/abstract.js' + interpreter_href: '/bundles/datadefinitions/pimcore/js/interpreters/href.js' + interpreter_multihref: '/bundles/datadefinitions/pimcore/js/interpreters/multihref.js' + interpreter_defaultvalue: '/bundles/datadefinitions/pimcore/js/interpreters/defaultvalue.js' + interpreter_specificobject: '/bundles/datadefinitions/pimcore/js/interpreters/specificobject.js' + interpreter_assetbypath: '/bundles/datadefinitions/pimcore/js/interpreters/assetbypath.js' + interpreter_asseturl: '/bundles/datadefinitions/pimcore/js/interpreters/asseturl.js' + interpreter_assetsurl: '/bundles/datadefinitions/pimcore/js/interpreters/assetsurl.js' + interpreter_quantityvalue: '/bundles/datadefinitions/pimcore/js/interpreters/quantityvalue.js' + interpreter_nested: '/bundles/datadefinitions/pimcore/js/interpreters/nested.js' + interpreter_nested_container: '/bundles/datadefinitions/pimcore/js/interpreters/nestedcontainer.js' + interpreter_empty: '/bundles/datadefinitions/pimcore/js/interpreters/empty.js' + interpreter_expression: '/bundles/datadefinitions/pimcore/js/interpreters/expression.js' + interpreter_object_resolver: '/bundles/datadefinitions/pimcore/js/interpreters/objectresolver.js' + interpreter_mapping: '/bundles/datadefinitions/pimcore/js/interpreters/mapping.js' + interpreter_iterator: '/bundles/datadefinitions/pimcore/js/interpreters/iterator.js' + interpreter_definition: '/bundles/datadefinitions/pimcore/js/interpreters/definition.js' + interpreter_conditional: '/bundles/datadefinitions/pimcore/js/interpreters/conditional.js' + interpreter_twig: '/bundles/datadefinitions/pimcore/js/interpreters/twig.js' + interpreter_carbon: '/bundles/datadefinitions/pimcore/js/interpreters/carbon.js' + interpreter_metadata: '/bundles/datadefinitions/pimcore/js/interpreters/metadata.js' + interpreter_typecasting: '/bundles/datadefinitions/pimcore/js/interpreters/typecasting.js' + setter_abstract: '/bundles/datadefinitions/pimcore/js/setters/abstract.js' + setter_fieldcollection: '/bundles/datadefinitions/pimcore/js/setters/fieldcollection.js' + setter_objectbrick: '/bundles/datadefinitions/pimcore/js/setters/objectbrick.js' + setter_classificationstore: '/bundles/datadefinitions/pimcore/js/setters/classificationstore.js' + setter_localizedfield: '/bundles/datadefinitions/pimcore/js/setters/localizedfield.js' + getter_fieldcollection: '/bundles/datadefinitions/pimcore/js/getters/fieldcollection.js' + getter_objectbrick: '/bundles/datadefinitions/pimcore/js/getters/objectbrick.js' + getter_classificationstore: '/bundles/datadefinitions/pimcore/js/getters/classificationstore.js' + getter_localizedfield: '/bundles/datadefinitions/pimcore/js/getters/localizedfield.js' + fetcher_abstract: '/bundles/datadefinitions/pimcore/js/fetchers/abstract.js' + fetcher_objects: '/bundles/datadefinitions/pimcore/js/fetchers/objects.js' + fuse: '/bundles/datadefinitions/pimcore/js/automap/fuse.min.js' + import_rule_action: '/bundles/datadefinitions/pimcore/js/import_rule/action.js' + import_rule_condition: '/bundles/datadefinitions/pimcore/js/import_rule/condition.js' + import_rule_item: '/bundles/datadefinitions/pimcore/js/import_rule/item.js' + import_rule_panel: '/bundles/datadefinitions/pimcore/js/import_rule/panel.js' + import_rules_interpreter: '/bundles/datadefinitions/pimcore/js/interpreters/import_rule.js' + import_rules_condition_expression: '/bundles/datadefinitions/pimcore/js/import_rule/conditions/expression.js' + import_rules_action_expression: '/bundles/datadefinitions/pimcore/js/import_rule/actions/expression.js' + import_rules_action_object: '/bundles/datadefinitions/pimcore/js/import_rule/actions/object.js' + css: + data_definition: '/bundles/datadefinitions/pimcore/css/datadefinition.css' + +framework: + http_client: + enabled: true \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml new file mode 100755 index 00000000..fe0ff6cd --- /dev/null +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml @@ -0,0 +1,18 @@ +framework: + messenger: + transports: + data_definitions_import: + dsn: "doctrine://default?queue_name=data_definitions_import" + failure_transport: data_definitions_import_failed + retry_strategy: + max_retries: 5 + delay: 300000 + multiplier: 2 + # we store failed messages here for admins to manually review them later + data_definitions_import_failed: + dsn: "doctrine://default?queue_name=data_definitions_import_failed" + retry_strategy: + max_retries: 0 + + routing: + 'Wvision\Bundle\DataDefinitionsBundle\Messenger\ImportRowMessage': data_definitions_import \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml b/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml index 7d59a7bc..d70c3bda 100755 --- a/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml +++ b/src/DataDefinitionsBundle/Resources/config/pimcore/routing.yml @@ -1,67 +1,67 @@ data_definitions_admin_import_definitions: - type: coreshop.resources - resource: | - alias: data_definitions.import_definition - additional_routes: - config: - path: get-config - action: getConfig - methods: [GET] - columns: - path: get-columns - action: getColumns - methods: [GET] - testData: - path: test-data - action: testData - methods: [GET] - import: - path: import - action: import - methods: [GET,POST] - export: - path: export - action: export - methods: [GET] - duplicate: - path: duplicate - action: duplicate - methods: [POST] + type: coreshop.resources + resource: | + alias: data_definitions.import_definition + additional_routes: + config: + path: get-config + action: getConfig + methods: [GET] + columns: + path: get-columns + action: getColumns + methods: [GET] + testData: + path: test-data + action: testData + methods: [GET] + import: + path: import + action: import + methods: [GET,POST] + export: + path: export + action: export + methods: [GET] + duplicate: + path: duplicate + action: duplicate + methods: [POST] data_definitions_admin_export_definitions: - type: coreshop.resources - resource: | - alias: data_definitions.export_definition - additional_routes: - config: - path: get-config - action: getConfig - methods: [GET] - columns: - path: get-columns - action: getColumns - methods: [GET] - testData: - path: test-data - action: testData - methods: [GET] - import: - path: import - action: import - methods: [GET,POST] - export: - path: export - action: export - methods: [GET] - duplicate: - path: duplicate - action: duplicate - methods: [POST] + type: coreshop.resources + resource: | + alias: data_definitions.export_definition + additional_routes: + config: + path: get-config + action: getConfig + methods: [GET] + columns: + path: get-columns + action: getColumns + methods: [GET] + testData: + path: test-data + action: testData + methods: [GET] + import: + path: import + action: import + methods: [GET,POST] + export: + path: export + action: export + methods: [GET] + duplicate: + path: duplicate + action: duplicate + methods: [POST] data_definitions_admin_export_import_rules: - path: /admin/data_definitions/import_rules/export - defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::exportAction} + path: /admin/data_definitions/import_rules/export + defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::exportAction } data_definitions_admin_import_import_rules: - path: /admin/data_definitions/import_rules/import - defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::importAction} + path: /admin/data_definitions/import_rules/import + defaults: { _controller: Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController::importAction } diff --git a/src/DataDefinitionsBundle/Resources/config/process_manager.yml b/src/DataDefinitionsBundle/Resources/config/process_manager.yml index 7f509f8a..c02bb4ab 100644 --- a/src/DataDefinitionsBundle/Resources/config/process_manager.yml +++ b/src/DataDefinitionsBundle/Resources/config/process_manager.yml @@ -1,48 +1,48 @@ services: - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerImportListener: - arguments: - - '@process_manager.factory.process' - - '@ProcessManagerBundle\Logger\ProcessLogger' - - '@process_manager.repository.process' - - '@event_dispatcher' - tags: - - { name: 'kernel.event_listener', event: 'data_definitions.import.total', method: 'onTotalEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.progress', method: 'onProgressEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.status', method: 'onStatusEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.finished', method: 'onFinishedEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.import.failure', method: 'onFailureEvent' } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerImportListener: + arguments: + - '@process_manager.factory.process' + - '@ProcessManagerBundle\Logger\ProcessLogger' + - '@process_manager.repository.process' + - '@event_dispatcher' + tags: + - { name: 'kernel.event_listener', event: 'data_definitions.import.total', method: 'onTotalEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.progress', method: 'onProgressEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.status', method: 'onStatusEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.finished', method: 'onFinishedEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.import.failure', method: 'onFailureEvent' } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerExportListener: + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ProcessManagerExportListener: + arguments: + - '@process_manager.factory.process' + - '@ProcessManagerBundle\Logger\ProcessLogger' + - '@process_manager.repository.process' + - '@event_dispatcher' + calls: + - method: setProviderRegistry arguments: - - '@process_manager.factory.process' - - '@ProcessManagerBundle\Logger\ProcessLogger' - - '@process_manager.repository.process' - - '@event_dispatcher' - calls: - - method: setProviderRegistry - arguments: - - '@data_definitions.registry.export_provider' - tags: - - { name: 'kernel.event_listener', event: 'data_definitions.export.total', method: 'onTotalEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.progress', method: 'onProgressEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.status', method: 'onStatusEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.finished', method: 'onFinishedEvent' } - - { name: 'kernel.event_listener', event: 'data_definitions.export.failure', method: 'onFailureEvent' } + - '@data_definitions.registry.export_provider' + tags: + - { name: 'kernel.event_listener', event: 'data_definitions.export.total', method: 'onTotalEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.progress', method: 'onProgressEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.status', method: 'onStatusEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.finished', method: 'onFinishedEvent' } + - { name: 'kernel.event_listener', event: 'data_definitions.export.failure', method: 'onFailureEvent' } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionProcess: - tags: - - { name: 'process_manager.process', type: 'importdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionProcess: + tags: + - { name: 'process_manager.process', type: 'importdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionProcess: - tags: - - { name: 'process_manager.process', type: 'exportdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionProcess: + tags: + - { name: 'process_manager.process', type: 'exportdefinition', form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager\ImportDefinitionsType } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionStartupFormResolver: - arguments: - - '@data_definitions.repository.export_definition' - tags: - - { name: 'process_manager.startup_form_resolver', type: 'exportdefinition' } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ExportDefinitionStartupFormResolver: + arguments: + - '@data_definitions.repository.export_definition' + tags: + - { name: 'process_manager.startup_form_resolver', type: 'exportdefinition' } - Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionsReport: - tags: - - { name: process_manager.process_report, type: import_definitions } + Wvision\Bundle\DataDefinitionsBundle\ProcessManager\ImportDefinitionsReport: + tags: + - { name: process_manager.process_report, type: import_definitions } diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml index 8e823170..f87cd6bb 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.Definition.yml @@ -1,45 +1,45 @@ Wvision\Bundle\DataDefinitionsBundle\Model\Definition: - exclusion_policy: ALL - xml_root_name: definition - properties: - id: - expose: true - type: integer - xml_attribute: true - groups: [List, Detailed] - name: - expose: true - type: string - groups: [List, Detailed] - provider: - expose: true - type: string - groups: [Detailed] - class: - expose: true - type: string - groups: [Detailed] - configuration: - expose: true - type: array - groups: [Detailed] - mapping: - expose: true - type: array - groups: [Detailed] - runner: - expose: true - type: string - groups: [Detailed] - stopOnException: - expose: true - type: boolean - groups: [Detailed] - failureNotificationDocument: - expose: true - type: integer - groups: [Detailed] - successNotificationDocument: - expose: true - type: integer - groups: [Detailed] + exclusion_policy: ALL + xml_root_name: definition + properties: + id: + expose: true + type: string + xml_attribute: true + groups: [ List, Detailed ] + name: + expose: true + type: string + groups: [ List, Detailed ] + provider: + expose: true + type: string + groups: [ Detailed ] + class: + expose: true + type: string + groups: [ Detailed ] + configuration: + expose: true + type: array + groups: [ Detailed ] + mapping: + expose: true + type: array + groups: [ Detailed ] + runner: + expose: true + type: string + groups: [ Detailed ] + stopOnException: + expose: true + type: boolean + groups: [ Detailed ] + failureNotificationDocument: + expose: true + type: integer + groups: [ Detailed ] + successNotificationDocument: + expose: true + type: integer + groups: [ Detailed ] diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml index f0e203c7..30e861c6 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ExportDefinition.yml @@ -1,16 +1,21 @@ Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition: - exclusion_policy: ALL - xml_root_name: export_definition - properties: - fetcher: - expose: true - type: string - groups: [Detailed] - fetcherConfig: - expose: true - type: array - groups: [Detailed] - fetchUnpublished: - expose: true - type: boolean - groups: [Detailed] + exclusion_policy: ALL + xml_root_name: export_definition + properties: + fetcher: + expose: true + type: string + groups: [ Detailed ] + fetcherConfig: + expose: true + type: array + groups: [ Detailed ] + fetchUnpublished: + expose: true + type: boolean + groups: [ Detailed ] + virtual_properties: + isWriteable: + exp: object.isWriteable() + type: boolean + serialized_name: isWriteable \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml index f2426729..c47fa82d 100755 --- a/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml +++ b/src/DataDefinitionsBundle/Resources/config/serializer/Model.ImportDefinition.yml @@ -1,56 +1,61 @@ Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition: - exclusion_policy: ALL - xml_root_name: import_definition - properties: - loader: - expose: true - type: string - groups: [Detailed] - objectPath: - expose: true - type: string - groups: [Detailed] - cleaner: - expose: true - type: string - groups: [Detailed] - key: - expose: true - type: string - groups: [Detailed] - filter: - expose: true - type: string - groups: [Detailed] - renameExistingObjects: - expose: true - type: boolean - groups: [Detailed] - relocateExistingObjects: - expose: true - type: boolean - groups: [Detailed] - omitMandatoryCheck: - expose: true - type: boolean - groups: [Detailed] - skipNewObjects: - expose: true - type: boolean - groups: [Detailed] - skipExistingObjects: - expose: true - type: boolean - groups: [Detailed] - forceLoadObject: - expose: true - type: boolean - groups: [Detailed] - createVersion: - expose: true - type: boolean - groups: [Detailed] - persister: - expose: true - type: string - groups: [Detailed] + exclusion_policy: ALL + xml_root_name: import_definition + properties: + loader: + expose: true + type: string + groups: [ Detailed ] + objectPath: + expose: true + type: string + groups: [ Detailed ] + cleaner: + expose: true + type: string + groups: [ Detailed ] + key: + expose: true + type: string + groups: [ Detailed ] + filter: + expose: true + type: string + groups: [ Detailed ] + renameExistingObjects: + expose: true + type: boolean + groups: [ Detailed ] + relocateExistingObjects: + expose: true + type: boolean + groups: [ Detailed ] + omitMandatoryCheck: + expose: true + type: boolean + groups: [ Detailed ] + skipNewObjects: + expose: true + type: boolean + groups: [ Detailed ] + skipExistingObjects: + expose: true + type: boolean + groups: [ Detailed ] + forceLoadObject: + expose: true + type: boolean + groups: [ Detailed ] + createVersion: + expose: true + type: boolean + groups: [ Detailed ] + virtual_properties: + isWriteable: + exp: object.isWriteable() + type: boolean + serialized_name: isWriteable + persister: + expose: true + type: string + groups: [Detailed] \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/config/services.yml b/src/DataDefinitionsBundle/Resources/config/services.yml index fe08f0a9..5e6accef 100644 --- a/src/DataDefinitionsBundle/Resources/config/services.yml +++ b/src/DataDefinitionsBundle/Resources/config/services.yml @@ -1,346 +1,403 @@ imports: - - { resource: "services/forms.yml" } - - { resource: "services/installer.yml" } - - { resource: "services/commands.yml" } - - { resource: "services/import_rules.yml" } + - { resource: "services/forms.yml" } + - { resource: "services/installer.yml" } + - { resource: "services/commands.yml" } + - { resource: "services/import_rules.yml" } services: Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher: - arguments: - - '@event_dispatcher' + arguments: + - '@event_dispatcher' Wvision\Bundle\DataDefinitionsBundle\Service\FieldSelection: - public: true + public: true + + Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface: '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactory' + Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactory: ~ Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface: '@Wvision\Bundle\DataDefinitionsBundle\Importer\Importer' Wvision\Bundle\DataDefinitionsBundle\Importer\Importer: - arguments: - - '@data_definitions.registry.provider' - - '@data_definitions.registry.filter' - - '@data_definitions.registry.runner' - - '@data_definitions.registry.interpreter' - - '@data_definitions.registry.setter' - - '@data_definitions.registry.cleaner' - - '@data_definitions.registry.loader' - - '@Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher' - - '@logger' - - '@pimcore.model.factory' - - '@coreshop.expression_language' - tags: - - { name: monolog.logger, channel: import_definition } - - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } + arguments: + - '@data_definitions.registry.provider' + - '@data_definitions.registry.filter' + - '@data_definitions.registry.runner' + - '@data_definitions.registry.interpreter' + - '@data_definitions.registry.setter' + - '@data_definitions.registry.cleaner' + - '@data_definitions.registry.loader' + - '@data_definitions.registry.persister' + - '@Wvision\Bundle\DataDefinitionsBundle\Event\EventDispatcher' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + - '@logger' + - '@pimcore.model.factory' + - '@coreshop.expression_language' + - '@messenger.default_bus' + tags: + - { name: monolog.logger, channel: import_definition } + - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface: '@Wvision\Bundle\DataDefinitionsBundle\Exporter\Exporter' Wvision\Bundle\DataDefinitionsBundle\Exporter\Exporter: - arguments: - - '@data_definitions.registry.fetcher' - - '@data_definitions.registry.export_runner' - - '@data_definitions.registry.interpreter' - - '@data_definitions.registry.getter' - - '@data_definitions.registry.export_provider' - - '@event_dispatcher' - - '@logger' - tags: - - { name: monolog.logger, channel: export_definition } - - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } + arguments: + - '@data_definitions.registry.fetcher' + - '@data_definitions.registry.export_runner' + - '@data_definitions.registry.interpreter' + - '@data_definitions.registry.getter' + - '@data_definitions.registry.export_provider' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + - '@event_dispatcher' + - '@logger' + tags: + - { name: monolog.logger, channel: export_definition } + - { name: 'kernel.event_listener', event: 'data_definitions.stop', method: 'stop' } ### Registries data_definitions.registry.provider: - class: CoreShop\Component\Registry\ServiceRegistry - public: true - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface - - 'Import Definition Providers' + class: CoreShop\Component\Registry\ServiceRegistry + public: true + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Provider\ImportProviderInterface + - 'Import Definition Providers' data_definitions.form.registry.provider: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry data_definitions.registry.export_provider: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Provider\ExportProviderInterface - - 'Import Definition Export Providers' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Provider\ExportProviderInterface + - 'Import Definition Export Providers' data_definitions.form.registry.export_provider: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry data_definitions.registry.loader: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Loader\LoaderInterface - - 'Import Definition Loaders' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Loader\LoaderInterface + - 'Import Definition Loaders' data_definitions.registry.cleaner: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Cleaner\CleanerInterface - - 'Import Definition Cleaners' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Cleaner\CleanerInterface + - 'Import Definition Cleaners' data_definitions.registry.filter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface - - 'Import Definition Filters' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface + - 'Import Definition Filters' data_definitions.registry.interpreter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface - - 'Import Definition Interpreters' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Interpreter\InterpreterInterface + - 'Import Definition Interpreters' data_definitions.form.registry.interpreter: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry data_definitions.registry.setter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface - - 'Import Definition Setters' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface + - 'Import Definition Setters' data_definitions.form.registry.setter: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry data_definitions.registry.getter: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface - - 'Import Definition Getters' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface + - 'Import Definition Getters' data_definitions.form.registry.getter: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry data_definitions.registry.fetcher: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Fetcher\FetcherInterface - - 'Import Definition Fetchers' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Fetcher\FetcherInterface + - 'Import Definition Fetchers' data_definitions.form.registry.fetcher: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry data_definitions.registry.runner: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface - - 'Import Definition Runners' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Runner\RunnerInterface + - 'Import Definition Runners' data_definitions.registry.export_runner: - class: CoreShop\Component\Registry\ServiceRegistry - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Runner\ExportRunnerInterface - - 'Export Definition Runners' + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Runner\ExportRunnerInterface + - 'Export Definition Runners' + + data_definitions.registry.persister: + class: CoreShop\Component\Registry\ServiceRegistry + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Persister\PersisterInterface + - 'Import Definition Persisters' ### CLEANER Wvision\Bundle\DataDefinitionsBundle\Cleaner\Deleter: - tags: - - { name: data_definitions.cleaner, type: deleter } + tags: + - { name: data_definitions.cleaner, type: deleter } Wvision\Bundle\DataDefinitionsBundle\Cleaner\None: - tags: - - { name: data_definitions.cleaner, type: none } + tags: + - { name: data_definitions.cleaner, type: none } Wvision\Bundle\DataDefinitionsBundle\Cleaner\ReferenceCleaner: - tags: - - { name: data_definitions.cleaner, type: reference_cleaner } + tags: + - { name: data_definitions.cleaner, type: reference_cleaner } Wvision\Bundle\DataDefinitionsBundle\Cleaner\Unpublisher: - tags: - - { name: data_definitions.cleaner, type: unpublisher } + tags: + - { name: data_definitions.cleaner, type: unpublisher } ### INTERPRETER Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetsUrlInterpreter: - arguments: - - '@pimcore.http_client' - tags: - - { name: data_definitions.interpreter, type: assets_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetsUrlInterpreterType } + arguments: + - '@Psr\Http\Client\ClientInterface' + - '@Psr\Http\Message\RequestFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: assets_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetsUrlInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetUrlInterpreter: - arguments: - - '@pimcore.http_client' - tags: - - { name: data_definitions.interpreter, type: asset_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetUrlInterpreterType } + arguments: + - '@Psr\Http\Client\ClientInterface' + - '@Psr\Http\Message\RequestFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: asset_url, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetUrlInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\MetadataInterpreter: - tags: - - { name: data_definitions.interpreter, type: metadata, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MetadataInterpreterType } + tags: + - { name: data_definitions.interpreter, type: metadata, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MetadataInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\AssetByPathInterpreter: - tags: - - { name: data_definitions.interpreter, type: asset_by_path, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetByPathInterpreterType } + tags: + - { name: data_definitions.interpreter, type: asset_by_path, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\AssetByPathInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\CarbonInterpreter: - tags: - - { name: data_definitions.interpreter, type: carbon, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CarbonInterpreterType } + tags: + - { name: data_definitions.interpreter, type: carbon, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\CarbonInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\CheckboxInterpreter: - tags: - - { name: data_definitions.interpreter, type: checkbox, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.interpreter, type: checkbox, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\DefaultValueInterpreter: - tags: - - { name: data_definitions.interpreter, type: default_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefaultValueInterpreterType } + tags: + - { name: data_definitions.interpreter, type: default_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefaultValueInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\SpecificObjectInterpreter: - tags: - - { name: data_definitions.interpreter, type: specific_object, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\SpecificObjectInterpreterType } + tags: + - { name: data_definitions.interpreter, type: specific_object, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\SpecificObjectInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\HrefInterpreter: - tags: - - { name: data_definitions.interpreter, type: href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\HrefInterpreterType } + tags: + - { name: data_definitions.interpreter, type: href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\HrefInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\MultiHrefInterpreter: - tags: - - { name: data_definitions.interpreter, type: multi_href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MultiHrefInterpreterType } + tags: + - { name: data_definitions.interpreter, type: multi_href, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MultiHrefInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\QuantityValueInterpreter: - tags: - - { name: data_definitions.interpreter, type: quantity_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\QuantityValueInterpreterType } + tags: + - { name: data_definitions.interpreter, type: quantity_value, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\QuantityValueInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\NestedInterpreter: - arguments: - - '@data_definitions.registry.interpreter' - tags: - - { name: data_definitions.interpreter, type: nested, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType } + arguments: + - '@data_definitions.registry.interpreter' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: nested, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\ExpressionInterpreter: - arguments: - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ExpressionInterpreterType } + arguments: + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ExpressionInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\ObjectResolverInterpreter: - arguments: - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: object_resolver, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType } + arguments: + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: object_resolver, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\DefinitionInterpreter: - arguments: - - '@data_definitions.repository.import_definition' - - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' - tags: - - { name: data_definitions.interpreter, type: definition, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefinitionType } + arguments: + - '@data_definitions.repository.import_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: data_definitions.interpreter, type: definition, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\DefinitionType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\ConditionalInterpreter: - arguments: - - '@data_definitions.registry.interpreter' - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: conditional, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ConditionalInterpreterType } + arguments: + - '@data_definitions.registry.interpreter' + - '@coreshop.expression_language' + - '@service_container' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: conditional, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ConditionalInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\MappingInterpreter: - arguments: - - '@service_container' - tags: - - { name: data_definitions.interpreter, type: mapping, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MappingInterpreterType } + arguments: + - '@service_container' + tags: + - { name: data_definitions.interpreter, type: mapping, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\MappingInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\IteratorInterpreter: - arguments: - - '@data_definitions.registry.interpreter' - tags: - - { name: data_definitions.interpreter, type: iterator, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\IteratorInterpreterType } + arguments: + - '@data_definitions.registry.interpreter' + - '@Wvision\Bundle\DataDefinitionsBundle\Context\ContextFactoryInterface' + tags: + - { name: data_definitions.interpreter, type: iterator, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\IteratorInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\TwigInterpreter: - arguments: - - '@twig' - tags: - - { name: data_definitions.interpreter, type: twig, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\TwigInterpreterType } + arguments: + - '@twig' + tags: + - { name: data_definitions.interpreter, type: twig, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\TwigInterpreterType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\DoNotSetOnEmptyInterpreter: tags: - { name: data_definitions.interpreter, type: donotsetonempty, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\TypeCastingInterpreter: + tags: + - { name: data_definitions.interpreter, type: type_casting, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\TypeCastingInterpreterType } + Wvision\Bundle\DataDefinitionsBundle\Interpreter\LinkInterpreter: - tags: - - { name: data_definitions.interpreter, type: link, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.interpreter, type: link, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Interpreter\ExternalImageInterpreter: - tags: - - { name: data_definitions.interpreter, type: external_image, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.interpreter, type: external_image, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } ### PROVIDER Wvision\Bundle\DataDefinitionsBundle\Provider\CsvProvider: - tags: - - { name: data_definitions.import_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\CsvProviderType } - - { name: data_definitions.export_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\CsvProviderType } + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' + tags: + - { name: data_definitions.import_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\CsvProviderType } + - { name: data_definitions.export_provider, type: csv, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\CsvProviderType } Wvision\Bundle\DataDefinitionsBundle\Provider\ExcelProvider: - tags: - - { name: data_definitions.import_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExcelProviderType } - - { name: data_definitions.export_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' + tags: + - { name: data_definitions.import_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExcelProviderType } + - { name: data_definitions.export_provider, type: excel, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Provider\JsonProvider: - tags: - - { name: data_definitions.import_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\JsonProviderType } - - { name: data_definitions.export_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' + tags: + - { name: data_definitions.import_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\JsonProviderType } + - { name: data_definitions.export_provider, type: json, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Provider\ExternalSqlProvider: - tags: - - { name: data_definitions.import_provider, type: external_sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExternalSqlProviderType } + tags: + - { name: data_definitions.import_provider, type: external_sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\ExternalSqlProviderType } Wvision\Bundle\DataDefinitionsBundle\Provider\SqlProvider: - arguments: - - '@doctrine.dbal.default_connection' - tags: - - { name: data_definitions.import_provider, type: sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\SqlProviderType } + arguments: + - '@doctrine.dbal.default_connection' + tags: + - { name: data_definitions.import_provider, type: sql, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\SqlProviderType } Wvision\Bundle\DataDefinitionsBundle\Provider\XmlProvider: - tags: - - { name: data_definitions.import_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\XmlProviderType } - - { name: data_definitions.export_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\XmlProviderType } + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator' + - '@Pimcore\Helper\LongRunningHelper' + tags: + - { name: data_definitions.import_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\XmlProviderType } + - { name: data_definitions.export_provider, type: xml, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProvider\XmlProviderType } Wvision\Bundle\DataDefinitionsBundle\Provider\RawProvider: - tags: - - { name: data_definitions.import_provider, type: raw, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\RawProviderType } + tags: + - { name: data_definitions.import_provider, type: raw, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProvider\RawProviderType } ### SETTER AND GETTER Wvision\Bundle\DataDefinitionsBundle\Setter\ClassificationStoreSetter: - tags: - - { name: data_definitions.setter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } - - { name: data_definitions.getter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } + tags: + - { name: data_definitions.setter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } + - { name: data_definitions.getter, type: classificationstore, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ClassificationStoreSetterType } Wvision\Bundle\DataDefinitionsBundle\Setter\ClassificationStoreFieldGetter: - tags: - - { name: data_definitions.getter, type: classificationstore_field, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.getter, type: classificationstore_field, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Setter\FieldCollectionSetter: - tags: - - { name: data_definitions.setter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } - - { name: data_definitions.getter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } + tags: + - { name: data_definitions.setter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } + - { name: data_definitions.getter, type: fieldcollection, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\FieldCollectionSetterType } Wvision\Bundle\DataDefinitionsBundle\Setter\KeySetter: - tags: - - { name: data_definitions.setter, type: key, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.setter, type: key, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Setter\LocalizedfieldSetter: - tags: - - { name: data_definitions.setter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } - - { name: data_definitions.getter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } + tags: + - { name: data_definitions.setter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } + - { name: data_definitions.getter, type: localizedfield, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\LocalizedFieldSetterType } Wvision\Bundle\DataDefinitionsBundle\Setter\ObjectbrickSetter: - tags: - - { name: data_definitions.setter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } - - { name: data_definitions.getter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } + tags: + - { name: data_definitions.setter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } + - { name: data_definitions.getter, type: objectbrick, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Setter\ObjectBrickSetterType } Wvision\Bundle\DataDefinitionsBundle\Setter\ObjectTypeSetter: - tags: - - { name: data_definitions.setter, type: object_type, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.setter, type: object_type, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\Setter\RelationSetter: - tags: - - { name: data_definitions.setter, type: relation, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } + tags: + - { name: data_definitions.setter, type: relation, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\NoConfigurationType } Wvision\Bundle\DataDefinitionsBundle\EventListener\ObjectDeleteListener: - tags: - - { name: kernel.event_listener, event: pimcore.dataobject.postDelete, method: onDataObjectDelete } + tags: + - { name: kernel.event_listener, event: pimcore.dataobject.postDelete, method: onDataObjectDelete } Wvision\Bundle\DataDefinitionsBundle\Fetcher\ObjectsFetcher: - tags: - - { name: data_definitions.fetcher, type: objects, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Fetcher\ObjectsFetcherType } + tags: + - { name: data_definitions.fetcher, type: objects, form-type: Wvision\Bundle\DataDefinitionsBundle\Form\Type\Fetcher\ObjectsFetcherType } ### LOADER Wvision\Bundle\DataDefinitionsBundle\Loader\PrimaryKeyLoader: - tags: - - { name: data_definitions.loader, type: primary_key } + tags: + - { name: data_definitions.loader, type: primary_key } + + ### PERSISTER + Wvision\Bundle\DataDefinitionsBundle\Persister\Persister: + tags: + - { name: data_definitions.persister, type: persister } + + Wvision\Bundle\DataDefinitionsBundle\Service\StorageLocator: + arguments: + $locator: !tagged_locator { tag: flysystem.storage } + + Wvision\Bundle\DataDefinitionsBundle\EventListener\PimcoreSettingsListener: + tags: + - { name: kernel.event_listener, event: pimcore.admin.indexAction.settings, method: indexSettings } + + Wvision\Bundle\DataDefinitionsBundle\EventListener\WriteableListener: + tags: + - { name: kernel.event_subscriber } + + Wvision\Bundle\DataDefinitionsBundle\Messenger\ImportRowMessageHandler: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: messenger.message_handler } diff --git a/src/DataDefinitionsBundle/Resources/config/services/commands.yml b/src/DataDefinitionsBundle/Resources/config/services/commands.yml index 6ade77a0..ea5aa5ef 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/commands.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/commands.yml @@ -1,46 +1,54 @@ services: - Wvision\Bundle\DataDefinitionsBundle\Command\ListImportDefinitionsCommand: - arguments: - - '@data_definitions.repository.import_definition' - tags: - - { name: 'console.command', command: 'data-definitions:list:imports' } + Wvision\Bundle\DataDefinitionsBundle\Command\ListImportDefinitionsCommand: + arguments: + - '@data_definitions.repository.import_definition' + tags: + - { name: 'console.command', command: 'data-definitions:list:imports' } - Wvision\Bundle\DataDefinitionsBundle\Command\ListExportDefinitionsCommand: - arguments: - - '@data_definitions.repository.export_definition' - tags: - - { name: 'console.command', command: 'data-definitions:list:exports' } + Wvision\Bundle\DataDefinitionsBundle\Command\ListExportDefinitionsCommand: + arguments: + - '@data_definitions.repository.export_definition' + tags: + - { name: 'console.command', command: 'data-definitions:list:exports' } - Wvision\Bundle\DataDefinitionsBundle\Command\ImportCommand: - arguments: - - '@event_dispatcher' - - '@data_definitions.repository.import_definition' - - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' - tags: - - { name: 'console.command', command: 'data-definitions:import' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportCommand: + arguments: + - '@event_dispatcher' + - '@data_definitions.repository.import_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: 'console.command', command: 'data-definitions:import' } - Wvision\Bundle\DataDefinitionsBundle\Command\ExportCommand: - arguments: - - '@event_dispatcher' - - '@data_definitions.repository.export_definition' - - '@Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface' - tags: - - { name: 'console.command', command: 'data-definitions:export' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportAsyncCommand: + arguments: + - '@event_dispatcher' + - '@data_definitions.repository.import_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface' + tags: + - { name: 'console.command', command: 'data-definitions:async-import' } - Wvision\Bundle\DataDefinitionsBundle\Command\ImportImportDefinitionCommand: - arguments: - - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.import_definition")' - - '@data_definitions.repository.import_definition' - - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' - - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' - tags: - - { name: 'console.command', command: 'data-definitions:definition:import:import' } + Wvision\Bundle\DataDefinitionsBundle\Command\ExportCommand: + arguments: + - '@event_dispatcher' + - '@data_definitions.repository.export_definition' + - '@Wvision\Bundle\DataDefinitionsBundle\Exporter\ExporterInterface' + tags: + - { name: 'console.command', command: 'data-definitions:export' } - Wvision\Bundle\DataDefinitionsBundle\Command\ImportExportDefinitionCommand: - arguments: - - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.export_definition")' - - '@data_definitions.repository.export_definition' - - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' - - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' - tags: - - { name: 'console.command', command: 'data-definitions:definition:import:export' } + Wvision\Bundle\DataDefinitionsBundle\Command\ImportImportDefinitionCommand: + arguments: + - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.import_definition")' + - '@data_definitions.repository.import_definition' + - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' + - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' + tags: + - { name: 'console.command', command: 'data-definitions:definition:import:import' } + + Wvision\Bundle\DataDefinitionsBundle\Command\ImportExportDefinitionCommand: + arguments: + - '@=service("CoreShop\\Component\\Resource\\Metadata\\RegistryInterface").get("data_definitions.export_definition")' + - '@data_definitions.repository.export_definition' + - '@CoreShop\Bundle\ResourceBundle\Pimcore\ObjectManager' + - '@CoreShop\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface' + tags: + - { name: 'console.command', command: 'data-definitions:definition:import:export' } diff --git a/src/DataDefinitionsBundle/Resources/config/services/forms.yml b/src/DataDefinitionsBundle/Resources/config/services/forms.yml index e7105d37..dfd4632f 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/forms.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/forms.yml @@ -1,137 +1,137 @@ parameters: - data_definitions.form.type.definition.validation_groups: [data_definitions] - data_definitions.form.type.mapping.validation_groups: [data_definitions] - data_definitions.form.type.export_definition.validation_groups: [data_definitions] - data_definitions.form.type.export_mapping.validation_groups: [data_definitions] + data_definitions.form.type.definition.validation_groups: [ data_definitions ] + data_definitions.form.type.mapping.validation_groups: [ data_definitions ] + data_definitions.form.type.export_definition.validation_groups: [ data_definitions ] + data_definitions.form.type.export_mapping.validation_groups: [ data_definitions ] services: - Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper: - arguments: - - !service - class: Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper - arguments: - - '@property_accessor' - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ClassChoiceType: - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\CleanerChoiceType: - arguments: ['%data_definitions.cleaners%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\FilterChoiceType: - arguments: ['%data_definitions.filters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\InterpreterChoiceType: - arguments: ['%data_definitions.interpreters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProviderChoiceType: - arguments: ['%data_definitions.import_providers%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProviderChoiceType: - arguments: ['%data_definitions.export_providers%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\LoaderChoiceType: - arguments: ['%data_definitions.loaders%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\RunnerChoiceType: - arguments: ['%data_definitions.runners%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\SetterChoiceType: - arguments: ['%data_definitions.setters%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportDefinitionType: - arguments: - - '%data_definitions.model.import_definition.class%' - - '%data_definitions.form.type.definition.validation_groups%' - - '@data_definitions.form.registry.provider' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingCollectionType: - arguments: - - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingType: - arguments: - - '%data_definitions.form.type.mapping.validation_groups%' - - '@data_definitions.form.registry.setter' - - '@data_definitions.form.registry.interpreter' - - '@data_definitions.form.registry.getter' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportDefinitionType: - arguments: - - '%data_definitions.model.export_definition.class%' - - '%data_definitions.form.type.export_definition.validation_groups%' - - '@data_definitions.form.registry.export_provider' - - '@data_definitions.form.registry.fetcher' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingCollectionType: - arguments: - - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingType: - arguments: - - '%data_definitions.form.type.export_mapping.validation_groups%' - - '@data_definitions.form.registry.getter' - - '@data_definitions.form.registry.interpreter' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterType: - arguments: ['@data_definitions.form.registry.interpreter'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterCollectionType: - arguments: ['@data_definitions.registry.interpreter'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType: - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType: - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\FetcherChoiceType: - arguments: ['%data_definitions.fetchers%'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\DefinitionChoiceType: - arguments: ['@data_definitions.repository.import_definition'] - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportRunnerChoiceType: - arguments: ['%data_definitions.export_runners%'] - tags: - - { name: form.type } + Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper: ~ + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ClassChoiceType: + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\CleanerChoiceType: + arguments: [ '%data_definitions.cleaners%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\FilterChoiceType: + arguments: [ '%data_definitions.filters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\InterpreterChoiceType: + arguments: [ '%data_definitions.interpreters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportProviderChoiceType: + arguments: [ '%data_definitions.import_providers%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportProviderChoiceType: + arguments: [ '%data_definitions.export_providers%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\LoaderChoiceType: + arguments: [ '%data_definitions.loaders%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\RunnerChoiceType: + arguments: [ '%data_definitions.runners%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\SetterChoiceType: + arguments: [ '%data_definitions.setters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\PersisterChoiceType: + arguments: [ '%data_definitions.persisters%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportDefinitionType: + arguments: + - '%data_definitions.model.import_definition.class%' + - '%data_definitions.form.type.definition.validation_groups%' + - '@data_definitions.form.registry.provider' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingCollectionType: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ImportMappingType: + arguments: + - '%data_definitions.form.type.mapping.validation_groups%' + - '@data_definitions.form.registry.setter' + - '@data_definitions.form.registry.interpreter' + - '@data_definitions.form.registry.getter' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportDefinitionType: + arguments: + - '%data_definitions.model.export_definition.class%' + - '%data_definitions.form.type.export_definition.validation_groups%' + - '@data_definitions.form.registry.export_provider' + - '@data_definitions.form.registry.fetcher' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingCollectionType: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Form\DataMapper\DefinitionMappingDataMapper' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportMappingType: + arguments: + - '%data_definitions.form.type.export_mapping.validation_groups%' + - '@data_definitions.form.registry.getter' + - '@data_definitions.form.registry.interpreter' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterType: + arguments: [ '@data_definitions.form.registry.interpreter' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\InterpreterCollectionType: + arguments: [ '@data_definitions.registry.interpreter' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\NestedInterpreterType: + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\Interpreter\ObjectResolverType: + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\FetcherChoiceType: + arguments: [ '%data_definitions.fetchers%' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\DefinitionChoiceType: + arguments: [ '@data_definitions.repository.import_definition' ] + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Form\Type\ExportRunnerChoiceType: + arguments: [ '%data_definitions.export_runners%' ] + tags: + - { name: form.type } diff --git a/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml b/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml index 6b28b7bc..5efb6877 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/import_rules.yml @@ -1,115 +1,115 @@ parameters: - data_definitions.form.type.import_rule.action.validation_groups: [data_definitions] - data_definitions.form.type.import_rule.condition.validation_groups: [data_definitions] - data_definitions.form.type.import_rule.validation_groups: [data_definitions] + data_definitions.form.type.import_rule.action.validation_groups: [ data_definitions ] + data_definitions.form.type.import_rule.condition.validation_groups: [ data_definitions ] + data_definitions.form.type.import_rule.validation_groups: [ data_definitions ] services: - data_definitions.import_rule.action: - class: CoreShop\Component\Registry\ServiceRegistry - public: true - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ImportRuleProcessorInterface - - 'Import Rule Action Processors' - - data_definitions.form.import_rule.action: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - data_definitions.import_rule.condition: - class: CoreShop\Component\Registry\ServiceRegistry - public: true - arguments: - - Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ImportRuleConditionCheckerInterface - - 'Import Rule Condition Checkers' - - data_definitions.form.import_rule.condition: - class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionChoiceType: - arguments: - - '%data_definitions.import_rule.actions%' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionChoiceType: - arguments: - - '%data_definitions.import_rule.conditions%' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionCollectionType: - arguments: - - '@data_definitions.import_rule.action' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionCollectionType: - arguments: - - '@data_definitions.import_rule.condition' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionType: - arguments: - - '%data_definitions.form.type.import_rule.action.validation_groups%' - - '@data_definitions.form.import_rule.action' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionType: - arguments: - - '%data_definitions.form.type.definition.validation_groups%' - - '@data_definitions.form.import_rule.condition' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleType: - arguments: - - '%data_definitions.form.type.definition.validation_groups%' - tags: - - { name: form.type } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ExpressionConditionChecker: - arguments: - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.import_rule.condition, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Condition\ExpressionConditionType } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ExpressionProcessor: - arguments: - - '@coreshop.expression_language' - - '@service_container' - tags: - - { name: data_definitions.import_rule.action, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ExpressionType } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ObjectProcessor: - tags: - - { name: data_definitions.import_rule.action, type: object, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ObjectType } - - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier' - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier: - arguments: - - '@data_definitions.import_rule.action' - - data_definitions.import_rules.conditions.validation.processor: - class: CoreShop\Component\Rule\Condition\RuleConditionsValidationProcessor - shared: false - arguments: - - '@data_definitions.import_rule.condition' - - 'Import Rules Interface' - - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor' - Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor: - arguments: - - '@data_definitions.import_rules.conditions.validation.processor' - - Wvision\Bundle\DataDefinitionsBundle\Interpreter\ImportRuleInterpreter: - arguments: - - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface' - - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface' - tags: - - { name: data_definitions.interpreter, type: import_rule, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRulesInterpreterType } - - Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController: - tags: - - { name: controller.service_arguments } + data_definitions.import_rule.action: + class: CoreShop\Component\Registry\ServiceRegistry + public: true + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ImportRuleProcessorInterface + - 'Import Rule Action Processors' + + data_definitions.form.import_rule.action: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + data_definitions.import_rule.condition: + class: CoreShop\Component\Registry\ServiceRegistry + public: true + arguments: + - Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ImportRuleConditionCheckerInterface + - 'Import Rule Condition Checkers' + + data_definitions.form.import_rule.condition: + class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionChoiceType: + arguments: + - '%data_definitions.import_rule.actions%' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionChoiceType: + arguments: + - '%data_definitions.import_rule.conditions%' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionCollectionType: + arguments: + - '@data_definitions.import_rule.action' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionCollectionType: + arguments: + - '@data_definitions.import_rule.condition' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleActionType: + arguments: + - '%data_definitions.form.type.import_rule.action.validation_groups%' + - '@data_definitions.form.import_rule.action' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleConditionType: + arguments: + - '%data_definitions.form.type.definition.validation_groups%' + - '@data_definitions.form.import_rule.condition' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRuleType: + arguments: + - '%data_definitions.form.type.definition.validation_groups%' + tags: + - { name: form.type } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Condition\ExpressionConditionChecker: + arguments: + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.import_rule.condition, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Condition\ExpressionConditionType } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ExpressionProcessor: + arguments: + - '@coreshop.expression_language' + - '@service_container' + tags: + - { name: data_definitions.import_rule.action, type: expression, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ExpressionType } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Action\ObjectProcessor: + tags: + - { name: data_definitions.import_rule.action, type: object, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\Action\ObjectType } + + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier' + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplier: + arguments: + - '@data_definitions.import_rule.action' + + data_definitions.import_rules.conditions.validation.processor: + class: CoreShop\Component\Rule\Condition\RuleConditionsValidationProcessor + shared: false + arguments: + - '@data_definitions.import_rule.condition' + - 'Import Rules Interface' + + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface: '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor' + Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessor: + arguments: + - '@data_definitions.import_rules.conditions.validation.processor' + + Wvision\Bundle\DataDefinitionsBundle\Interpreter\ImportRuleInterpreter: + arguments: + - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\ImportRuleValidationProcessorInterface' + - '@Wvision\Bundle\DataDefinitionsBundle\Rules\Processor\RuleApplierInterface' + tags: + - { name: data_definitions.interpreter, type: import_rule, form-type: Wvision\Bundle\DataDefinitionsBundle\Rules\Form\Type\ImportRulesInterpreterType } + + Wvision\Bundle\DataDefinitionsBundle\Controller\ImportRuleController: + tags: + - { name: controller.service_arguments } diff --git a/src/DataDefinitionsBundle/Resources/config/services/installer.yml b/src/DataDefinitionsBundle/Resources/config/services/installer.yml index 4983c58a..6a43e238 100644 --- a/src/DataDefinitionsBundle/Resources/config/services/installer.yml +++ b/src/DataDefinitionsBundle/Resources/config/services/installer.yml @@ -1,10 +1,10 @@ services: - _defaults: - autowire: true - autoconfigure: true - public: false + _defaults: + autowire: true + autoconfigure: true + public: false - Wvision\Bundle\DataDefinitionsBundle\Installer: - public: true - arguments: - $bundle: "@=service('kernel').getBundle('DataDefinitionsBundle')" + Wvision\Bundle\DataDefinitionsBundle\Installer: + public: true + arguments: + $bundle: "@=service('kernel').getBundle('DataDefinitionsBundle')" diff --git a/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql b/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql index abcff742..5633b2b1 100644 --- a/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql +++ b/src/DataDefinitionsBundle/Resources/install/pimcore/sql/data.sql @@ -1,6 +1,18 @@ CREATE TABLE IF NOT EXISTS `data_definitions_import_log` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `definition` INT NOT NULL, - `o_id` INT NOT NULL + `id` + INT + NOT + NULL + AUTO_INCREMENT + PRIMARY + KEY, + `definition` + INT + NOT + NULL, + `o_id` + INT + NOT + NULL ); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css b/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css index bb84fe85..da4ec80e 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/css/datadefinition.css @@ -6,7 +6,7 @@ background: url(../img/import_definition.svg) center center no-repeat !important; } -body.pimcore_version_10 .data_definitions_nav_icon_import_definition { +body.pimcore_version_11 .data_definitions_nav_icon_import_definition { background: url(../img/import_definition_white.svg) center center no-repeat !important; } @@ -18,7 +18,7 @@ body.pimcore_version_10 .data_definitions_nav_icon_import_definition { background: url(../img/export_definition.svg) center center no-repeat !important; } -body.pimcore_version_10 .data_definitions_nav_icon_export_definition { +body.pimcore_version_11 .data_definitions_nav_icon_export_definition { background: url(../img/export_definition_white.svg) center center no-repeat !important; } diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg b/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg index 552d1a6a..2505ba40 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/img/rules.svg @@ -1 +1,7 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js index 1a2fca67..6b64cf29 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/definition/abstractItem.js @@ -14,6 +14,10 @@ pimcore.registerNS('pimcore.plugin.datadefinitions.definition.abstractItem'); pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.resource.item, { + saveDisabled: function() { + return false; + }, + getPanel: function () { var me = this, panel = new Ext.TabPanel({ @@ -45,7 +49,8 @@ pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.r { text: t('data_definitions_import_definition'), iconCls: 'pimcore_icon_import', - handler: this.upload.bind(this) + handler: this.upload.bind(this), + disabled: this.saveDisabled() }, { text: t('data_definitions_export_definition'), @@ -58,6 +63,7 @@ pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.r { text: t('data_definitions_duplicate_definition'), iconCls: 'pimcore_icon_copy', + disabled: this.saveDisabled(), handler: function () { var id = me.data.id; @@ -88,7 +94,8 @@ pimcore.plugin.datadefinitions.definition.abstractItem = Class.create(coreshop.r { text: t('save'), iconCls: 'pimcore_icon_apply', - handler: this.save.bind(this) + handler: this.save.bind(this), + disabled: this.saveDisabled() }], items: this.getItems() }); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js index 40cb601e..1e1b2799 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/item.js @@ -24,6 +24,10 @@ pimcore.plugin.datadefinitions.export.item = Class.create(pimcore.plugin.datadef providers: [], + saveDisabled: function () { + return !this.data.isWriteable; + }, + getSettings: function () { var classesStore = new Ext.data.JsonStore({ autoDestroy: true, diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js index 0ea8a6c9..d7a2c66b 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export/panel.js @@ -38,6 +38,20 @@ pimcore.plugin.datadefinitions.export.panel = Class.create(coreshop.resource.pan filters: [], runners: [], + + getTopBar: function () { + return [ + { + // add button + text: t('add'), + iconCls: 'pimcore_icon_add', + itemId: 'add-button', + handler: this.addItem.bind(this), + disabled: !pimcore.settings['data-definitions-import-definition-writeable'] + } + ]; + }, + getDefaultGridConfiguration: function () { return { region: 'west', diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js index 37cc4a9c..a594cafa 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/export_provider/csv.js @@ -27,6 +27,13 @@ pimcore.plugin.datadefinitions.export_provider.csv = Class.create(pimcore.plugin fieldLabel: t('data_definitions_csv_enclosure'), anchor: '100%', value: this.data['enclosure'] ? this.data.enclosure : '"' + }, { + xtype: 'textfield', + name: 'escape', + fieldLabel: t('data_definitions_csv_escape'), + anchor: '100%', + maxLength: 1, + value: this.data['escape'] || '' === this.data['escape'] ? this.data.escape : '\\' }]; } }); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js index cd0387a8..b10f623a 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/item.js @@ -25,6 +25,10 @@ pimcore.plugin.datadefinitions.import.item = Class.create(pimcore.plugin.datadef providers: [], + saveDisabled: function () { + return !this.data.isWriteable; + }, + getSettings: function () { var classesStore = new Ext.data.JsonStore({ autoDestroy: true, @@ -145,6 +149,21 @@ pimcore.plugin.datadefinitions.import.item = Class.create(pimcore.plugin.datadef }.bind(this) } }, + { + xtype: 'combo', + fieldLabel: t('data_definitions_persister'), + name: 'persister', + displayField: 'persister', + valueField: 'persister', + store: pimcore.globalmanager.get('data_definitions_persisters'), + value: this.data.persister, + width: 500, + listeners: { + change: function (combo, value) { + this.data.persister = value; + }.bind(this) + } + }, { xtype: 'combo', fieldLabel: t('data_definitions_filter'), diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js index ba43a6a6..de5d7ff5 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import/panel.js @@ -37,6 +37,20 @@ pimcore.plugin.datadefinitions.import.panel = Class.create(coreshop.resource.pan setters: [], filters: [], runners: [], + persisters: [], + + getTopBar: function () { + return [ + { + // add button + text: t('add'), + iconCls: 'pimcore_icon_add', + itemId: 'add-button', + handler: this.addItem.bind(this), + disabled: !pimcore.settings['data-definitions-import-definition-writeable'] + } + ]; + }, getDefaultGridConfiguration: function () { return { @@ -100,6 +114,7 @@ pimcore.plugin.datadefinitions.import.panel = Class.create(coreshop.resource.pan this.setters = []; this.cleaners = []; this.runners = []; + this.persisters = []; config.providers.forEach(function (provider) { this.providers.push([provider]); @@ -129,6 +144,10 @@ pimcore.plugin.datadefinitions.import.panel = Class.create(coreshop.resource.pan this.runners.push([runner]); }.bind(this)); + config.persister.forEach(function (persister) { + this.persisters.push([persister]); + }.bind(this)); + var providerStore = new Ext.data.ArrayStore({ data: this.providers, fields: ['provider'], @@ -192,6 +211,15 @@ pimcore.plugin.datadefinitions.import.panel = Class.create(coreshop.resource.pan pimcore.globalmanager.add('importdefinitions_runners', runnersStore); pimcore.globalmanager.add('data_definitions_runners', runnersStore); + var persistersStore = new Ext.data.ArrayStore({ + data: this.persisters, + fields: ['persister'], + idProperty: 'persister' + }); + + pimcore.globalmanager.add('importdefinitions_persisters', persistersStore); + pimcore.globalmanager.add('data_definitions_persisters', persistersStore); + pimcore.globalmanager.add('data_definitions_import_rule_conditions', config.import_rules.conditions); pimcore.globalmanager.add('data_definitions_import_rule_actions', config.import_rules.actions); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js index d307e1d1..38c4109d 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/import_rule/panel.js @@ -55,14 +55,14 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p layout: 'border', items: this.getItems(), buttons: [{ - text: t('import'), - iconCls: 'pimcore_icon_import', - handler: this.importRules.bind(this) + text: t('import'), + iconCls: 'pimcore_icon_import', + handler: this.importRules.bind(this) }, { text: t('export'), iconCls: 'pimcore_icon_export', handler: this.exportRules.bind(this) - },{ + }, { text: t('save'), iconCls: 'pimcore_icon_apply', handler: this.save.bind(this) @@ -73,7 +73,7 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p return this.layout; }, - exportRules: function() { + exportRules: function () { pimcore.settings.showCloseConfirmation = false; window.setTimeout(function () { pimcore.settings.showCloseConfirmation = true; @@ -93,14 +93,14 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p }); }, - importRules: function() { + importRules: function () { pimcore.helpers.uploadDialog('/admin/data_definitions/import_rules/import', 'file', function (res) { var res = Ext.decode(res.response.responseText); if (res.success) { pimcore.helpers.showNotification(t('success'), t('success'), 'success'); - Ext.Object.each(this.panels, function(key, panel) { + Ext.Object.each(this.panels, function (key, panel) { panel.destroy(); }); @@ -115,25 +115,25 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p }); }, - getData: function() { + getData: function () { var panelData = {}; - this.store.getRange().forEach(function(value, index) { + this.store.getRange().forEach(function (value, index) { panelData[value.id] = value.data; panelData[value.id].id = value.id; }); - var result = Ext.Object.each(this.panels, function(key, panel) { + var result = Ext.Object.each(this.panels, function (key, panel) { panelData[key] = panel.getSaveData(); }); return Object.values(panelData); }, - save: function() { + save: function () { var stopped = false; - var result = Ext.Object.each(this.panels, function(key, panel) { + var result = Ext.Object.each(this.panels, function (key, panel) { if (!panel.isValid()) { stopped = true; return false; @@ -224,8 +224,7 @@ pimcore.plugin.datadefinitions.import_rule.panel = Class.create(coreshop.rules.p if (this.panels[panelKey]) { this.panels[panelKey].activate(); - } - else { + } else { var itemClass = this.getItemClass(); this.panels[panelKey] = new itemClass(this, record.data, panelKey, this.type, record); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js index 7bdc4649..3914e374 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/asseturl.js @@ -16,12 +16,13 @@ pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.asset_url'); pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, { getLayout: function (fromColumn, toColumn, record, config) { var deduplicateByUrlEnabled = Ext.isDefined(config.deduplicate_by_url) ? config.deduplicate_by_url : false + var deduplicateByHashEnabled = Ext.isDefined(config.deduplicate_by_hash) ? config.deduplicate_by_hash : false var relocateExistingCheckbox = Ext.create({ xtype: 'checkbox', fieldLabel: t('data_definitions_relocate_existing_objects'), name: 'relocate_existing_objects', value: config.deduplicate_by_url && Ext.isDefined(config.relocate_existing_objects) ? config.relocate_existing_objects : false, - disabled: deduplicateByUrlEnabled === false + disabled: deduplicateByUrlEnabled === false || deduplicateByHashEnabled === false }); var renameExistingCheckbox = Ext.create({ @@ -29,7 +30,7 @@ pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plu fieldLabel: t('data_definitions_rename_existing_objects'), name: 'rename_existing_objects', value: config.deduplicate_by_url && Ext.isDefined(config.rename_existing_objects) ? config.rename_existing_objects : false, - disabled: deduplicateByUrlEnabled === false + disabled: deduplicateByUrlEnabled === false || deduplicateByHashEnabled === false }); return [{ @@ -87,15 +88,40 @@ pimcore.plugin.datadefinitions.interpreters.asset_url = Class.create(pimcore.plu var isDeduplicateByUrlDisabled = (enabled === false); relocateExistingCheckbox - .setValue(false) - .setDisabled(isDeduplicateByUrlDisabled); + .setValue(false) + .setDisabled(isDeduplicateByUrlDisabled); renameExistingCheckbox - .setValue(false) - .setDisabled(isDeduplicateByUrlDisabled); + .setValue(false) + .setDisabled(isDeduplicateByUrlDisabled); } } }, + { + xtype: 'checkbox', + fieldLabel: t('data_definitions_interpreter_asset_url_deduplicate_by_hash'), + name: 'deduplicate_by_hash', + value: deduplicateByHashEnabled, + listeners: { + change: function (el, enabled) { + var isDeduplicateByHashDisabled = (enabled === false); + + relocateExistingCheckbox + .setValue(false) + .setDisabled(isDeduplicateByHashDisabled); + + renameExistingCheckbox + .setValue(false) + .setDisabled(isDeduplicateByHashDisabled); + } + } + }, + { + xtype: 'checkbox', + fieldLabel: t('data_definitions_interpreter_asset_url_use_content_disposition'), + name: 'use_content_disposition', + value: Ext.isDefined(config.use_content_disposition) ? config.use_content_disposition : false + }, relocateExistingCheckbox, renameExistingCheckbox ]; diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js index 02c1e0d6..b1759cc5 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/carbon.js @@ -14,13 +14,13 @@ pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.carbon'); pimcore.plugin.datadefinitions.interpreters.carbon = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, { - getLayout : function (fromColumn, toColumn, record, config) { + getLayout: function (fromColumn, toColumn, record, config) { return [{ - xtype : 'textfield', + xtype: 'textfield', fieldLabel: t('date_format'), name: 'date_format', width: 500, - value : config.date_format ? config.date_format : null + value: config.date_format ? config.date_format : null }]; } }); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js index e434744c..11d7fffc 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/import_rule.js @@ -49,7 +49,7 @@ pimcore.plugin.datadefinitions.interpreters.import_rule = Class.create(pimcore.p }); }, - close: function(rules) { + close: function (rules) { this.rules = rules; this.window.destroy(); }, diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js new file mode 100644 index 00000000..cd846392 --- /dev/null +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/interpreters/typecasting.js @@ -0,0 +1,41 @@ +/** + * Data Definitions. + * + * LICENSE + * + * This source file is subject to the GNU General Public License version 3 (GPLv3) + * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt + * files that are distributed with this source code. + * + * @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch) + * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + */ + +pimcore.registerNS('pimcore.plugin.datadefinitions.interpreters.type_casting'); + +pimcore.plugin.datadefinitions.interpreters.type_casting = Class.create(pimcore.plugin.datadefinitions.interpreters.abstract, { + getLayout: function (fromColumn, toColumn, record, config) { + const typeStore = new Ext.data.ArrayStore({ + fields: ['key', 'value'], + data: [ + ['int', 'integer'], + ['float', 'float'], + ['string', 'string'], + ['boolean', 'boolean'] + ] + }); + + return [ + { + xtype: 'combo', + fieldLabel: t('type'), + name: 'toType', + displayField: 'value', + valueField: 'key', + store: typeStore, + width: 500, + value: config.Totype ? config.Totype : 'int' + }, + ]; + } +}); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js index 28383438..71f7242c 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_contextmenu.js @@ -1,92 +1,77 @@ -pimcore.registerNS("pimcore.plugin.datadefinitions.export.context_menu"); - -pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin.admin, { - getClassName: function() { - return "pimcore.plugin.datadefinitions.export.context_menu"; - }, - - initialize: function() { - pimcore.plugin.broker.registerPlugin(this); - }, +document.addEventListener(pimcore.events.prepareObjectTreeContextMenu, function (event) { + if (!Ext.ClassManager.get('Executable')) { + Ext.define('Executable', { + extend: 'Ext.data.Model', + fields: [ + {name: 'name', type: 'string'}, + ] + }); + } - prepareObjectTreeContextMenu: function (tree, treeClass, menuItem) { - if (!Ext.ClassManager.get('Executable')) { - Ext.define('Executable', { - extend: 'Ext.data.Model', - fields: [ - {name: 'name', type: 'string'}, - ] - }); - } + const tree = event.detail.menu; - var $this = this; - Ext.create('Ext.data.Store', { - model: 'Executable', - proxy: { - type: 'ajax', - url: '/admin/process_manager/executables/list-by-type', - extraParams: { - type: 'exportdefinition' - }, - reader: { - type: 'json', - rootProperty: 'data' - } + Ext.create('Ext.data.Store', { + model: 'Executable', + proxy: { + type: 'ajax', + url: '/admin/process_manager/executables/list-by-type', + extraParams: { + type: 'exportdefinition' }, - sorters: [{ - property: 'name', - direction: 'ASC' - }], - sortRoot: 'data', - autoLoad: true, - listeners: { - refresh: function(store) { - var exportMenu = []; - store.each(function (executable) { - exportMenu.push({ - text: executable.get('name'), - iconCls: "pimcore_icon_object pimcore_icon_overlay_add", - handler: $this.exportObjects.bind($this, executable, menuItem) - }); - }); - - if (exportMenu) { - tree.add([ - { xtype: 'menuseparator' }, - { - text: t("data_definitions_processmanager_export_from_here"), - iconCls: "pimcore_icon_object pimcore_icon_overlay_download", - menu: exportMenu - } - ]); - } - } + reader: { + type: 'json', + rootProperty: 'data' } - }); - }, + }, + sorters: [{ + property: 'name', + direction: 'ASC' + }], + sortRoot: 'data', + autoLoad: true, + listeners: { + refresh: function (store) { + var exportMenu = []; + store.each(function (executable) { + exportMenu.push({ + text: executable.get('name'), + iconCls: "pimcore_icon_object pimcore_icon_overlay_add", + handler: function (menuItem) { + Ext.Ajax.request({ + url: '/admin/process_manager/executables/run', + params: { + id: executable.id, + startupConfig: Ext.encode({ + root: menuItem.$iid, + }), + csrfToken: pimcore.settings['csrfToken'] + }, + method: 'POST', + success: function (result) { + result = Ext.decode(result.responseText); - exportObjects: function (executable, menuItem) { - Ext.Ajax.request({ - url: '/admin/process_manager/executables/run', - params: { - id: executable.id, - startupConfig: Ext.encode({ - root: menuItem.get('id'), - }), - csrfToken: pimcore.settings['csrfToken'] - }, - method: 'POST', - success: function (result) { - result = Ext.decode(result.responseText); + if (result.success) { + Ext.Msg.alert(t('success'), t('processmanager_executable_started')); + } else { + Ext.Msg.alert(t('error'), result.message); + } + }.bind(this) + }); + } + }); + }); - if (result.success) { - Ext.Msg.alert(t('success'), t('processmanager_executable_started')); - } else { - Ext.Msg.alert(t('error'), result.message); + if (exportMenu) { + tree.add([ + {xtype: 'menuseparator'}, + { + text: t("data_definitions_processmanager_export_from_here"), + iconCls: "pimcore_icon_object pimcore_icon_overlay_download", + menu: exportMenu + } + ]); } - }.bind(this) - }); - } + } + } + }); }); - -new pimcore.plugin.datadefinitions.export.context_menu(); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js index 93d3c975..235a0b4f 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/export_search.js @@ -21,7 +21,7 @@ pimcore.object.search = Class.create(pimcore.object.search, { ] }); } - + this.exportFromHere = new Ext.SplitButton({ text: t('data_definitions_processmanager_export_from_here'), iconCls: "pimcore_icon_object pimcore_icon_overlay_add", @@ -49,7 +49,7 @@ pimcore.object.search = Class.create(pimcore.object.search, { sortRoot: 'data', autoLoad: true, listeners: { - refresh: function(store) { + refresh: function (store) { var exportMenu = []; store.each(function (executable) { exportMenu.push({ diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js index 1e7d4eb9..89fbbb89 100644 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/process_manager/import_definitions.js @@ -11,7 +11,7 @@ * @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) */ -document.addEventListener('processmanager.ready', function() { +document.addEventListener('processmanager.ready', function () { processmanager.executable.types.importdefinition = Class.create(pimcore.plugin.processmanager.executable.abstractType, { getItems: function () { pimcore.globalmanager.get('data_definitions_definitions').load(); @@ -85,11 +85,10 @@ document.addEventListener('processmanager.ready', function() { addDataFromSelector: function (data) { this.setValue(data.fullpath); - console.log(data); }, setValue: function (value) { - var params = '{"file":"web/var/assets' + value + '"}'; + var params = '{"file":"var/assets' + value + '"}'; Ext.getCmp('data_definitions_processmanager_params').setValue(params); } }); diff --git a/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js b/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js index 8246ce92..9208129e 100755 --- a/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js +++ b/src/DataDefinitionsBundle/Resources/public/pimcore/js/startup.js @@ -13,16 +13,18 @@ pimcore.registerNS('pimcore.plugin.data_definitions'); -pimcore.plugin.data_definitions = Class.create(pimcore.plugin.admin, { +pimcore.plugin.data_definitions = Class.create({ getClassName: function () { return 'pimcore.plugin.data_definitions'; }, initialize: function () { - pimcore.plugin.broker.registerPlugin(this); + document.addEventListener(pimcore.events.pimcoreReady, (e) => { + this.pimcoreReady(); + }); }, - pimcoreReady: function (params, broker) { + pimcoreReady: function () { var user = pimcore.globalmanager.get('user'); diff --git a/src/DataDefinitionsBundle/Resources/translations/admin.en.yml b/src/DataDefinitionsBundle/Resources/translations/admin.en.yml index 12e77efd..f784385e 100644 --- a/src/DataDefinitionsBundle/Resources/translations/admin.en.yml +++ b/src/DataDefinitionsBundle/Resources/translations/admin.en.yml @@ -5,6 +5,7 @@ data_definitions_provider_settings: 'Provider Settings' data_definitions_loader: 'Loader' data_definitions_csv_example: 'CSV Example' data_definitions_csv_enclosure: 'Enclosure' +data_definitions_csv_escape: 'Escape' data_definitions_csv_delimiter: 'Delimiter' data_definitions_excel_headers: 'Excel headers' data_definitions_excel_file: 'Excel example file' @@ -89,3 +90,4 @@ data_definitions_invalid_mapping: 'Invalid mapping!' processmanager_type_importdefinition: 'Import Definition' processmanager_type_exportdefinition: 'Export Definition' data_definitions_import_rules: 'Import Rules' +data_definitions_persister: 'Persister' diff --git a/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php b/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php index cb3589e2..694cbf6f 100644 --- a/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php +++ b/src/DataDefinitionsBundle/Rules/Action/ExpressionProcessor.php @@ -32,8 +32,13 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt $this->container = $container; } - public function apply(ImportRuleInterface $rule, Concrete $concrete, $value, array $configuration, array $params = []) - { + public function apply( + ImportRuleInterface $rule, + Concrete $concrete, + $value, + array $configuration, + array $params = [] + ) { $expression = $configuration['expression']; return $this->expressionLanguage->evaluate( diff --git a/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php b/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php index c9fb2ec2..74acfe28 100644 --- a/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php +++ b/src/DataDefinitionsBundle/Rules/Action/ImportRuleProcessorInterface.php @@ -21,5 +21,11 @@ interface ImportRuleProcessorInterface { - public function apply(ImportRuleInterface $rule, Concrete $concrete, $value, array $configuration, array $params = []); + public function apply( + ImportRuleInterface $rule, + Concrete $concrete, + $value, + array $configuration, + array $params = [] + ); } diff --git a/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php b/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php index 70d9230d..c823f45a 100644 --- a/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php +++ b/src/DataDefinitionsBundle/Rules/Action/ObjectProcessor.php @@ -21,8 +21,13 @@ class ObjectProcessor implements ImportRuleProcessorInterface { - public function apply(ImportRuleInterface $rule, Concrete $concrete, $value, array $configuration, array $params = []) - { + public function apply( + ImportRuleInterface $rule, + Concrete $concrete, + $value, + array $configuration, + array $params = [] + ) { $object = Concrete::getById($configuration['object']); if ($object) { diff --git a/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php b/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php index 7c9055fb..753f306b 100644 --- a/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php +++ b/src/DataDefinitionsBundle/Rules/Condition/AbstractConditionChecker.php @@ -25,10 +25,16 @@ abstract class AbstractConditionChecker implements ImportRuleConditionCheckerInterface { - public function isValid(ResourceInterface $subject, RuleInterface $rule, array $configuration, array $params = []): bool - { + public function isValid( + ResourceInterface $subject, + RuleInterface $rule, + array $configuration, + array $params = [] + ): bool { if (!$rule instanceof ImportRuleInterface) { - throw new InvalidArgumentException('Import Rule Condition $subject needs to be instance of ImportRuleInterface'); + throw new InvalidArgumentException( + 'Import Rule Condition $subject needs to be instance of ImportRuleInterface' + ); } Assert::keyExists($params, 'object'); diff --git a/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php b/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php index db056ce8..f326e04c 100644 --- a/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php +++ b/src/DataDefinitionsBundle/Rules/Condition/ExpressionConditionChecker.php @@ -32,8 +32,12 @@ public function __construct(ExpressionLanguage $expressionLanguage, ContainerInt $this->container = $container; } - public function isImportRuleValid(ImportRuleInterface $subject, Concrete $concrete, array $params, array $configuration): bool - { + public function isImportRuleValid( + ImportRuleInterface $subject, + Concrete $concrete, + array $params, + array $configuration + ): bool { $expression = $configuration['expression']; return $this->expressionLanguage->evaluate( diff --git a/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php b/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php index 5a15eefb..e1b4f58f 100644 --- a/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php +++ b/src/DataDefinitionsBundle/Rules/Condition/ImportRuleConditionCheckerInterface.php @@ -22,5 +22,10 @@ interface ImportRuleConditionCheckerInterface extends ConditionCheckerInterface { - public function isImportRuleValid(ImportRuleInterface $subject, Concrete $concrete, array $params, array $configuration): bool; + public function isImportRuleValid( + ImportRuleInterface $subject, + Concrete $concrete, + array $params, + array $configuration + ): bool; } diff --git a/src/DataDefinitionsBundle/Rules/Model/ImportRule.php b/src/DataDefinitionsBundle/Rules/Model/ImportRule.php index 16bf733f..e8fa3a01 100644 --- a/src/DataDefinitionsBundle/Rules/Model/ImportRule.php +++ b/src/DataDefinitionsBundle/Rules/Model/ImportRule.php @@ -24,7 +24,7 @@ class ImportRule implements ImportRuleInterface protected int $id; - public function getId() + public function getId(): ?int { return $this->id; } diff --git a/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php b/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php index 4fc7a50a..781f987a 100644 --- a/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php +++ b/src/DataDefinitionsBundle/Runner/ExportRunnerInterface.php @@ -16,12 +16,11 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Runner; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinitionInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\RunnerContextInterface; interface ExportRunnerInterface { - public function exportPreRun(Concrete $object, array $data, ExportDefinitionInterface $definition, array $params); + public function exportPreRun(RunnerContextInterface $context); - public function exportPostRun(Concrete $object, array $data, ExportDefinitionInterface $definition, array $params); + public function exportPostRun(RunnerContextInterface $context); } diff --git a/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php b/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php new file mode 100644 index 00000000..27aa57b7 --- /dev/null +++ b/src/DataDefinitionsBundle/Runner/ImportStartFinishRunnerInterface.php @@ -0,0 +1,26 @@ +getAllowedGroupIds(); if ($allowedGroupIds) { - $list->setCondition('ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', - [$field->getStoreId()]); + $list->setCondition( + 'ID in ('.implode(',', $allowedGroupIds).') AND storeId = ?', + [$field->getStoreId()] + ); } else { $list->setCondition('storeId = ?', [$field->getStoreId()]); } diff --git a/src/DataDefinitionsBundle/Service/StorageLocator.php b/src/DataDefinitionsBundle/Service/StorageLocator.php new file mode 100644 index 00000000..851611c8 --- /dev/null +++ b/src/DataDefinitionsBundle/Service/StorageLocator.php @@ -0,0 +1,35 @@ +locator = $locator; + } + + public function getStorage(string $name): FilesystemOperator + { + return $this->locator->get($name); + } +} diff --git a/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php b/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php index cad06b80..ca72a938 100644 --- a/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php +++ b/src/DataDefinitionsBundle/Setter/ClassificationStoreFieldGetter.php @@ -18,19 +18,18 @@ use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Classificationstore; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Tool; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; class ClassificationStoreFieldGetter implements GetterInterface { - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $classificationStoreGetter = sprintf('get%s', ucfirst($map->getFromColumn())); + $classificationStoreGetter = sprintf('get%s', ucfirst($context->getMapping()->getFromColumn())); - if (method_exists($object, $classificationStoreGetter)) { - $classificationStore = $object->$classificationStoreGetter(); + if (method_exists($context->getObject(), $classificationStoreGetter)) { + $classificationStore = $context->getObject()->$classificationStoreGetter(); if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); @@ -48,8 +47,11 @@ public function get(Concrete $object, ExportMapping $map, $data) $keyConfig = DataObject\Classificationstore\KeyConfig::getById($keyRelation->getKeyId()); foreach (Tool::getValidLanguages() as $language) { - $value = $classificationStore->getLocalizedKeyValue($groupId, $keyConfig->getId(), - $language); + $value = $classificationStore->getLocalizedKeyValue( + $groupId, + $keyConfig->getId(), + $language + ); if (is_null($value)) { continue; diff --git a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php index fff2b192..3559e18b 100644 --- a/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php +++ b/src/DataDefinitionsBundle/Setter/ClassificationStoreSetter.php @@ -17,54 +17,53 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; use Pimcore\Model\DataObject\Classificationstore; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; class ClassificationStoreSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $mapConfig = $map->getSetterConfig(); + $mapConfig = $context->getMapping()->getSetterConfig(); $fieldName = $mapConfig['field']; $keyConfig = (int)$mapConfig['keyConfig']; $groupConfig = (int)$mapConfig['groupConfig']; $classificationStoreGetter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $classificationStoreGetter)) { - $classificationStore = $object->$classificationStoreGetter(); + if (method_exists($context->getObject(), $classificationStoreGetter)) { + $classificationStore = $context->getObject()->$classificationStoreGetter(); if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); - if (!$groups[$groupConfig]) { + if (!($groups[$groupConfig] ?? false)) { $groups[$groupConfig] = true; $classificationStore->setActiveGroups($groups); } - $classificationStore->setLocalizedKeyValue($groupConfig, $keyConfig, $value); + $classificationStore->setLocalizedKeyValue($groupConfig, $keyConfig, $context->getValue()); } } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $mapConfig = $map->getGetterConfig(); + $mapConfig = $context->getMapping()->getGetterConfig(); $fieldName = $mapConfig['field']; $keyConfig = (int)$mapConfig['keyConfig']; $groupConfig = (int)$mapConfig['groupConfig']; $classificationStoreGetter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $classificationStoreGetter)) { - $classificationStore = $object->$classificationStoreGetter(); + if (method_exists($context->getObject(), $classificationStoreGetter)) { + $classificationStore = $context->getObject()->$classificationStoreGetter(); if ($classificationStore instanceof Classificationstore) { $groups = $classificationStore->getActiveGroups(); - if (!$groups[$groupConfig]) { + if (!($groups[$groupConfig] ?? false)) { $groups[$groupConfig] = true; $classificationStore->setActiveGroups($groups); } diff --git a/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php b/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php index 7872748e..84486df4 100644 --- a/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php +++ b/src/DataDefinitionsBundle/Setter/CoreShop/StorePriceSetter.php @@ -19,10 +19,9 @@ use CoreShop\Component\Core\Model\StoreInterface; use CoreShop\Component\Store\Repository\StoreRepositoryInterface; use InvalidArgumentException; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface; use function is_array; @@ -35,9 +34,9 @@ public function __construct(StoreRepositoryInterface $storeRepository) $this->storeRepository = $storeRepository; } - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - $config = $map->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return; @@ -50,19 +49,19 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $setter = sprintf('set%s', ucfirst($map->getToColumn())); + $setter = sprintf('set%s', ucfirst($context->getMapping()->getToColumn())); - if (!method_exists($object, $setter)) { + if (!method_exists($context->getObject(), $setter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $setter)); } - $object->$setter($value, $store); + $context->getObject()->$setter($context->getValue(), $store); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return []; @@ -77,13 +76,13 @@ public function get(Concrete $object, ExportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $getter = sprintf('get%s', ucfirst($map->getFromColumn())); + $getter = sprintf('get%s', ucfirst($context->getMapping()->getFromColumn())); - if (!method_exists($object, $getter)) { + if (!method_exists($context->getObject(), $getter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $getter)); } - $values[$store->getId()] = $object->$getter($store); + $values[$store->getId()] = $context->getObject()->$getter($store); } return $values; diff --git a/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php b/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php index 3ed28c76..66e605c4 100644 --- a/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php +++ b/src/DataDefinitionsBundle/Setter/CoreShop/StoreValuesSetter.php @@ -19,10 +19,9 @@ use CoreShop\Component\Core\Model\StoreInterface; use CoreShop\Component\Store\Repository\StoreRepositoryInterface; use InvalidArgumentException; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; use Wvision\Bundle\DataDefinitionsBundle\Setter\SetterInterface; use function is_array; @@ -35,9 +34,9 @@ public function __construct(StoreRepositoryInterface $storeRepository) $this->storeRepository = $storeRepository; } - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - $config = $map->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return; @@ -50,19 +49,19 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $setter = sprintf('set%sOfType', ucfirst($map->getToColumn())); + $setter = sprintf('set%sOfType', ucfirst($context->getMapping()->getToColumn())); - if (!method_exists($object, $setter)) { + if (!method_exists($context->getObject(), $setter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $setter)); } - $object->$setter($config['type'], $value, $store); + $context->getObject()->$setter($config['type'], $context->getValue(), $store); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); if (!array_key_exists('stores', $config) || !is_array($config['stores'])) { return []; @@ -77,13 +76,13 @@ public function get(Concrete $object, ExportMapping $map, $data) throw new InvalidArgumentException(sprintf('Store with ID %s not found', $config['store'])); } - $getter = sprintf('get%sOfType', ucfirst($map->getFromColumn())); + $getter = sprintf('get%sOfType', ucfirst($context->getMapping()->getFromColumn())); - if (!method_exists($object, $getter)) { + if (!method_exists($context->getObject(), $getter)) { throw new InvalidArgumentException(sprintf('Expected a %s function but can not find it', $getter)); } - $values[$store->getId()] = $object->$getter($config['type'], $store); + $values[$store->getId()] = $context->getObject()->$getter($config['type'], $store); } return $values; diff --git a/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php b/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php index ca49c52f..a626a370 100644 --- a/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php +++ b/src/DataDefinitionsBundle/Setter/FieldCollectionSetter.php @@ -16,26 +16,24 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Exception; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Fieldcollection; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData as AbstractFieldCollection; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; class FieldCollectionSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $keyParts = explode('~', $map->getToColumn()); + $keyParts = explode('~', $context->getMapping()->getToColumn()); - $config = $map->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); $keys = $config['keys']; $fieldName = $config['field']; $class = $config['class']; $keys = explode(',', $keys); - $fieldCollectionClass = 'Pimcore\Model\DataObject\Fieldcollection\Data\\' . ucfirst($class); + $fieldCollectionClass = 'Pimcore\Model\DataObject\Fieldcollection\Data\\'.ucfirst($class); $field = $keyParts[3]; $mappedKeys = []; @@ -51,8 +49,8 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $getter = sprintf('get%s', ucfirst($fieldName)); $setter = sprintf('set%s', ucfirst($fieldName)); - if (method_exists($object, $getter)) { - $fieldCollection = $object->$getter(); + if (method_exists($context->getObject(), $getter)) { + $fieldCollection = $context->getObject()->$getter(); if (!$fieldCollection instanceof Fieldcollection) { $fieldCollection = new Fieldcollection(); @@ -62,9 +60,13 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $found = false; foreach ($items as $item) { - if (is_a($item, $fieldCollectionClass) && $this->isValidKey($mappedKeys, $item, $data)) { + if (is_a($item, $fieldCollectionClass) && $this->isValidKey( + $mappedKeys, + $item, + $context->getDataRow() + )) { if ($item instanceof AbstractFieldCollection) { - $item->setValue($field, $value); + $item->setValue($field, $context->getValue()); } $found = true; @@ -77,24 +79,24 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void if ($item instanceof AbstractFieldCollection) { foreach ($mappedKeys as $key) { - $item->setValue($key['to'], $data[$key['from']]); + $item->setValue($key['to'], $context->getDataRow()[$key['from']]); } - $item->setValue($field, $value); + $item->setValue($field, $context->getValue()); $fieldCollection->add($item); } } - $object->$setter($fieldCollection); + $context->getObject()->$setter($fieldCollection); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $keyParts = explode('~', $map->getFromColumn()); + $keyParts = explode('~', $context->getMapping()->getFromColumn()); - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); $fieldName = $config['field']; $class = $config['class']; $fieldCollectionClass = 'Pimcore\Model\DataObject\Fieldcollection\Data\\'.ucfirst($class); @@ -102,8 +104,8 @@ public function get(Concrete $object, ExportMapping $map, $data) $getter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $getter)) { - $fieldCollection = $object->$getter(); + if (method_exists($context->getObject(), $getter)) { + $fieldCollection = $context->getObject()->$getter(); if (!$fieldCollection instanceof Fieldcollection) { return null; diff --git a/src/DataDefinitionsBundle/Setter/KeySetter.php b/src/DataDefinitionsBundle/Setter/KeySetter.php index 4a7cb05c..22d416e2 100644 --- a/src/DataDefinitionsBundle/Setter/KeySetter.php +++ b/src/DataDefinitionsBundle/Setter/KeySetter.php @@ -17,19 +17,18 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; use Pimcore\Model\DataObject; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; class KeySetter implements SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $setter = explode('~', $map->getToColumn()); + $setter = explode('~', $context->getMapping()->getToColumn()); $setter = preg_replace('/^o_/', '', $setter[0]); $setter = sprintf('set%s', ucfirst($setter)); - if (method_exists($object, $setter)) { - $object->$setter(DataObject\Service::getValidKey($value, "object")); + if (method_exists($context->getObject(), $setter)) { + $context->getObject()->$setter(DataObject\Service::getValidKey($context->getValue(), "object")); } } } diff --git a/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php b/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php index 98ddddfb..d1355e89 100644 --- a/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php +++ b/src/DataDefinitionsBundle/Setter/LocalizedfieldSetter.php @@ -16,34 +16,33 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; class LocalizedfieldSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $config = $map->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); - $setter = explode('~', $map->getToColumn()); + $setter = explode('~', $context->getMapping()->getToColumn()); $setter = sprintf('set%s', ucfirst($setter[0])); - if (method_exists($object, $setter)) { - $object->$setter($value, $config['language']); + if (method_exists($context->getObject(), $setter)) { + $context->getObject()->$setter($context->getValue(), $config['language']); } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); - $getter = explode('~', $map->getFromColumn()); + $getter = explode('~', $context->getMapping()->getFromColumn()); $getter = sprintf('get%s', ucfirst($getter[0])); - if (method_exists($object, $getter)) { - return $object->$getter($config['language']); + if (method_exists($context->getObject(), $getter)) { + return $context->getObject()->$getter($config['language']); } return null; diff --git a/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php b/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php index ef9bee12..95335c52 100644 --- a/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php +++ b/src/DataDefinitionsBundle/Setter/ObjectTypeSetter.php @@ -17,25 +17,25 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; class ObjectTypeSetter implements SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - if ($value === Concrete::OBJECT_TYPE_FOLDER) { - $object->setType(Concrete::OBJECT_TYPE_FOLDER); + if ($context->getValue() === Concrete::OBJECT_TYPE_FOLDER) { + $context->getObject()->setType(Concrete::OBJECT_TYPE_FOLDER); return; } - if ($value === Concrete::OBJECT_TYPE_VARIANT) { - $object->setType(Concrete::OBJECT_TYPE_VARIANT); + if ($context->getValue() === Concrete::OBJECT_TYPE_VARIANT) { + $context->getObject()->setType(Concrete::OBJECT_TYPE_VARIANT); return; } - $object->setType(Concrete::OBJECT_TYPE_OBJECT); + $context->getObject()->setType(Concrete::OBJECT_TYPE_OBJECT); } } diff --git a/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php b/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php index 45ffe440..06d9028a 100644 --- a/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php +++ b/src/DataDefinitionsBundle/Setter/ObjectbrickSetter.php @@ -16,21 +16,19 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Objectbrick; use Pimcore\Model\DataObject\Objectbrick\Data\AbstractData; +use Wvision\Bundle\DataDefinitionsBundle\Context\GetterContextInterface; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Getter\GetterInterface; -use Wvision\Bundle\DataDefinitionsBundle\Model\ExportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; -use Wvision\Bundle\DataDefinitionsBundle\Model\MappingInterface; class ObjectbrickSetter implements SetterInterface, GetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data) + public function set(SetterContextInterface $context) { - $keyParts = explode('~', $map->getToColumn()); + $keyParts = explode('~', $context->getMapping()->getToColumn()); - $config = $map->getSetterConfig(); + $config = $context->getMapping()->getSetterConfig(); $fieldName = $config['brickField']; $class = $config['class']; $brickField = $keyParts[3]; @@ -38,12 +36,12 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) $brickGetter = sprintf('get%s', ucfirst($fieldName)); $brickSetter = sprintf('set%s', ucfirst($fieldName)); - if (method_exists($object, $brickGetter)) { - $brick = $object->$brickGetter(); + if (method_exists($context->getObject(), $brickGetter)) { + $brick = $context->getObject()->$brickGetter(); if (!$brick instanceof Objectbrick) { - $brick = new Objectbrick($object, $fieldName); - $object->$brickSetter($brick); + $brick = new Objectbrick($context->getObject(), $fieldName); + $context->getObject()->$brickSetter($brick); } if ($brick instanceof Objectbrick) { @@ -55,7 +53,7 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) if (!$brickFieldObject instanceof AbstractData) { $brickFieldObjectClass = 'Pimcore\Model\DataObject\Objectbrick\Data\\'.$class; - $brickFieldObject = new $brickFieldObjectClass($object); + $brickFieldObject = new $brickFieldObjectClass($context->getObject()); $brick->$brickClassSetter($brickFieldObject); } @@ -63,25 +61,25 @@ public function set(Concrete $object, $value, ImportMapping $map, $data) $setter = sprintf('set%s', ucfirst($brickField)); if (method_exists($brickFieldObject, $setter)) { - $brickFieldObject->$setter($value); + $brickFieldObject->$setter($context->getValue()); } } } } - public function get(Concrete $object, ExportMapping $map, $data) + public function get(GetterContextInterface $context) { - $keyParts = explode('~', $map->getFromColumn()); + $keyParts = explode('~', $context->getMapping()->getFromColumn()); - $config = $map->getGetterConfig(); + $config = $context->getMapping()->getGetterConfig(); $fieldName = $config['brickField']; $class = $config['class']; $brickField = $keyParts[3]; $brickGetter = sprintf('get%s', ucfirst($fieldName)); - if (method_exists($object, $brickGetter)) { - $brick = $object->$brickGetter(); + if (method_exists($context->getObject(), $brickGetter)) { + $brick = $context->getObject()->$brickGetter(); if (!$brick instanceof Objectbrick) { return; @@ -95,7 +93,7 @@ public function get(Concrete $object, ExportMapping $map, $data) if (!$brickFieldObject instanceof AbstractData) { $brickFieldObjectClass = 'Pimcore\Model\DataObject\Objectbrick\Data\\'.$class; - $brickFieldObject = new $brickFieldObjectClass($object); + $brickFieldObject = new $brickFieldObjectClass($context->getObject()); $brick->$brickClassSetter($brickFieldObject); } diff --git a/src/DataDefinitionsBundle/Setter/RelationSetter.php b/src/DataDefinitionsBundle/Setter/RelationSetter.php index ff409848..2cf943fb 100644 --- a/src/DataDefinitionsBundle/Setter/RelationSetter.php +++ b/src/DataDefinitionsBundle/Setter/RelationSetter.php @@ -16,18 +16,17 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; class RelationSetter implements SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, $data): void + public function set(SetterContextInterface $context): void { - $fieldName = $map->getToColumn(); + $fieldName = $context->getMapping()->getToColumn(); $getter = sprintf('get%s', ucfirst($fieldName)); $setter = sprintf('set%s', ucfirst($fieldName)); - $existingElements = $object->$getter(); + $existingElements = $context->getObject()->$getter(); if (!is_array($existingElements)) { $existingElements = []; } @@ -38,6 +37,7 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void $existingKeys[] = (string)$existingElement; } + $value = $context->getValue(); if (!is_iterable($value)) { $value = [$value]; @@ -51,6 +51,6 @@ public function set(Concrete $object, $value, ImportMapping $map, $data): void } } - $object->$setter($existingElements); + $context->getObject()->$setter($existingElements); } } diff --git a/src/DataDefinitionsBundle/Setter/SetterInterface.php b/src/DataDefinitionsBundle/Setter/SetterInterface.php index 1cec7bd4..9b19b17e 100644 --- a/src/DataDefinitionsBundle/Setter/SetterInterface.php +++ b/src/DataDefinitionsBundle/Setter/SetterInterface.php @@ -16,10 +16,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Setter; -use Pimcore\Model\DataObject\Concrete; -use Wvision\Bundle\DataDefinitionsBundle\Model\ImportMapping; +use Wvision\Bundle\DataDefinitionsBundle\Context\SetterContextInterface; interface SetterInterface { - public function set(Concrete $object, $value, ImportMapping $map, array $data); + public function set(SetterContextInterface $context); } diff --git a/src/Kernel.php b/src/Kernel.php index 2e2ba14d..4b84caec 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -17,16 +17,16 @@ class Kernel extends PimcoreKernel { - public function registerBundlesToCollection(BundleCollection $collection) + public function registerBundlesToCollection(BundleCollection $collection): void { $collection->addBundle(new \Wvision\Bundle\DataDefinitionsBundle\DataDefinitionsBundle()); $collection->addBundle(new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle()); } - public function boot() + public function boot(): void { - \Pimcore::setKernel($this); - parent::boot(); + + \Pimcore::setKernel($this); } } diff --git a/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php b/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php index a691ed8e..94a74ed1 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Domain/PimcoreContext.php @@ -64,7 +64,7 @@ public function thereAreUnpublishedDataObjects(int $count, ClassDefinition $defi * @var DataObject\Listing $list */ $list = $fqcn::getList(); - $list->setCondition('o_published=0'); + $list->setCondition('published=0'); Assert::eq($count, $list->getTotalCount(), sprintf( @@ -88,7 +88,7 @@ public function thereArePublishedDataObjects(int $count, ClassDefinition $defini * @var DataObject\Listing $list */ $list = $fqcn::getList(); - $list->setCondition('o_published=1'); + $list->setCondition('published=1'); Assert::eq($count, $list->getTotalCount(), sprintf( diff --git a/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php b/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php index fa471a0c..2709f863 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Hook/IMSetupContext.php @@ -17,6 +17,8 @@ use Behat\Behat\Context\Context; use Wvision\Bundle\DataDefinitionsBundle\Installer; use Pimcore\Db\PhpArrayFileTable; +use Wvision\Bundle\DataDefinitionsBundle\Model\ExportDefinition; +use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; final class IMSetupContext implements Context { @@ -46,18 +48,30 @@ public static function setupImportDefinitions() */ public function purgeDefinitions() { - if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php')) { - unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php'); - } + $importDefinitions = new ImportDefinition\Listing(); - if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php')) { - unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php'); + foreach ($importDefinitions->getObjects() as $definition) { + $definition->delete(); } - $obj = new PhpArrayFileTable(); - $refObject = new \ReflectionObject($obj); - $refProperty = $refObject->getProperty('tables'); - $refProperty->setAccessible(true); - $refProperty->setValue(null, []); + $exportDefinitions = new ExportDefinition\Listing(); + + foreach ($exportDefinitions->getObjects() as $definition) { + $definition->delete(); + } +// +// if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php')) { +// unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/importdefinitions.php'); +// } +// +// if (file_exists(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php')) { +// unlink(PIMCORE_CONFIGURATION_DIRECTORY.'/exportdefinitions.php'); +// } +// +// $obj = new PhpArrayFileTable(); +// $refObject = new \ReflectionObject($obj); +// $refProperty = $refObject->getProperty('tables'); +// $refProperty->setAccessible(true); +// $refProperty->setValue(null, []); } } diff --git a/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php b/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php index b6b1c4fc..5dd74b03 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Hook/PimcoreDaoContext.php @@ -23,14 +23,24 @@ use Pimcore\Model\DataObject\Fieldcollection; use Pimcore\Model\DataObject\Listing; use Pimcore\Model\DataObject\Objectbrick; +use Symfony\Component\HttpKernel\KernelInterface; final class PimcoreDaoContext implements Context { - private $connection; + public function __construct( + private Connection $connection, + private KernelInterface $kernel, + ) + { + + } - public function __construct(Connection $connection) + /** + * @BeforeScenario + */ + public function setKernel(): void { - $this->connection = $connection; + \Pimcore::setKernel($this->kernel); } /** @@ -39,14 +49,14 @@ public function __construct(Connection $connection) public function purgeObjects() { Cache::clearAll(); - Cache\Runtime::clear(); + Cache\RuntimeCache::clear(); /** * @var Listing $list */ $list = new DataObject\Listing(); $list->setUnpublished(true); - $list->setCondition('o_id <> 1'); + $list->setCondition('id <> 1'); $list->load(); foreach ($list->getObjects() as $obj) { @@ -60,7 +70,7 @@ public function purgeObjects() public function purgeAssets() { Cache::clearAll(); - Cache\Runtime::clear(); + Cache\RuntimeCache::clear(); /** * @var Asset\Listing $list @@ -107,7 +117,7 @@ public function purgeBricks() public function clearRuntimeCacheScenario() { //Clearing it here is totally fine, since each scenario has its own separated context of objects - \Pimcore\Cache\Runtime::clear(); + Cache\RuntimeCache::clear(); } /** @@ -117,7 +127,7 @@ public function clearRuntimeCacheStep() { //We should not clear Pimcore Objects here, otherwise we lose the reference to it //and end up having the same object twice - $copy = \Pimcore\Cache\Runtime::getInstance()->getArrayCopy(); + $copy = \Pimcore\Cache\RuntimeCache::getInstance()->getArrayCopy(); $keepItems = []; foreach ($copy as $key => $value) { @@ -126,7 +136,7 @@ public function clearRuntimeCacheStep() } } - \Pimcore\Cache\Runtime::clear($keepItems); + \Pimcore\Cache\RuntimeCache::clear($keepItems); } /** diff --git a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php index 0385632a..bd92c194 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Setup/PimcoreClassContext.php @@ -79,7 +79,7 @@ public function createClassNamed($className) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [ + "children": [ { "fieldtype": "panel", "labelWidth": 100, @@ -95,7 +95,7 @@ public function createClassNamed($className) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [], + "children": [], "locked": false } ], @@ -159,7 +159,7 @@ public function createBrickNamed($brickName) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [ + "children": [ { "fieldtype": "panel", "labelWidth": 100, @@ -175,7 +175,7 @@ public function createBrickNamed($brickName) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [], + "children": [], "locked": false } ], @@ -217,7 +217,7 @@ public function createCollectionNamed($collection) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [ + "children": [ { "fieldtype": "panel", "labelWidth": 100, @@ -233,7 +233,7 @@ public function createCollectionNamed($collection) "bodyStyle": null, "datatype": "layout", "permissions": null, - "childs": [], + "children": [], "locked": false } ], @@ -318,9 +318,9 @@ public function definitionHasExternalImageField($definition, $name) $jsonDefinition = sprintf(' { "fieldtype": "externalImage", - "previewWidth": "", - "inputWidth": "", - "previewHeight": "", + "previewWidth": null, + "inputWidth": null, + "previewHeight": null, "name": "%s", "title": "%s", "tooltip": "", @@ -522,7 +522,7 @@ public function definitionHasLocalizedInputField($definition, $name) { "fieldtype": "localizedfields", "phpdocType": "\\Pimcore\\Model\\DataObject\\Localizedfield", - "childs": [ + "children": [ { "fieldtype": "input", "width": null, @@ -587,7 +587,7 @@ public function definitionHasLocalizedTextareaField($definition, $name) { "fieldtype": "localizedfields", "phpdocType": "\\Pimcore\\Model\\DataObject\\Localizedfield", - "childs": [ + "children": [ { "fieldtype": "textarea", "width": "", diff --git a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php index 42b58ffb..dce8bc31 100644 --- a/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php +++ b/tests/DataDefinitionsBundle/Behat/Context/Transform/PimcoreClassContext.php @@ -15,10 +15,9 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Behat\Context\Transform; use Behat\Behat\Context\Context; -use CoreShop\Component\Pimcore\DataObject\ClassLoader; use Wvision\Bundle\DataDefinitionsBundle\Behat\Service\ClassStorageInterface; use Wvision\Bundle\DataDefinitionsBundle\Behat\Service\SharedStorageInterface; -use Pimcore\Cache\Runtime; +use Pimcore\Cache\RuntimeCache; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Concrete; @@ -43,12 +42,10 @@ public function __construct( */ public function class($name) { - Runtime::clear(); + RuntimeCache::clear(); $name = $this->classStorage->get($name); - ClassLoader::forceLoadDataObjectClass($name); - $classDefinition = ClassDefinition::getByName($name); Assert::notNull($classDefinition, sprintf('Class Definition for class with name %s not found', $name)); @@ -132,7 +129,7 @@ public function objectOfTheClass($name) */ public function definition() { - Runtime::clear(); + RuntimeCache::clear(); $name = $this->sharedStorage->get('pimcore_definition_name'); $class = $this->sharedStorage->get('pimcore_definition_class'); diff --git a/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml b/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml index aee25a91..e88d3ecd 100644 --- a/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml +++ b/tests/DataDefinitionsBundle/Behat/Resources/config/profiles/default.yml @@ -9,6 +9,6 @@ default: FriendsOfBehat\SymfonyExtension: bootstrap: behat-bootstrap.php kernel: - path: src/Kernel.php - class: Kernel + path: src/BehatKernel.php + class: BehatKernel environment: test diff --git a/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml b/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml index 8b689ee8..d11a7946 100644 --- a/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml +++ b/tests/DataDefinitionsBundle/Behat/Resources/config/services/contexts/hook.yml @@ -6,6 +6,7 @@ services: class: Wvision\Bundle\DataDefinitionsBundle\Behat\Context\Hook\PimcoreDaoContext arguments: - '@doctrine.dbal.default_connection' + - '@kernel' tags: - { name: fob.context_service } diff --git a/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php b/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php index 76a38ea7..c28eee64 100644 --- a/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php +++ b/tests/DataDefinitionsBundle/Behat/Service/Filter/SimpleFilter.php @@ -3,13 +3,14 @@ namespace Wvision\Bundle\DataDefinitionsBundle\Behat\Service\Filter; use Pimcore\Model\DataObject\Concrete; +use Wvision\Bundle\DataDefinitionsBundle\Context\FilterContextInterface; use Wvision\Bundle\DataDefinitionsBundle\Filter\FilterInterface; use Wvision\Bundle\DataDefinitionsBundle\Model\DataDefinitionInterface; class SimpleFilter implements FilterInterface { - public function filter(DataDefinitionInterface $definition, array $data, Concrete $object): bool + public function filter(FilterContextInterface $context): bool { - return $data['doFilter'] !== '1'; + return $context->getDataRow()['doFilter'] !== '1'; } }