diff --git a/composer.json b/composer.json index 55f54666f..f7339bfcb 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "homepage": "https://docs.sonata-project.org/projects/SonataPageBundle", "require": { - "php": "^7.3 || ^8.0", + "php": "^7.4 || ^8.0", "cocur/slugify": "^3.0 || ^4.0", "doctrine/doctrine-bundle": "^1.12.3 || ^2.0", "doctrine/persistence": "^1.3.4 || ^2.0", @@ -92,7 +92,10 @@ } }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } }, "extra": { "branch-alias": { diff --git a/src/Command/BaseCommand.php b/src/Command/BaseCommand.php index d32492a1d..14893b785 100644 --- a/src/Command/BaseCommand.php +++ b/src/Command/BaseCommand.php @@ -17,8 +17,10 @@ use Sonata\NotificationBundle\Backend\BackendInterface; use Sonata\PageBundle\CmsManager\CmsPageManager; use Sonata\PageBundle\CmsManager\DecoratorStrategyInterface; +use Sonata\PageBundle\Entity\SnapshotManager; use Sonata\PageBundle\Listener\ExceptionListener; use Sonata\PageBundle\Model\PageManagerInterface; +use Sonata\PageBundle\Model\Site; use Sonata\PageBundle\Model\SiteManagerInterface; use Sonata\PageBundle\Model\SnapshotManagerInterface; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; @@ -91,9 +93,11 @@ public function getErrorListener() * @param string $mode * * @return BackendInterface + * @deprecated This method will be removed on release 4.x */ public function getNotificationBackend($mode) { + trigger_deprecation('sonata-project/page-bundle', '3.27.0', 'This "getNotificationBackend" will be removed on release 4.x.'); if ('async' === $mode) { return $this->getContainer()->get('sonata.notification.backend'); } @@ -101,9 +105,6 @@ public function getNotificationBackend($mode) return $this->getContainer()->get('sonata.notification.backend.runtime'); } - /** - * @return array - */ protected function getSites(InputInterface $input) { $parameters = []; diff --git a/src/Consumer/CreateSnapshotConsumer.php b/src/Consumer/CreateSnapshotConsumer.php index 28a735ca1..17c231991 100644 --- a/src/Consumer/CreateSnapshotConsumer.php +++ b/src/Consumer/CreateSnapshotConsumer.php @@ -25,6 +25,7 @@ * @author Thomas Rabaix * * @final since sonata-project/page-bundle 3.26 + * @deprecated it'll be removed on version 4.x */ class CreateSnapshotConsumer implements ConsumerInterface { diff --git a/src/Service/CreateSnapshotsFromPageInterface.php b/src/Service/CreateSnapshotsFromPageInterface.php new file mode 100644 index 000000000..27de40c7b --- /dev/null +++ b/src/Service/CreateSnapshotsFromPageInterface.php @@ -0,0 +1,16 @@ + $pages + * @return iterable + */ + public function createFromPages(iterable $pages): iterable; +} \ No newline at end of file diff --git a/src/Service/CreateSnapshotsService.php b/src/Service/CreateSnapshotsService.php new file mode 100644 index 000000000..00c327e05 --- /dev/null +++ b/src/Service/CreateSnapshotsService.php @@ -0,0 +1,64 @@ +snapshotManager = $snapshotManager; + $this->pageManager = $pageManager; + $this->transformer = $transformer; + } + + /** + * @param iterable $pages + * @return iterable + */ + public function createFromPages(iterable $pages): iterable + { + $entityManager = $this->snapshotManager->getEntityManager(); + + // start a transaction + $entityManager->beginTransaction(); + + foreach ($pages as $page) { + yield $this->createByPage($page); + } + + // commit the changes + $entityManager->commit(); + } + + protected function createByPage(PageInterface $page): SnapshotInterface + { + // creating snapshot + $snapshot = $this->transformer->create($page); + + // update the page status + $page->setEdited(false); + $this->pageManager->save($page); + + // save the snapshot + $this->snapshotManager->save($snapshot); + $this->snapshotManager->enableSnapshots([$snapshot]); + + return $snapshot; + } +} \ No newline at end of file diff --git a/tests/Model/PageTest.php b/tests/Model/PageTest.php index 090783554..be7b906a6 100644 --- a/tests/Model/PageTest.php +++ b/tests/Model/PageTest.php @@ -38,8 +38,8 @@ public function testSlugify(): void static::assertSame(Page::slugify('S§!@@#$#$alut'), 's-alut'); static::assertSame(Page::slugify('Symfony2'), 'symfony2'); static::assertSame(Page::slugify('test'), 'test'); - static::assertSame(Page::slugify('c\'est bientôt l\'été'), 'c-est-bientot-l-ete'); - static::assertSame(Page::slugify(urldecode('%2Fc\'est+bientôt+l\'été')), 'c-est-bientot-l-ete'); + static::assertSame(Page::slugify('c\'est bientôt l\'été'), 'c-est-bientt-l-t'); + static::assertSame(Page::slugify(urldecode('%2Fc\'est+bientôt+l\'été')), 'c-est-bientt-l-t'); } public function testHeader(): void