Skip to content

Commit

Permalink
Merge 2a7db7b into bd6674a
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Sep 30, 2021
2 parents bd6674a + 2a7db7b commit dcf9c2a
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManagerInterface;

class ContentMetadataInspector implements ContentMetadataInspectorInterface
Expand All @@ -29,6 +30,8 @@ public function __construct(EntityManagerInterface $entityManager)

public function getDimensionContentClass(string $contentRichEntityClass): string
{
$contentRichEntityClass = ClassUtils::getRealClass($contentRichEntityClass);

$classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass);
$associationMapping = $classMetadata->getAssociationMapping('dimensionContents');

Expand All @@ -37,6 +40,8 @@ public function getDimensionContentClass(string $contentRichEntityClass): string

public function getDimensionContentPropertyName(string $contentRichEntityClass): string
{
$contentRichEntityClass = ClassUtils::getRealClass($contentRichEntityClass);

$classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass);
$associationMapping = $classMetadata->getAssociationMapping('dimensionContents');

Expand Down
88 changes: 88 additions & 0 deletions Content/Infrastructure/Doctrine/RouteRemover.php
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);
}
}
}
7 changes: 7 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<tag name="doctrine.event_subscriber" priority="100"/>
</service>

<service id="sulu_content.route_remover" class="Sulu\Bundle\ContentBundle\Content\Infrastructure\Doctrine\RouteRemover">
<argument type="service" id="sulu_content.content_metadata_inspector"/>
<argument type="service" id="sulu.repository.route"/>
<argument>%sulu_route.mappings%</argument>
<tag name="doctrine.event_subscriber"/>
</service>

<service id="sulu_content.content_view_builder_factory" class="Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Admin\ContentViewBuilderFactory">
<argument type="service" id="sulu_admin.view_builder_factory"/>
<argument type="service" id="sulu_preview.preview_object_provider_registry"/>
Expand Down
4 changes: 1 addition & 3 deletions Tests/Application/ExampleTestBundle/Entity/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function getId()

public function createDimensionContent(): DimensionContentInterface
{
$exampleDimensionContent = new ExampleDimensionContent($this);

return $exampleDimensionContent;
return new ExampleDimensionContent($this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins": [
["@babel/plugin-proposal-decorators", {"legacy": true}],
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-flow-strip-types",
["@babel/plugin-proposal-class-properties", {"loose": true}]
]
}
73 changes: 40 additions & 33 deletions Tests/Application/assets/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,66 @@
"license": "MIT",
"repository": "https://github.com/sulu/skeleton.git",
"scripts": {
"preinstall": "node ../../../../vendor/sulu/sulu/preinstall.js",
"preinstall": "node ../../../../vendor/sulu/sulu/preinstall.js ../../../../vendor node_modules/@sulu/vendor",
"postinstall": "node ../../../../vendor/sulu/sulu/postinstall.js ../../../../vendor node_modules/@sulu/vendor",
"build": "webpack --mode production",
"watch": "webpack --mode development -w"
"watch": "webpack --mode development --watch"
},
"dependencies": {
"mobx": "^4.0.0",
"mobx-react": "^5.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"sulu-admin-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/AdminBundle/Resources/js",
"sulu-audience-targeting-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/AudienceTargetingBundle/Resources/js",
"sulu-category-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/CategoryBundle/Resources/js",
"sulu-contact-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/ContactBundle/Resources/js",
"sulu-custom-url-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/CustomUrlBundle/Resources/js",
"sulu-location-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/LocationBundle/Resources/js",
"sulu-media-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/Resources/js",
"sulu-page-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/PageBundle/Resources/js",
"sulu-preview-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Resources/js",
"sulu-route-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/RouteBundle/Resources/js",
"sulu-search-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/SearchBundle/Resources/js",
"sulu-security-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Resources/js",
"sulu-snippet-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/SnippetBundle/Resources/js",
"sulu-website-bundle": "file:../../../../vendor/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Resources/js"
"react": "^17.0.0",
"react-dom": "^17.0.0",
"sulu-admin-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/AdminBundle/Resources/js",
"sulu-audience-targeting-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/AudienceTargetingBundle/Resources/js",
"sulu-category-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/CategoryBundle/Resources/js",
"sulu-contact-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/ContactBundle/Resources/js",
"sulu-custom-url-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/CustomUrlBundle/Resources/js",
"sulu-location-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/LocationBundle/Resources/js",
"sulu-media-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/Resources/js",
"sulu-page-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/PageBundle/Resources/js",
"sulu-preview-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Resources/js",
"sulu-route-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/RouteBundle/Resources/js",
"sulu-search-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/SearchBundle/Resources/js",
"sulu-security-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Resources/js",
"sulu-snippet-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/SnippetBundle/Resources/js",
"sulu-trash-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/TrashBundle/Resources/js",
"sulu-website-bundle": "file:node_modules/@sulu/vendor/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Resources/js"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2",
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@ckeditor/ckeditor5-dev-utils": "^12.0.1",
"@ckeditor/ckeditor5-theme-lark": "^14.0.0",
"autoprefixer": "^9.6.1",
"@ckeditor/ckeditor5-dev-utils": "^24.4.2",
"@ckeditor/ckeditor5-theme-lark": "^27.1.0",
"autoprefixer": "^9.8.6",
"babel-loader": "^8.0.6",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.2.0",
"file-loader": "^4.2.0",
"core-js": "^3.18.0",
"css-loader": "^5.2.4",
"file-loader": "^6.0.0",
"glob": "^7.1.2",
"mini-css-extract-plugin": "^0.8.0",
"mini-css-extract-plugin": "^1.5.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"postcss-calc": "^7.0.1",
"postcss-hexrgba": "^1.0.0",
"postcss": "7.0.35",
"postcss-calc": "^7.0.5",
"postcss-hexrgba": "^2.0.0",
"postcss-import": "^12.0.1",
"postcss-loader": "^3.0.0",
"postcss-nested": "^4.1.2",
"postcss-nested": "^4.2.3",
"postcss-simple-vars": "^5.0.2",
"raw-loader": "^3.1.0",
"raw-loader": "^4.0.0",
"regenerator-runtime": "^0.13.3",
"webpack": "^4.20.2",
"webpack": "^4.27.0",
"webpack-clean-obsolete-chunks": "^0.4.0",
"webpack-cli": "^3.1.1",
"webpack-manifest-plugin": "^2.0.2"
"webpack-cli": "^4.7.0",
"webpack-manifest-plugin": "^3.1.1"
},
"engines": {
"node": ">=12",
"npm": ">=6 <7"
}
}
17 changes: 17 additions & 0 deletions Tests/Application/assets/admin/postcss.config.js
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': {},
},
};
6 changes: 6 additions & 0 deletions Tests/Functional/Integration/ExampleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function testPost(): int

$this->assertResponseSnapshot('example_post.json', $response, 201);

$routeRepository = $this->getContainer()->get('sulu.repository.route');
$this->assertCount(0, $routeRepository->findAll());

$id = \json_decode((string) $response->getContent(), true)['id'] ?? null;

return $id;
Expand Down Expand Up @@ -215,6 +218,9 @@ public function testDelete(int $id): void
$this->client->request('DELETE', '/admin/api/examples/' . $id . '?locale=en');
$response = $this->client->getResponse();
$this->assertHttpStatusCode(204, $response);

$routeRepository = $this->getContainer()->get('sulu.repository.route');
$this->assertCount(0, $routeRepository->findAll());
}

protected function getSnapshotFolder(): string
Expand Down
Loading

0 comments on commit dcf9c2a

Please sign in to comment.