Skip to content

Commit

Permalink
Add SmartCotnent ArticleDataProvider (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn authored and alexander-schranz committed Aug 8, 2024
1 parent 9a87b3e commit fbead4b
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 38 deletions.
1 change: 0 additions & 1 deletion 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 Down
1 change: 0 additions & 1 deletion DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ public function load(array $configs, ContainerBuilder $container)
$storage = $config['storage'];
$container->setParameter('sulu_article.article_storage', $storage);


$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 Down
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## 3.x

### Article user settings updated

Due to the refactoring of the new content bundle storage, the user settings for articles must be erased to avoid conflicts.

Execute the following SQL query to delete the user settings:
```mysql
DELETE FROM `se_user_settings`
WHERE `se_user_settings`.`settingsKey` LIKE '%article%'
```

### Elasticsearch Bundle need to be required

The SuluArticleBundle defines not longer its dependency to `handcraftedinthealps/elasticsearch-bundle` because
Expand Down
93 changes: 93 additions & 0 deletions config/lists/articles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
<list xmlns="http://schemas.sulu.io/list-builder/list">
<key>articles</key>

<joins name="creator">
<join>
<entity-name>%sulu.model.user.class%</entity-name>
<field-name>Sulu\Article\Domain\Model\ArticleInterface.creator</field-name>
</join>
<join>
<entity-name>%sulu.model.contact.class%</entity-name>
<field-name>%sulu.model.user.class%.contact</field-name>
</join>
</joins>
<joins name="changer">
<join>
<entity-name>%sulu.model.user.class%</entity-name>
<field-name>Sulu\Article\Domain\Model\ArticleInterface.changer</field-name>
</join>
<join>
<entity-name>%sulu.model.contact.class%</entity-name>
<field-name>%sulu.model.user.class%.contact</field-name>
</join>
</joins>

<joins name="dimensionContent">
<join>
<entity-name>dimensionContent</entity-name>
Expand Down Expand Up @@ -29,6 +50,13 @@
</join>
</joins>

<joins name="author">
<join>
<entity-name>authorEntity</entity-name>
<field-name>dimensionContent.author</field-name>
</join>
</joins>

<properties>
<!-- TODO should be uuid not id -->
<property name="id" translation="sulu_admin.uuid">
Expand All @@ -54,6 +82,71 @@
<transformer type="title"/>
</case-property>

<concatenation-property name="author" visibility="yes" translation="sulu_admin.author" glue=" " sortable="false">
<field>
<field-name>firstName</field-name>
<entity-name>authorEntity</entity-name>

<joins ref="author"/>
</field>
<field>
<field-name>lastName</field-name>
<entity-name>authorEntity</entity-name>

<joins ref="author"/>
</field>
</concatenation-property>

<property name="authored" type="date" visibility="no" translation="sulu_admin.authored"
>
<transformer type="datetime"/>
<filter type="date"/>
</property>

<property name="created" translation="sulu_admin.created">
<field-name>created</field-name>
<entity-name>Sulu\Article\Domain\Model\ArticleInterface</entity-name>
<transformer type="datetime"/>
</property>

<property name="changed" translation="sulu_admin.changed">
<field-name>changed</field-name>
<entity-name>Sulu\Article\Domain\Model\ArticleInterface</entity-name>
<transformer type="datetime"/>
</property>

<concatenation-property name="creator" visibility="always" glue=" "
translation="sulu_automation.list.creator" sortable="false">
<field>
<field-name>firstName</field-name>
<entity-name>%sulu.model.contact.class%</entity-name>

<joins ref="creator"/>
</field>
<field>
<field-name>lastName</field-name>
<entity-name>%sulu.model.contact.class%</entity-name>

<joins ref="creator"/>
</field>
</concatenation-property>

<concatenation-property name="changer" glue=" " translation="sulu_automation.list.changer"
sortable="false">
<field>
<field-name>firstName</field-name>
<entity-name>%sulu.model.contact.class%</entity-name>

<joins ref="changer"/>
</field>
<field>
<field-name>lastName</field-name>
<entity-name>%sulu.model.contact.class%</entity-name>

<joins ref="changer"/>
</field>
</concatenation-property>

<property name="locale" translation="sulu_admin.locale" visibility="never">
<field-name>locale</field-name>
<entity-name>dimensionContent</entity-name>
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Exception/ArticleNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ArticleNotFoundException extends \Exception
/**
* @param array<string, mixed> $filters
*/
public function __construct(array $filters, int $code = 0, \Throwable $previous = null)
public function __construct(array $filters, int $code = 0, ?\Throwable $previous = null)
{
$this->model = ArticleInterface::class;

Expand Down
25 changes: 25 additions & 0 deletions src/Domain/Repository/ArticleRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ public function findOneBy(array $filters, array $selects = []): ?ArticleInterfac
*/
public function findBy(array $filters = [], array $sortBy = [], array $selects = []): iterable;

/**
* @param array{
* uuid?: string,
* uuids?: string[],
* locale?: string,
* stage?: string,
* categoryIds?: int[],
* categoryKeys?: string[],
* categoryOperator?: 'AND'|'OR',
* tagIds?: int[],
* tagNames?: string[],
* tagOperator?: 'AND'|'OR',
* templateKeys?: string[],
* page?: int,
* limit?: int,
* } $filters
* @param array{
* id?: 'asc'|'desc',
* title?: 'asc'|'desc',
* } $sortBy
*
* @return iterable<string>
*/
public function findIdentifiersBy(array $filters = [], array $sortBy = []): iterable;

/**
* @param array{
* uuid?: string,
Expand Down
39 changes: 35 additions & 4 deletions src/Infrastructure/Doctrine/Repository/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query\Expr\OrderBy;
use Doctrine\ORM\QueryBuilder;
use Sulu\Article\Domain\Exception\ArticleNotFoundException;
use Sulu\Article\Domain\Model\ArticleDimensionContentInterface;
Expand Down Expand Up @@ -149,6 +150,24 @@ public function findBy(array $filters = [], array $sortBy = [], array $selects =
}
}

public function findIdentifiersBy(array $filters = [], array $sortBy = []): iterable
{
$queryBuilder = $this->createQueryBuilder($filters, $sortBy);

$queryBuilder->select('DISTINCT article.uuid');

// we need to select the fields which are used in the order by clause
/** @var OrderBy $orderBy */
foreach ($queryBuilder->getDQLPart('orderBy') as $orderBy) {
$queryBuilder->addSelect(\explode(' ', $orderBy->getParts()[0])[0]);
}

/** @var iterable $identifiers */
$identifiers = $queryBuilder->getQuery()->getResult();

return $identifiers;
}

public function add(ArticleInterface $article): void
{
$this->entityManager->persist($article);
Expand Down Expand Up @@ -228,17 +247,29 @@ private function createQueryBuilder(array $filters, array $sortBy = [], array $s
$queryBuilder->setFirstResult($offset);
}

if (\array_key_exists('locale', $filters) // should also work with locale = null
&& \array_key_exists('stage', $filters)) {
if (
(\array_key_exists('locale', $filters) // should also work with locale = null
&& \array_key_exists('stage', $filters))
|| ([] === $filters && [] !== $sortBy) // if no filters are set, but sortBy is set, we need to set the sorting
) {
$this->dimensionContentQueryEnhancer->addFilters(
$queryBuilder,
'article',
$this->articleDimensionContentClassName,
$filters
$filters,
$sortBy
);
}

// TODO add sortBys
if ([] !== $sortBy) {
foreach ($sortBy as $field => $order) {
if ('uuid' === $field) {
$queryBuilder->addOrderBy('article.uuid', $order);
} elseif ('created' === $field) {
$queryBuilder->addOrderBy('article.created', $order);
}
}
}

// selects
if ($selects[self::SELECT_ARTICLE_CONTENT] ?? null) {
Expand Down
Loading

0 comments on commit fbead4b

Please sign in to comment.