Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental ArticleRepository and ArticleController #583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
DATABASE_URL: mysql://[email protected]:3306/su_articles_test?serverVersion=5.7
ARTICLE_TEST_CASE: extend
docker:
- image: circleci/php:7.3-node-browsers
- image: circleci/php:8.1-node-browsers
- image: circleci/mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
Expand Down
26 changes: 1 addition & 25 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,11 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '7.3'
elasticsearch-version: '5.6.14'
elasticsearch-package-constraint: '~5.5'
phpcr-transport: doctrinedbal
dependency-versions: 'lowest'
php-extensions: 'ctype, iconv, mysql, gd'
tools: 'composer:v1'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
ELASTICSEARCH_HOST: '127.0.0.1:9200'
DATABASE_CHARSET: UTF8
DATABASE_COLLATE: UTF8_BIN

- php-version: '7.4'
elasticsearch-version: '7.9.3'
elasticsearch-package-constraint: '~7.9.0'
phpcr-transport: doctrinedbal
dependency-versions: 'highest'
php-extensions: 'ctype, iconv, mysql, imagick'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak
ELASTICSEARCH_HOST: '127.0.0.1:9200'

- php-version: '8.0'
elasticsearch-version: '7.11.1'
elasticsearch-package-constraint: '~7.11.0'
phpcr-transport: jackrabbit
dependency-versions: 'highest'
dependency-versions: 'lowest'
php-extensions: 'ctype, iconv, mysql, imagick'
tools: 'composer:v2'
env:
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'single_line_throw' => false,
'single_line_comment_spacing' => false,
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var', 'see', 'phpstan-ignore-next-line'],
'ignored_tags' => ['todo', 'var', 'see', 'phpstan-ignore-next-line', 'phpstan-use'],
],
])
->setFinder($finder);
Expand Down
25 changes: 0 additions & 25 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Sulu\Bundle\ArticleBundle\Document\ArticlePageViewObject;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument;
use Sulu\Bundle\ArticleBundle\Domain\Model\Article;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContent;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -23,37 +22,13 @@
*/
class Configuration implements ConfigurationInterface
{
public const ARTICLE_STORAGE_PHPCR = 'phpcr';
public const ARTICLE_STORAGE_EXPERIMENTAL = 'experimental';

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sulu_article');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
->enumNode('storage')
->values([self::ARTICLE_STORAGE_PHPCR, self::ARTICLE_STORAGE_EXPERIMENTAL])
->defaultValue(self::ARTICLE_STORAGE_PHPCR)
->end()
->arrayNode('objects')
->addDefaultsIfNotSet()
->children()
->arrayNode('article')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(Article::class)->end()
->end()
->end()
->arrayNode('article_content')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(ArticleDimensionContent::class)->end()
->end()
->end()
->end()
->end()
->scalarNode('index_name')->end()
->arrayNode('hosts')
->prototype('scalar')->end()
Expand Down
148 changes: 33 additions & 115 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Sulu\Bundle\ArticleBundle\Document\LocalizedLastModifiedBehavior;
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticleBridge;
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticlePageBridge;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Exception\ArticlePageNotFoundException;
use Sulu\Bundle\ArticleBundle\Exception\ParameterNotAllowedException;
use Sulu\Bundle\PersistenceBundle\DependencyInjection\PersistenceExtensionTrait;
Expand All @@ -44,8 +43,6 @@ public function prepend(ContainerBuilder $container)
$configs = $resolvingBag->resolveValue($configs);
$config = $this->processConfiguration(new Configuration(), $configs);

$storage = $config['storage'];

if ($container->hasExtension('jms_serializer')) {
$container->prependExtensionConfig(
'jms_serializer',
Expand All @@ -61,7 +58,6 @@ public function prepend(ContainerBuilder $container)
]
);
}

if ($container->hasExtension('sulu_admin')) {
$container->prependExtensionConfig(
'sulu_admin',
Expand Down Expand Up @@ -130,18 +126,6 @@ public function prepend(ContainerBuilder $container)
);
}

if (Configuration::ARTICLE_STORAGE_PHPCR === $storage) {
$this->prependPHPCRStorage($container);
} elseif (Configuration::ARTICLE_STORAGE_EXPERIMENTAL === $storage) {
$this->prependExperimentalStorage($container);
}
}

/**
* Can be removed when phpcr storage is removed.
*/
private function prependPHPCRStorage(ContainerBuilder $container): void
{
if ($container->hasExtension('sulu_core')) {
// can be removed when phpcr storage is removed
$container->prependExtensionConfig(
Expand Down Expand Up @@ -315,115 +299,35 @@ private function prependPHPCRStorage(ContainerBuilder $container): void
}
}

private function prependExperimentalStorage(ContainerBuilder $container): void
{
if ($container->hasExtension('doctrine')) {
$container->prependExtensionConfig(
'doctrine',
[
'orm' => [
'mappings' => [
'SuluBundleArticle' => [
'type' => 'xml',
'prefix' => 'Sulu\Bundle\ArticleBundle\Domain\Model',
'dir' => \dirname(__DIR__) . '/Resources/config/doctrine/Article',
'alias' => 'SuluArticleBundle',
'is_bundle' => false,
'mapping' => true,
],
],
],
]
);
}

if ($container->hasExtension('sulu_core')) {
$container->prependExtensionConfig(
'sulu_core',
[
'content' => [
'structure' => [
'paths' => [
ArticleInterface::TEMPLATE_TYPE => [
'path' => '%kernel.project_dir%/config/templates/articles',
'type' => 'article',
],
],
'default_type' => [
ArticleInterface::TEMPLATE_TYPE => 'default',
],
],
],
]
);
}

if ($container->hasExtension('sulu_route')) {
$container->prependExtensionConfig(
'sulu_route',
[
'mappings' => [
ArticleInterface::class => [
'generator' => 'schema',
'options' => [
'route_schema' => '/{implode("-", object)}',
],
'resource_key' => ArticleInterface::RESOURCE_KEY,
],
],
]
);
}

if ($container->hasExtension('sulu_search')) {
$suluSearchConfigs = $container->getExtensionConfig('sulu_search');

foreach ($suluSearchConfigs as $suluSearchConfig) {
if (isset($suluSearchConfig['website']['indexes'])) {
$container->prependExtensionConfig(
'sulu_search',
[
'website' => [
'indexes' => [
ArticleInterface::RESOURCE_KEY => ArticleInterface::RESOURCE_KEY . '_published',
],
],
]
);
}
}
}
}

/**
* @param mixed[] $configs
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
/**
* @var array{
* storage: 'experimental'|'phpcr',
* objects: array<string, array{model: class-string}>,
* default_main_webspace: string|null,
* default_additional_webspaces: string[]|null,
* types: array<string, string>,
* display_tab_all: bool,
* smart_content: array{
* default_limit: int,
* },
* search_fields: string[],
* documents: array<string, array{view: class-string}>,
* default_author: bool,
* } $config
*/
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

$storage = $config['storage'];
$container->setParameter('sulu_article.article_storage', $storage);

if (Configuration::ARTICLE_STORAGE_PHPCR === $storage) {
$this->loadPHPCRStorage($config, $container, $loader);
} elseif (Configuration::ARTICLE_STORAGE_EXPERIMENTAL === $storage) {
$this->loadExperimentalStorage($config, $container, $loader);
}
}

private function loadExperimentalStorage(array $config, ContainerBuilder $container, Loader\XmlFileLoader $loader): void
{
$this->configurePersistence($config['objects'], $container);

$loader->load('experimental.xml');
}

/**
* Can be removed when phpcr storage is removed.
*/
private function loadPHPCRStorage(array $config, ContainerBuilder $container, Loader\XmlFileLoader $loader): void
{
$container->setParameter('sulu_article.default_main_webspace', $config['default_main_webspace']);
$container->setParameter('sulu_article.default_additional_webspaces', $config['default_additional_webspaces']);
$container->setParameter('sulu_article.types', $config['types']);
Expand All @@ -435,6 +339,18 @@ private function loadPHPCRStorage(array $config, ContainerBuilder $container, Lo

$loader->load('services.xml');

/** @var array<string, class-string> $bundles */
$bundles = $container->getParameter('kernel.bundles');
if (\array_key_exists('SuluAutomationBundle', $bundles)) {
$loader->load('automation.xml');
}
if (\array_key_exists('SuluTrashBundle', $bundles)) {
$loader->load('services_trash.xml');
}
if (\array_key_exists('SuluHeadlessBundle', $bundles)) {
$loader->load('services_headless.xml');
}

$this->appendDefaultAuthor($config, $container);
$this->appendArticlePageConfig($container);

Expand All @@ -459,6 +375,8 @@ private function loadPHPCRStorage(array $config, ContainerBuilder $container, Lo
* Append configuration for article "set_default_author".
*
* Can be removed when phpcr storage is removed.
*
* @param array{default_author: bool} $config
*/
private function appendDefaultAuthor(array $config, ContainerBuilder $container): void
{
Expand Down
26 changes: 0 additions & 26 deletions Resources/config/experimental.xml

This file was deleted.

Loading
Loading