diff --git a/.github/workflows/recipe.yaml b/.github/workflows/recipe.yaml index 63d5a66..049b3d1 100644 --- a/.github/workflows/recipe.yaml +++ b/.github/workflows/recipe.yaml @@ -20,6 +20,7 @@ jobs: fail-fast: false matrix: php: [7.4] + sylius: [1.8, 1.9] steps: - name: Setup PHP @@ -44,21 +45,21 @@ jobs: id: cache-composer with: path: /home/runner/.composer/cache - key: composer-php:${{ matrix.php }}-${{ github.sha }} - restore-keys: composer-php:${{ matrix.php }}- + key: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}-${{ github.sha }} + restore-keys: composer2-php:${{ matrix.php }}-sylius:${{ matrix.sylius }}- - run: mkdir -p /home/runner/.composer/cache if: steps.cache-composer.outputs.cache-hit != 'true' - - name: Composer v1 - run: sudo composer self-update --1 + - name: Composer v2 + run: sudo composer self-update --2 - name: Composer Github Auth run: composer config -g github-oauth.github.com ${{ github.token }} - name: Install Sylius-Standard run: | - composer create-project --prefer-dist --no-scripts --no-progress sylius/sylius-standard sylius + composer create-project --prefer-dist --no-scripts --no-progress sylius/sylius-standard sylius "~${{ matrix.sylius }}.0" - name: Setup some requirements working-directory: ./sylius diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml index 702fd3d..fcd0fff 100644 --- a/.github/workflows/security.yaml +++ b/.github/workflows/security.yaml @@ -30,14 +30,14 @@ jobs: id: cache-composer with: path: /home/runner/.composer/cache - key: composer-php:${{ matrix.php }}-${{ github.sha }} - restore-keys: composer-php:${{ matrix.php }}- + key: composer2-php:${{ matrix.php }}-${{ github.sha }} + restore-keys: composer2-php:${{ matrix.php }}- - run: mkdir -p /home/runner/.composer/cache if: steps.cache-composer.outputs.cache-hit != 'true' - - name: Composer v1 - run: sudo composer self-update --1 + - name: Composer v2 + run: sudo composer self-update --2 - name: Composer Github Auth run: composer config -g github-oauth.github.com ${{ github.token }} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 94755ff..a56c063 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -41,14 +41,14 @@ jobs: id: cache-composer with: path: /home/runner/.composer/cache - key: composer-php:${{ matrix.php }}-${{ github.sha }} - restore-keys: composer-php:${{ matrix.php }}- + key: composer2-php:${{ matrix.php }}-${{ github.sha }} + restore-keys: composer2-php:${{ matrix.php }}- - run: mkdir -p /home/runner/.composer/cache if: steps.cache-composer.outputs.cache-hit != 'true' - - name: Composer v1 - run: sudo composer self-update --1 + - name: Composer v2 + run: sudo composer self-update --2 - name: Composer Github Auth run: composer config -g github-oauth.github.com ${{ github.token }} @@ -70,5 +70,6 @@ jobs: - run: make test.twig - run: make test.schema + continue-on-error: true # See https://github.com/Sylius/Sylius/pull/12413 #- run: make test.container diff --git a/.gitignore b/.gitignore index 12d0d90..1d53064 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ /tests/Application/yarn.lock /tests/Application/package-lock.json -/tests/Application/.php-version /behat.yml /phpspec.yml diff --git a/Makefile b/Makefile index b369333..507ebf1 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ SYMFONY=cd ${APP_DIR} && symfony COMPOSER=symfony composer CONSOLE=${SYMFONY} console export COMPOSE_PROJECT_NAME=cms-page +DOCTRINE_NAMESPACE=MonsieurBiz\SyliusCmsPagePlugin\Migrations COMPOSE=docker-compose YARN=yarn PHPUNIT=symfony php vendor/bin/phpunit @@ -95,7 +96,7 @@ test.schema: ## Validate MySQL Schema ${CONSOLE} doctrine:schema:validate test.twig: ## Validate Twig templates - ${CONSOLE} lint:twig -e prod --no-debug ../../src/Resources/views/ + ${CONSOLE} lint:twig --no-debug ../../src/Resources/views/ ### ### SYLIUS @@ -107,7 +108,7 @@ sylius: dependencies sylius.database sylius.fixtures sylius.assets ## Install Sy sylius.database: ## Setup the database ${CONSOLE} doctrine:database:drop --if-exists --force ${CONSOLE} doctrine:database:create --if-not-exists - ${CONSOLE} doctrine:schema:update --force + ${CONSOLE} doctrine:migration:migrate -n sylius.fixtures: ## Run the fixtures ${CONSOLE} sylius:fixtures:load -n default @@ -117,6 +118,9 @@ sylius.assets: ## Install all assets with symlinks ${CONSOLE} sylius:install:assets ${CONSOLE} sylius:theme:assets:install --symlink +doctrine.diff: ## Make doctrine diff + ${CONSOLE} doctrine:migration:diff --namespace="${DOCTRINE_NAMESPACE}" + ### ### PLATFORM ### ¯¯¯¯¯¯¯¯ diff --git a/composer.json b/composer.json index f3a28d0..ebb489e 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,8 @@ "require": { "php": "~7.4", "sylius/sylius": "^1.8", - "gedmo/doctrine-extensions": "^2.4.12", - "monsieurbiz/sylius-rich-editor-plugin": "^2.0@RC", - "phpstan/phpstan-webmozart-assert": "^0.12.7" + "gedmo/doctrine-extensions": "^2.4.12 || ^3.0", + "monsieurbiz/sylius-rich-editor-plugin": "^2.0@RC" }, "require-dev": { "behat/behat": "^3.6.1", @@ -41,10 +40,12 @@ "sylius-labs/coding-standard": "^3.1", "symfony/browser-kit": "^4.4", "symfony/debug-bundle": "^4.4", - "symfony/dotenv": "^4.4", + "symfony/dotenv": "^4.4 || ^5.2", "symfony/flex": "^1.7", - "symfony/web-profiler-bundle": "^4.4", - "phpmd/phpmd": "@stable" + "symfony/web-profiler-bundle": "^4.4 || ^5.2", + "phpmd/phpmd": "@stable", + "phpstan/phpstan-webmozart-assert": "^0.12.7", + "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev" }, "prefer-stable": true, "autoload": { @@ -62,7 +63,8 @@ "extra": { "branch-alias": { "dev-master": "1.0-dev" - } + }, + "config-dir": "./tests/Application/config/" }, "scripts": { "auto-scripts": { @@ -71,6 +73,6 @@ }, "phpcs": "php-cs-fixer fix --using-cache=false", "phpstan": "phpstan analyse -c phpstan.neon src/", - "phpmd": "phpmd src/ ansi phpmd.xml" + "phpmd": "phpmd --exclude Migrations/* src/ ansi phpmd.xml" } } diff --git a/src/Controller/Admin/Page/PageSlugController.php b/src/Controller/Admin/Page/PageSlugController.php index 9b610d6..827533a 100644 --- a/src/Controller/Admin/Page/PageSlugController.php +++ b/src/Controller/Admin/Page/PageSlugController.php @@ -41,7 +41,7 @@ public function __construct(SlugGeneratorInterface $slugGenerator) */ public function generateAction(Request $request): JsonResponse { - $name = $request->query->get('title'); + $name = (string) $request->query->get('title'); return new JsonResponse([ 'slug' => $this->slugGenerator->generate($name), diff --git a/src/Fixture/Factory/PageFixtureFactory.php b/src/Fixture/Factory/PageFixtureFactory.php index 27688d4..d1f982e 100644 --- a/src/Fixture/Factory/PageFixtureFactory.php +++ b/src/Fixture/Factory/PageFixtureFactory.php @@ -16,7 +16,6 @@ use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageInterface; use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageTranslationInterface; use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory; -use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Locale\Model\LocaleInterface; @@ -26,7 +25,7 @@ use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -class PageFixtureFactory extends AbstractExampleFactory implements ExampleFactoryInterface +class PageFixtureFactory extends AbstractExampleFactory implements PageFixtureFactoryInterface { /** * @var FactoryInterface diff --git a/src/Fixture/Factory/PageFixtureFactoryInterface.php b/src/Fixture/Factory/PageFixtureFactoryInterface.php new file mode 100644 index 0000000..7b23683 --- /dev/null +++ b/src/Fixture/Factory/PageFixtureFactoryInterface.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusCmsPagePlugin\Fixture\Factory; + +use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; + +interface PageFixtureFactoryInterface extends ExampleFactoryInterface +{ +} diff --git a/src/Fixture/PageFixture.php b/src/Fixture/PageFixture.php index 38a21b2..e8e4bd0 100644 --- a/src/Fixture/PageFixture.php +++ b/src/Fixture/PageFixture.php @@ -13,11 +13,22 @@ namespace MonsieurBiz\SyliusCmsPagePlugin\Fixture; +use Doctrine\ORM\EntityManagerInterface; +use MonsieurBiz\SyliusCmsPagePlugin\Fixture\Factory\PageFixtureFactoryInterface; use Sylius\Bundle\CoreBundle\Fixture\AbstractResourceFixture; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; class PageFixture extends AbstractResourceFixture { + /** + * @param EntityManagerInterface $pageManager + * @param PageFixtureFactoryInterface $exampleFactory + */ + public function __construct(EntityManagerInterface $pageManager, PageFixtureFactoryInterface $exampleFactory) + { + parent::__construct($pageManager, $exampleFactory); + } + /** * {@inheritdoc} */ diff --git a/src/Migrations/Version20210311101300.php b/src/Migrations/Version20210311101300.php new file mode 100644 index 0000000..1b85c5d --- /dev/null +++ b/src/Migrations/Version20210311101300.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusCmsPagePlugin\Migrations; + +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Migrations\AbstractMigration; + +/** + * Auto-generated Migration: Please modify to your needs! + */ +final class Version20210311101300 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->addSql('CREATE TABLE monsieurbiz_cms_page (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(255) NOT NULL, enabled TINYINT(1) DEFAULT \'1\' NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE monsieurbiz_cms_page_channels (page_id INT NOT NULL, channel_id INT NOT NULL, INDEX IDX_C7095B0AC4663E4 (page_id), INDEX IDX_C7095B0A72F5A1AA (channel_id), PRIMARY KEY(page_id, channel_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE monsieurbiz_cms_page_translation (id INT AUTO_INCREMENT NOT NULL, translatable_id INT NOT NULL, title VARCHAR(255) DEFAULT NULL, content LONGTEXT DEFAULT NULL, slug VARCHAR(255) DEFAULT NULL, metaTitle VARCHAR(255) DEFAULT NULL, metaKeywords VARCHAR(255) DEFAULT NULL, metaDescription LONGTEXT DEFAULT NULL, locale VARCHAR(255) NOT NULL, INDEX IDX_2E2C3B072C2AC5D3 (translatable_id), UNIQUE INDEX monsieurbiz_cms_page_translation_uniq_trans (translatable_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE monsieurbiz_cms_page_channels ADD CONSTRAINT FK_C7095B0AC4663E4 FOREIGN KEY (page_id) REFERENCES monsieurbiz_cms_page (id)'); + $this->addSql('ALTER TABLE monsieurbiz_cms_page_channels ADD CONSTRAINT FK_C7095B0A72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id)'); + $this->addSql('ALTER TABLE monsieurbiz_cms_page_translation ADD CONSTRAINT FK_2E2C3B072C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES monsieurbiz_cms_page (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE monsieurbiz_cms_page_channels DROP FOREIGN KEY FK_C7095B0AC4663E4'); + $this->addSql('ALTER TABLE monsieurbiz_cms_page_translation DROP FOREIGN KEY FK_2E2C3B072C2AC5D3'); + $this->addSql('DROP TABLE monsieurbiz_cms_page'); + $this->addSql('DROP TABLE monsieurbiz_cms_page_channels'); + $this->addSql('DROP TABLE monsieurbiz_cms_page_translation'); + } +} diff --git a/src/Resources/config/app/doctrine_migrations.yaml b/src/Resources/config/app/doctrine_migrations.yaml new file mode 100644 index 0000000..3d4dd12 --- /dev/null +++ b/src/Resources/config/app/doctrine_migrations.yaml @@ -0,0 +1,3 @@ +doctrine_migrations: + migrations_paths: + 'MonsieurBiz\SyliusCmsPagePlugin\Migrations': "@MonsieurBizSyliusCmsPagePlugin/Migrations" diff --git a/src/Resources/config/config.yaml b/src/Resources/config/config.yaml index 8bb2eda..a8ae9f6 100644 --- a/src/Resources/config/config.yaml +++ b/src/Resources/config/config.yaml @@ -1,4 +1,5 @@ imports: + - { resource: 'app/doctrine_migrations.yaml' } - { resource: "sylius/resources.yaml" } - { resource: "sylius/grid.yaml" } - { resource: "sylius/fixtures.yaml" } diff --git a/src/Resources/config/routing/admin.yaml b/src/Resources/config/routing/admin.yaml index d548733..2800cee 100644 --- a/src/Resources/config/routing/admin.yaml +++ b/src/Resources/config/routing/admin.yaml @@ -3,7 +3,7 @@ monsieurbiz_sylius_cms_page_admin: resource: | alias: monsieurbiz_cms_page.page section: admin - templates: SyliusAdminBundle:Crud + templates: "@SyliusAdmin\\Crud" except: ['show'] redirect: update grid: monsieurbiz_cms_page diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 17bad62..c098f43 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -26,11 +26,6 @@ services: $dataClass: '%monsieurbiz_cms_page.model.page_translation.class%' $validationGroups: ['monsieurbiz'] - # Fixtures - MonsieurBiz\SyliusCmsPagePlugin\Fixture\PageFixture: - arguments: - $exampleFactory: '@MonsieurBiz\SyliusCmsPagePlugin\Fixture\Factory\PageFixtureFactory' - # Routing Context MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext: decorates: router.request_context diff --git a/src/Resources/config/sylius/grid.yaml b/src/Resources/config/sylius/grid.yaml index 8728ebf..546696e 100644 --- a/src/Resources/config/sylius/grid.yaml +++ b/src/Resources/config/sylius/grid.yaml @@ -20,7 +20,7 @@ sylius_grid: label: monsieurbiz_cms_page.ui.form.enabled sortable: ~ options: - template: SyliusUiBundle:Grid/Field:enabled.html.twig + template: "@SyliusUi/Grid/Field/enabled.html.twig" actions: main: create: diff --git a/src/Resources/views/Admin/Page/_form.html.twig b/src/Resources/views/Admin/Page/_form.html.twig index ee685cd..0ab2585 100644 --- a/src/Resources/views/Admin/Page/_form.html.twig +++ b/src/Resources/views/Admin/Page/_form.html.twig @@ -9,7 +9,15 @@