-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
333 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine; | ||
|
||
use Doctrine\Common\EventSubscriber; | ||
use Doctrine\ORM\Event\LifecycleEventArgs; | ||
use Doctrine\ORM\Events; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; | ||
use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface; | ||
|
||
/** | ||
* @internal | ||
* @final | ||
*/ | ||
class RouteRemover implements EventSubscriber | ||
{ | ||
/** | ||
* @var ContentMetadataInspectorInterface | ||
*/ | ||
private $contentMetadataInspector; | ||
|
||
/** | ||
* @var RouteRepositoryInterface | ||
*/ | ||
private $routeRepository; | ||
|
||
/** | ||
* @var array<string, array<mixed>> | ||
*/ | ||
private $routeMappings; | ||
|
||
/** | ||
* @param array<string, array<mixed>> $routeMappings | ||
*/ | ||
public function __construct( | ||
ContentMetadataInspectorInterface $contentMetadataInspector, | ||
RouteRepositoryInterface $routeRepository, | ||
array $routeMappings | ||
) { | ||
$this->routeRepository = $routeRepository; | ||
$this->contentMetadataInspector = $contentMetadataInspector; | ||
$this->routeMappings = $routeMappings; | ||
} | ||
|
||
public function getSubscribedEvents() | ||
{ | ||
return [Events::preRemove]; | ||
} | ||
|
||
public function preRemove(LifecycleEventArgs $event): void | ||
{ | ||
$object = $event->getObject(); | ||
if (!$object instanceof ContentRichEntityInterface) { | ||
return; // @codeCoverageIgnore | ||
} | ||
|
||
$dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass(\get_class($object)); | ||
$resourceKey = $dimensionContentClass::getResourceKey(); | ||
|
||
$entityClass = null; | ||
foreach ($this->routeMappings as $key => $mapping) { | ||
if ($resourceKey === $mapping['resource_key']) { | ||
$entityClass = $mapping['entityClass'] ?? $key; | ||
break; | ||
} | ||
} | ||
|
||
if (!$entityClass) { | ||
return; | ||
} | ||
|
||
foreach ($this->routeRepository->findAllByEntity($entityClass, $object->getId()) as $route) { | ||
$event->getEntityManager()->remove($route); | ||
} | ||
} | ||
} |
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
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,17 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
/* eslint-disable import/no-nodejs-modules */ | ||
const path = require('path'); | ||
|
||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
plugins: { | ||
'postcss-import': { | ||
path: path.resolve(process.cwd(), 'node_modules'), | ||
}, | ||
'postcss-nested': {}, | ||
'postcss-simple-vars': {}, | ||
'postcss-calc': {}, | ||
'postcss-hexrgba': {}, | ||
'autoprefixer': {}, | ||
}, | ||
}; |
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,4 @@ | ||
security: | ||
providers: | ||
testprovider: | ||
id: sulu_security.user_provider |
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
Oops, something went wrong.