forked from sonata-project/SonataPageBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple and deprecate NotificationBundle
Issue sonata-project#1415
- Loading branch information
Showing
6 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Sonata\PageBundle\Service; | ||
|
||
use Sonata\PageBundle\Model\PageInterface; | ||
use Sonata\PageBundle\Model\SiteInterface; | ||
use Sonata\PageBundle\Model\SnapshotInterface; | ||
|
||
interface CreateSnapshotsFromPageInterface | ||
{ | ||
/** | ||
* @param iterable<PageInterface> $pages | ||
* @return iterable<SnapshotInterface> | ||
*/ | ||
public function createFromPages(iterable $pages): iterable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Sonata\PageBundle\Service; | ||
|
||
use Sonata\PageBundle\Model\PageInterface; | ||
use Sonata\PageBundle\Model\PageManagerInterface; | ||
use Sonata\PageBundle\Model\SiteInterface; | ||
use Sonata\PageBundle\Model\SnapshotInterface; | ||
use Sonata\PageBundle\Model\SnapshotManagerInterface; | ||
use Sonata\PageBundle\Model\TransformerInterface; | ||
|
||
final class CreateSnapshotsService implements CreateSnapshotsFromPageInterface | ||
{ | ||
protected SnapshotManagerInterface $snapshotManager; | ||
|
||
protected PageManagerInterface $pageManager; | ||
|
||
protected TransformerInterface $transformer; | ||
|
||
public function __construct( | ||
SnapshotManagerInterface $snapshotManager, | ||
PageManagerInterface $pageManager, | ||
TransformerInterface $transformer | ||
) { | ||
$this->snapshotManager = $snapshotManager; | ||
$this->pageManager = $pageManager; | ||
$this->transformer = $transformer; | ||
} | ||
|
||
/** | ||
* @param iterable<PageInterface> $pages | ||
* @return iterable<SnapshotInterface> | ||
*/ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters