Skip to content

Commit

Permalink
Merge branch '2.6' of https://github.com/sulu/SuluArticleBundle into 3.0
Browse files Browse the repository at this point in the history
 Conflicts:
	DependencyInjection/Configuration.php
	DependencyInjection/SuluArticleExtension.php
	composer.json
  • Loading branch information
alexander-schranz committed Jul 24, 2024
2 parents 1fa29ee + 7b40fb2 commit c215b5e
Show file tree
Hide file tree
Showing 69 changed files with 1,466 additions and 276 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
sudo docker-php-ext-install pdo_mysql gd
parallel: true
- run: echo -e "memory_limit=2G" | sudo tee /usr/local/etc/php/php.ini > /dev/null
- run: /usr/local/bin/composer remove php-cs-fixer/shim --dev --no-update
- run: /usr/local/bin/composer require "elasticsearch/elasticsearch:~7.5.2" --no-update
- restore_cache:
keys:
Expand Down
42 changes: 36 additions & 6 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ jobs:
SYMFONY_DEPRECATIONS_HELPER: weak
ELASTICSEARCH_HOST: '127.0.0.1:9200'

- php-version: '8.3'
elasticsearch-version: '7.17.2'
elasticsearch-package-constraint: '~7.17.0'
phpcr-transport: doctrinedbal
dependency-versions: 'highest'
php-extensions: 'ctype, iconv, mysql, imagick'
tools: 'composer:v2'
phpstan: false
env:
SYMFONY_DEPRECATIONS_HELPER: weak
ELASTICSEARCH_HOST: '127.0.0.1:9200'

- php-version: '8.4'
composer-options: '--ignore-platform-reqs'
elasticsearch-version: '8.14.3'
elasticsearch-package-constraint: '~7.17.0'
phpcr-transport: doctrinedbal
dependency-versions: 'highest'
php-extensions: 'ctype, iconv, mysql, imagick'
tools: 'composer:v2'
phpstan: false
env:
SYMFONY_DEPRECATIONS_HELPER: weak
ELASTICSEARCH_HOST: '127.0.0.1:9200'

services:
mysql:
image: mysql:5.7
Expand All @@ -88,7 +113,7 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5

jackrabbit:
image: sulu/jackrabbit:2.20-standalone
image: sulu/jackrabbit:2.20-tomcat-filesystem
env:
DATABASE_HOST: mysql
DATABASE_PORT: 3306
Expand All @@ -110,7 +135,7 @@ jobs:

steps:
- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
Expand All @@ -120,11 +145,16 @@ jobs:
tools: ${{ matrix.tools }}
coverage: none

- name: Remove Lint Tools
# These tools are not required to run tests, so we are removing them to improve dependency resolving and
# testing lowest versions.
run: composer remove "*php-cs-fixer*" "*phpstan*" "*rector*" --dev --no-update

- name: Require elasticsearch dependency
run: composer require --dev elasticsearch/elasticsearch:"${{ matrix.elasticsearch-package-constraint }}" --no-interaction --no-update

- name: Install composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{matrix.dependency-versions}}
composer-options: ${{ matrix.composer-options }}
Expand All @@ -146,12 +176,12 @@ jobs:

steps:
- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
extensions: 'ctype, iconv, mysql, imagick'
tools: 'composer:v2'
coverage: none
Expand All @@ -160,7 +190,7 @@ jobs:
run: composer require --dev elasticsearch/elasticsearch:"~7.11.0" --no-interaction --no-update

- name: Install composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{matrix.dependency-versions}}
composer-options: ${{ matrix.composer-options }}
Expand Down
9 changes: 6 additions & 3 deletions Command/ArticleExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

class ArticleExportCommand extends Command
{
/**
* @var string
*/
protected static $defaultName = 'sulu:article:export';

/**
Expand All @@ -30,20 +33,20 @@ class ArticleExportCommand extends Command

public function __construct(ArticleExportInterface $articleExporter)
{
parent::__construct();
parent::__construct(static::$defaultName);

$this->articleExporter = $articleExporter;
}

protected function configure()
protected function configure(): void
{
$this->addArgument('target', InputArgument::REQUIRED, 'export.xliff')
->addArgument('locale', InputArgument::REQUIRED)
->addOption('format', 'f', InputOption::VALUE_REQUIRED, '', '1.2.xliff')
->setDescription('Export article translations from given language into xliff file for translating into a new language.');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$target = $input->getArgument('target');
if (0 === !\strpos($target, '/')) {
Expand Down
11 changes: 7 additions & 4 deletions Command/ArticleImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

class ArticleImportCommand extends Command
{
/**
* @var string
*/
protected static $defaultName = 'sulu:article:import';

/**
Expand All @@ -37,15 +40,15 @@ class ArticleImportCommand extends Command
*/
private $logger;

public function __construct(ArticleImportInterface $articleImporter, LoggerInterface $logger = null)
public function __construct(ArticleImportInterface $articleImporter, ?LoggerInterface $logger = null)
{
parent::__construct();
parent::__construct(static::$defaultName);

$this->articleImporter = $articleImporter;
$this->logger = $logger ?: new NullLogger();
}

protected function configure()
protected function configure(): void
{
$this->addArgument('file', InputArgument::REQUIRED, 'export.xliff')
->addArgument('locale', InputArgument::REQUIRED)
Expand All @@ -55,7 +58,7 @@ protected function configure()
->setDescription('Import article translations from xliff file into a specific language.');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$filePath = $input->getArgument('file');
if (0 === !\strpos($filePath, '/')) {
Expand Down
11 changes: 8 additions & 3 deletions Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
*/
class ReindexCommand extends Command
{
/**
* @var string
*/
protected static $defaultName = 'sulu:article:reindex';

/**
* @var WebspaceManagerInterface
*/
Expand Down Expand Up @@ -68,7 +73,7 @@ public function __construct(
IndexerInterface $liveIndexer,
string $suluContext
) {
parent::__construct('sulu:article:reindex');
parent::__construct(static::$defaultName);
$this->webspaceManager = $webspaceManager;
$this->propertyEncoder = $propertyEncoder;
$this->documentManager = $documentManager;
Expand All @@ -77,15 +82,15 @@ public function __construct(
$this->suluContext = $suluContext;
}

public function configure()
public function configure(): void
{
$this->setDescription('Rebuild elastic-search index for articles');
$this->setHelp('This command will load all articles and index them to elastic-search indexes.');
$this->addOption('drop', null, InputOption::VALUE_NONE, 'Drop and recreate index before reindex');
$this->addOption('clear', null, InputOption::VALUE_NONE, 'Clear all articles of index before reindex');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$startTime = \microtime(true);

Expand Down
26 changes: 24 additions & 2 deletions Content/ArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class ArticleDataProvider implements DataProviderInterface, DataProviderAliasInt
*/
private $tokenStorage;

/**
* @var bool
*/
private $hasAudienceTargeting;

public function __construct(
Manager $searchManager,
DocumentManagerInterface $documentManager,
Expand All @@ -93,8 +98,9 @@ public function __construct(
ArticleResourceItemFactory $articleResourceItemFactory,
string $articleDocumentClass,
int $defaultLimit,
MetadataProviderInterface $formMetadataProvider = null,
TokenStorageInterface $tokenStorage = null
?MetadataProviderInterface $formMetadataProvider = null,
?TokenStorageInterface $tokenStorage = null,
bool $hasAudienceTargeting = false
) {
$this->searchManager = $searchManager;
$this->documentManager = $documentManager;
Expand All @@ -105,6 +111,7 @@ public function __construct(
$this->defaultLimit = $defaultLimit;
$this->formMetadataProvider = $formMetadataProvider;
$this->tokenStorage = $tokenStorage;
$this->hasAudienceTargeting = $hasAudienceTargeting;
}

public function getConfiguration()
Expand All @@ -130,13 +137,18 @@ protected function getConfigurationBuilder(): BuilderInterface
['column' => 'created', 'title' => 'sulu_admin.created'],
['column' => 'title.raw', 'title' => 'sulu_admin.title'],
['column' => 'author_full_name.raw', 'title' => 'sulu_admin.author'],
['column' => 'last_modified_or_authored', 'title' => 'sulu_article.last_modified_or_authored'],
]
);

if (\method_exists($builder, 'enableTypes')) {
$builder->enableTypes($this->getTypes());
}

if ($this->hasAudienceTargeting) {
$builder->enableAudienceTargeting();
}

return $builder;
}

Expand Down Expand Up @@ -165,6 +177,7 @@ public function resolveDataItems(
$filters['types'] = $this->getTypesProperty($propertyParameter);
$filters['excluded'] = $this->getExcludedFilter($filters, $propertyParameter);

/** @var string|null $locale */
$locale = $options['locale'];
$webspaceKey = $this->getWebspaceKey($propertyParameter, $options);
$queryResult = $this->getSearchResult($filters, $limit, $page, $pageSize, $locale, $webspaceKey);
Expand Down Expand Up @@ -195,6 +208,7 @@ public function resolveResourceItems(
$filters['types'] = $this->getTypesProperty($propertyParameter);
$filters['excluded'] = $this->getExcludedFilter($filters, $propertyParameter);

/** @var string|null $locale */
$locale = $options['locale'];
$webspaceKey = $this->getWebspaceKey($propertyParameter, $options);
$queryResult = $this->getSearchResult($filters, $limit, $page, $pageSize, $locale, $webspaceKey);
Expand Down Expand Up @@ -298,6 +312,14 @@ private function getSearchResult(array $filters, ?int $limit, int $page, ?int $p
$search->addQuery($segmentQuery);
}

$targetGroup = $filters['targetGroupId'] ?? null;

if ($targetGroup) {
$targetGroupQuery = new BoolQuery();
$targetGroupQuery->add(new TermQuery('excerpt.audience_targeting_groups', $targetGroup), BoolQuery::MUST);
$search->addQuery($targetGroupQuery);
}

return $repository->findDocuments($search);
}

Expand Down
8 changes: 8 additions & 0 deletions Content/ArticleResourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public function getPublished(): \DateTime
return $this->article->getPublished();
}

/**
* Returns lastModified.
*/
public function getLastModified(): ?\DateTime
{
return $this->article->getLastModified();
}

/**
* Returns authored.
*/
Expand Down
4 changes: 3 additions & 1 deletion Content/PageTreeArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function resolveDatasource($datasource, array $propertyParameter, array $
return null;
}

$document = $this->documentManager->find($datasource, $options['locale']);
/** @var string|null $locale */
$locale = $options['locale'];
$document = $this->documentManager->find($datasource, $locale);

if (!$document instanceof BasePageDocument) {
return null;
Expand Down
22 changes: 17 additions & 5 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Sulu\Component\Rest\AbstractRestController;
use Sulu\Component\Rest\Exception\MissingParameterException;
use Sulu\Component\Rest\Exception\RestException;
use Sulu\Component\Rest\ListBuilder\FieldDescriptor;
use Sulu\Component\Rest\ListBuilder\FieldDescriptorInterface;
use Sulu\Component\Rest\ListBuilder\ListRepresentation;
use Sulu\Component\Rest\ListBuilder\ListRestHelperInterface;
Expand Down Expand Up @@ -173,6 +174,8 @@ protected function getFieldDescriptors(): array
->build(),
'title' => ElasticSearchFieldDescriptor::create('title', 'public.title')
->setSortField('title.raw')
->setSearchField('title')
->setSearchability(FieldDescriptor::SEARCHABILITY_YES)
->build(),
'creatorFullName' => ElasticSearchFieldDescriptor::create('creatorFullName', 'sulu_article.list.creator')
->setSortField('creatorFullName.raw')
Expand Down Expand Up @@ -208,6 +211,8 @@ protected function getFieldDescriptors(): array
->build(),
'routePath' => ElasticSearchFieldDescriptor::create('routePath')
->setVisibility(FieldDescriptorInterface::VISIBILITY_NO)
->setSearchField('route_path.value')
->setSearchability(FieldDescriptor::SEARCHABILITY_YES)
->build(),
];
}
Expand Down Expand Up @@ -248,9 +253,17 @@ public function cgetAction(Request $request): Response
$limit = \count($ids);
}

$fieldDescriptors = $this->getFieldDescriptors();

$searchFields = $this->restHelper->getSearchFields();
if (0 === \count($searchFields)) {
$searchFields = ['title'];
foreach ($fieldDescriptors as $fieldDescriptor) {
if (FieldDescriptorInterface::SEARCHABILITY_YES !== $fieldDescriptor->getSearchability()) {
continue;
}

$searchFields[] = $fieldDescriptor->getSearchField();
}
}

$searchPattern = $this->restHelper->getSearchPattern();
Expand Down Expand Up @@ -320,8 +333,8 @@ public function cgetAction(Request $request): Response
$search->addQuery(new MatchAllQuery());
}

if (null !== $this->restHelper->getSortColumn() &&
$sortField = $this->getSortFieldName($this->restHelper->getSortColumn())
if (null !== $this->restHelper->getSortColumn()
&& $sortField = $this->getSortFieldName($this->restHelper->getSortColumn())
) {
$search->addSort(
new FieldSort($sortField, $this->restHelper->getSortOrder())
Expand All @@ -332,8 +345,6 @@ public function cgetAction(Request $request): Response
);
}

$fieldDescriptors = $this->getFieldDescriptors();

if ($limit) {
$search->setSize($limit);
$search->setFrom(($page - 1) * $limit);
Expand Down Expand Up @@ -605,6 +616,7 @@ public function postTriggerAction(string $id, Request $request): Response
case 'copy':
/** @var ArticleDocument $document */
$document = $this->documentManager->find($id, $locale);
/** @var string $copiedPath */
$copiedPath = $this->documentManager->copy($document, \dirname($document->getPath()));
$this->documentManager->flush();

Expand Down
Loading

0 comments on commit c215b5e

Please sign in to comment.