Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Sylius 1.7 again #230

Merged
merged 5 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ jobs:
tests:
runs-on: ubuntu-latest

name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}, Node ${{ matrix.node }}"
name: "PHP ${{ matrix.php }}, MySQL ${{ matrix.mysql }}, Sylius ${{ matrix.sylius }}"

strategy:
fail-fast: false
matrix:
php: [7.4, 7.3]
node: [10.x]
mysql: [5.7, 8.0]
sylius: [1.7.*, 1.8.*]

exclude:
-
Expand Down Expand Up @@ -91,9 +92,32 @@ jobs:
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-composer-

-
name: Prepare migrations for Sylius 1.7
if: matrix.sylius == '1.7.*'
run: |
cp etc/sylius17/migrations/* tests/Application/src/Migrations/
cp src/Migrations/* tests/Application/src/Migrations/
sed -i -- 's/Sylius\\RefundPlugin\\Migrations/DoctrineMigrations/g' tests/Application/src/Migrations/*
cp etc/sylius17/bundles.php tests/Application/config/
cp etc/sylius17/doctrine_migrations.yaml tests/Application/config/packages/
cp etc/sylius17/security.yaml tests/Application/config/packages/
rm tests/Application/config/packages//lexik_jwt_authentication.yaml
rm tests/Application/config/routes/sylius_api.yaml

- name: Prepare migrations for Sylius 1.8
if: matrix.sylius == '1.8.*'
run: |
composer require sylius-labs/doctrine-migrations-extra-bundle --no-interaction --no-update

-
name: Install Sylius version
run: |
composer require "sylius/sylius:${{ matrix.sylius }}" --no-update

-
name: Install PHP dependencies
run: composer install --no-interaction
run: composer update --no-interaction

-
name: Get Yarn cache directory
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"knplabs/knp-snappy-bundle": "^1.7",
"myclabs/php-enum": "^1.7",
"sylius/resource-bundle": "^1.6",
"sylius/sylius": "^1.8",
"sylius/sylius": "^1.7",
"symfony/messenger": "^4.4"
},
"require-dev": {
Expand Down
58 changes: 58 additions & 0 deletions etc/sylius17/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true],
Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true],
Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true],
Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true],
Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true],
Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true],
Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true],
Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true],
Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true],
Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true],
Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true],
Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true],
Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true],
Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true],
Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true],
Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true],
Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true],
Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true],
Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true],
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true],
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true],
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true],
Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true],
Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['all' => true],
Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true],
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Sylius\RefundPlugin\SyliusRefundPlugin::class => ['all' => true],
Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
];
3 changes: 3 additions & 0 deletions etc/sylius17/doctrine_migrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
doctrine_migrations:
dir_name: "%kernel.project_dir%/src/Migrations"
namespace: DoctrineMigrations
40 changes: 40 additions & 0 deletions etc/sylius17/migrations/Version20200110132702.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200110132702 extends AbstractMigration
{
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_channel ADD menu_taxon_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE sylius_channel ADD CONSTRAINT FK_16C8119EF242B1E6 FOREIGN KEY (menu_taxon_id) REFERENCES sylius_taxon (id) ON DELETE SET NULL');
$this->addSql('CREATE INDEX IDX_16C8119EF242B1E6 ON sylius_channel (menu_taxon_id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_channel DROP FOREIGN KEY FK_16C8119EF242B1E6');
$this->addSql('DROP INDEX IDX_16C8119EF242B1E6 ON sylius_channel');
$this->addSql('ALTER TABLE sylius_channel DROP menu_taxon_id');
}
}
37 changes: 37 additions & 0 deletions etc/sylius17/migrations/Version20200122082429.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200122082429 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE sylius_channel_countries (channel_id INT NOT NULL, country_id INT NOT NULL, INDEX IDX_D96E51AE72F5A1AA (channel_id), INDEX IDX_D96E51AEF92F3E70 (country_id), PRIMARY KEY(channel_id, country_id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE sylius_channel_countries ADD CONSTRAINT FK_D96E51AE72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE sylius_channel_countries ADD CONSTRAINT FK_D96E51AEF92F3E70 FOREIGN KEY (country_id) REFERENCES sylius_country (id) ON DELETE CASCADE');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('DROP TABLE sylius_channel_countries');
}
}
25 changes: 25 additions & 0 deletions etc/sylius17/migrations/Version20200202104152.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200202104152 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_shipment ADD shipped_at DATETIME DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_shipment DROP shipped_at');
}
}
102 changes: 102 additions & 0 deletions etc/sylius17/security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
parameters:
sylius.security.admin_regex: "^/admin"
sylius.security.api_regex: "^/api"
sylius.security.shop_regex: "^/(?!admin|api/.*|api$|media/.*)[^/]++"

security:
providers:
sylius_admin_user_provider:
id: sylius.admin_user_provider.email_or_name_based
sylius_shop_user_provider:
id: sylius.shop_user_provider.email_or_name_based
encoders:
Sylius\Component\User\Model\UserInterface: argon2i
firewalls:
admin:
switch_user: true
context: admin
pattern: "%sylius.security.admin_regex%"
provider: sylius_admin_user_provider
form_login:
provider: sylius_admin_user_provider
login_path: sylius_admin_login
check_path: sylius_admin_login_check
failure_path: sylius_admin_login
default_target_path: sylius_admin_dashboard
use_forward: false
use_referer: true
csrf_token_generator: security.csrf.token_manager
csrf_parameter: _csrf_admin_security_token
csrf_token_id: admin_authenticate
remember_me:
secret: "%env(APP_SECRET)%"
path: /admin
name: APP_ADMIN_REMEMBER_ME
lifetime: 31536000
remember_me_parameter: _remember_me
logout:
path: sylius_admin_logout
target: sylius_admin_login
anonymous: true

oauth_token:
pattern: "%sylius.security.api_regex%/oauth/v2/token"
security: false

api:
pattern: "%sylius.security.api_regex%/.*"
provider: sylius_admin_user_provider
fos_oauth: true
stateless: true
anonymous: true

shop:
switch_user: { role: ROLE_ALLOWED_TO_SWITCH }
context: shop
pattern: "%sylius.security.shop_regex%"
provider: sylius_shop_user_provider
form_login:
success_handler: sylius.authentication.success_handler
failure_handler: sylius.authentication.failure_handler
provider: sylius_shop_user_provider
login_path: sylius_shop_login
check_path: sylius_shop_login_check
failure_path: sylius_shop_login
default_target_path: sylius_shop_homepage
use_forward: false
use_referer: true
csrf_token_generator: security.csrf.token_manager
csrf_parameter: _csrf_shop_security_token
csrf_token_id: shop_authenticate
remember_me:
secret: "%env(APP_SECRET)%"
name: APP_SHOP_REMEMBER_ME
lifetime: 31536000
remember_me_parameter: _remember_me
logout:
path: sylius_shop_logout
target: sylius_shop_login
invalidate_session: false
success_handler: sylius.handler.shop_user_logout
anonymous: true

dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false

access_control:
- { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
- { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS }
- { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] }
- { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS }

- { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY }

- { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY }

- { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS }
- { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS }
- { path: "%sylius.security.shop_regex%/account", role: ROLE_USER }
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parameters:
excludes_analyse:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'
- 'src/DependencyInjection/SyliusRefundExtension.php'

# Test dependencies
- 'tests/Application/app/**.php'
Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/SyliusRefundExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sylius\RefundPlugin\DependencyInjection;

use Sylius\Bundle\CoreBundle\Application\Kernel;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -30,6 +31,11 @@ public function prepend(ContainerBuilder $container): void
}

$doctrineConfig = $container->getExtensionConfig('doctrine_migrations');

if (!$this->shouldDoctrineMigrationsConfigurationBePrepended()) {
return;
}

$migrationsPath = (array) \array_pop($doctrineConfig)['migrations_paths'];
$container->prependExtensionConfig('doctrine_migrations', [
'migrations_paths' => \array_merge(
Expand All @@ -46,4 +52,10 @@ public function prepend(ContainerBuilder $container): void
],
]);
}

private function shouldDoctrineMigrationsConfigurationBePrepended(): bool
{
// prepending configuration is required only for DoctrineMigrations ^3.0 used in Sylius ^1.8
return (int) Kernel::MINOR_VERSION >= 8;
}
}
6 changes: 0 additions & 6 deletions tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,3 @@ MAILER_URL=smtp://localhost
###> knplabs/knp-snappy-bundle ###
WKHTMLTOPDF_PATH=%kernel.project_dir%/etc/wkhtmltopdf
###< knplabs/knp-snappy-bundle ###

###> lexik/jwt-authentication-bundle ###
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=66d45daf91b2ed1031e62d81c81dba2e
###< lexik/jwt-authentication-bundle ###
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lexik_jwt_authentication:
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
secret_key: 'SECRET'
public_key: 'PUBLIC'
pass_phrase: 'PASS_PHRASE'
Loading