Skip to content
Draft
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
19 changes: 19 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
use Setono\SyliusMeilisearchPlugin\Document\Product;
use Setono\SyliusMeilisearchPlugin\Event\QueryBuilderForDataProvisionCreated;
use Setono\SyliusMeilisearchPlugin\Filter\Entity\EntityFilterInterface;
use Setono\SyliusMeilisearchPlugin\Form\Type\IndexSettingsType;
use Setono\SyliusMeilisearchPlugin\Form\Type\SynonymType;
use Setono\SyliusMeilisearchPlugin\Indexer\DefaultIndexer;
use Setono\SyliusMeilisearchPlugin\Model\IndexSettings;
use Setono\SyliusMeilisearchPlugin\Model\Synonym;
use Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepository;
use Setono\SyliusMeilisearchPlugin\Repository\SynonymRepository;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\Factory\Factory;
Expand Down Expand Up @@ -174,6 +177,22 @@
->arrayNode('resources')
->addDefaultsIfNotSet()
->children()
->arrayNode('index_settings')
->addDefaultsIfNotSet()
->children()
->variableNode('options')->end()
->arrayNode('classes')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(IndexSettings::class)->cannotBeEmpty()->end()
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
->scalarNode('repository')->defaultValue(IndexSettingsRepository::class)->cannotBeEmpty()->end()

Check failure on line 189 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/DependencyInjection/Configuration.php:189:82: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepository depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 189 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/DependencyInjection/Configuration.php:189:82: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepository depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 189 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/DependencyInjection/Configuration.php:189:82: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepository depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)
->scalarNode('form')->defaultValue(IndexSettingsType::class)->end()
->scalarNode('factory')->defaultValue(Factory::class)->end()
->end()
->end()
->end()
->end()
->arrayNode('synonym')
->addDefaultsIfNotSet()
->children()
Expand Down
31 changes: 31 additions & 0 deletions src/DependencyInjection/SetonoSyliusMeilisearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ public function prepend(ContainerBuilder $container): void
],
],
'grids' => [
'setono_sylius_meilisearch_admin_index_settings' => [
'driver' => [
'name' => SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
'options' => [
'class' => '%setono_sylius_meilisearch.model.index_settings.class%',
],
],
'limits' => [100, 250, 500, 1000],
'fields' => [
'index' => [
'type' => 'string',
'label' => 'setono_sylius_meilisearch.ui.index',
],
],
'filters' => [
'search' => [
'type' => 'string',
'label' => 'sylius.ui.search',
'options' => [
'fields' => ['index'],
],
],
],
'actions' => [
'item' => [
'update' => [
'type' => 'update',
],
],
],
],
'setono_sylius_meilisearch_admin_synonym' => [
'driver' => [
'name' => SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
Expand Down
8 changes: 8 additions & 0 deletions src/EventSubscriber/AddMenuSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

$header = $this->getHeader($menu);

$header
->addChild('settings', [
'route' => 'setono_sylius_meilisearch_admin_index_settings_index',
])
->setLabel('setono_sylius_meilisearch.menu.admin.main.meilisearch.settings')
->setLabelAttribute('icon', 'cog')
;

Check warning on line 34 in src/EventSubscriber/AddMenuSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/AddMenuSubscriber.php#L28-L34

Added lines #L28 - L34 were not covered by tests

$header
->addChild('synonyms', [
'route' => 'setono_sylius_meilisearch_admin_synonym_index',
Expand Down
40 changes: 40 additions & 0 deletions src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\EventSubscriber;

use Setono\SyliusMeilisearchPlugin\Config\IndexRegistryInterface;
use Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface;
use Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class EnsureIndexSettingsAreCreatedSubscriber implements EventSubscriberInterface
{
public function __construct(

Check warning on line 14 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L14

Added line #L14 was not covered by tests
private readonly IndexRegistryInterface $indexRegistry,
private readonly IndexSettingsRepositoryInterface $indexSettingsRepository,

Check failure on line 16 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:16:9: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 16 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:16:9: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 16 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:16:9: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)
private readonly IndexSettingsFactoryInterface $indexSettingsFactory,

Check failure on line 17 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:17:9: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 17 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:17:9: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 17 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:17:9: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)
) {
}

Check warning on line 19 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L19

Added line #L19 was not covered by tests

public static function getSubscribedEvents(): array

Check warning on line 21 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L21

Added line #L21 was not covered by tests
{
return [
'setono_sylius_meilisearch.index_settings.index' => 'ensure',
];

Check warning on line 25 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L23-L25

Added lines #L23 - L25 were not covered by tests
}

public function ensure(): void

Check warning on line 28 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L28

Added line #L28 was not covered by tests
{
foreach ($this->indexRegistry->getNames() as $name) {
$indexSettings = $this->indexSettingsRepository->findOneByIndex($name);

Check failure on line 31 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:31:30: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 31 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:31:30: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 31 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:31:30: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)
if (null !== $indexSettings) {
continue;

Check warning on line 33 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L30-L33

Added lines #L30 - L33 were not covered by tests
}

$indexSettings = $this->indexSettingsFactory->createWithIndexName($name);

Check failure on line 36 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:36:30: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 36 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:36:30: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 36 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:36:30: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)
$this->indexSettingsRepository->add($indexSettings);

Check failure on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:37:13: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

UndefinedInterfaceMethod

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:37:45: UndefinedInterfaceMethod: Method Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface::add does not exist (see https://psalm.dev/181)

Check failure on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:37:13: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

UndefinedInterfaceMethod

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:37:45: UndefinedInterfaceMethod: Method Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface::add does not exist (see https://psalm.dev/181)

Check failure on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:37:13: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

UndefinedInterfaceMethod

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php:37:45: UndefinedInterfaceMethod: Method Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface::add does not exist (see https://psalm.dev/181)

Check warning on line 37 in src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php

View check run for this annotation

Codecov / codecov/patch

src/EventSubscriber/EnsureIndexSettingsAreCreatedSubscriber.php#L36-L37

Added lines #L36 - L37 were not covered by tests
}
}
}
34 changes: 34 additions & 0 deletions src/Factory/IndexSettingsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Factory;

use Setono\SyliusMeilisearchPlugin\Model\IndexSettingsInterface;
use Setono\SyliusMeilisearchPlugin\Settings\Settings;
use Sylius\Resource\Factory\FactoryInterface;

final class IndexSettingsFactory implements IndexSettingsFactoryInterface

Check failure on line 11 in src/Factory/IndexSettingsFactory.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/Factory/IndexSettingsFactory.php:11:45: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 11 in src/Factory/IndexSettingsFactory.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/Factory/IndexSettingsFactory.php:11:45: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 11 in src/Factory/IndexSettingsFactory.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/Factory/IndexSettingsFactory.php:11:45: MissingDependency: Setono\SyliusMeilisearchPlugin\Factory\IndexSettingsFactoryInterface depends on class or interface sylius\resource\factory\factoryinterface that does not exist (see https://psalm.dev/157)
{
public function __construct(

Check warning on line 13 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L13

Added line #L13 was not covered by tests
/** @var FactoryInterface<IndexSettingsInterface> $decorated */
private readonly FactoryInterface $decorated,
) {
}

Check warning on line 17 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L17

Added line #L17 was not covered by tests

public function createNew(): IndexSettingsInterface

Check warning on line 19 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L19

Added line #L19 was not covered by tests
{
$obj = $this->decorated->createNew();
$obj->setSettings(new Settings());

Check warning on line 22 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L21-L22

Added lines #L21 - L22 were not covered by tests

return $obj;

Check warning on line 24 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L24

Added line #L24 was not covered by tests
}

public function createWithIndexName(string $index): IndexSettingsInterface

Check warning on line 27 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L27

Added line #L27 was not covered by tests
{
$obj = $this->createNew();
$obj->setIndexName($index);

Check warning on line 30 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L29-L30

Added lines #L29 - L30 were not covered by tests

return $obj;

Check warning on line 32 in src/Factory/IndexSettingsFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factory/IndexSettingsFactory.php#L32

Added line #L32 was not covered by tests
}
}
18 changes: 18 additions & 0 deletions src/Factory/IndexSettingsFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Factory;

use Setono\SyliusMeilisearchPlugin\Model\IndexSettingsInterface;
use Sylius\Resource\Factory\FactoryInterface;

/**
* @extends FactoryInterface<IndexSettingsInterface>
*/
interface IndexSettingsFactoryInterface extends FactoryInterface
{
public function createNew(): IndexSettingsInterface;

public function createWithIndexName(string $index): IndexSettingsInterface;
}
19 changes: 19 additions & 0 deletions src/Form/Type/IndexSettingsType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Form\Type;

use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;

final class IndexSettingsType extends AbstractResourceType
{
public function buildForm(FormBuilderInterface $builder, array $options): void

Check warning on line 12 in src/Form/Type/IndexSettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/IndexSettingsType.php#L12

Added line #L12 was not covered by tests
{
$builder
->add('indexName', IndexChoiceType::class)
->add('settings', SettingsType::class)
;

Check warning on line 17 in src/Form/Type/IndexSettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/IndexSettingsType.php#L14-L17

Added lines #L14 - L17 were not covered by tests
}
}
34 changes: 34 additions & 0 deletions src/Form/Type/SettingsType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Form\Type;

use Setono\SyliusMeilisearchPlugin\Settings\Settings;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class SettingsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void

Check warning on line 14 in src/Form/Type/SettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/SettingsType.php#L14

Added line #L14 was not covered by tests
{
$reflection = new \ReflectionClass(Settings::class);
$properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
foreach ($properties as $property) {
$builder->add($property->getName());

Check warning on line 19 in src/Form/Type/SettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/SettingsType.php#L16-L19

Added lines #L16 - L19 were not covered by tests
}
}

public function configureOptions(OptionsResolver $resolver): void

Check warning on line 23 in src/Form/Type/SettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/SettingsType.php#L23

Added line #L23 was not covered by tests
{
$resolver->setDefaults([
'data_class' => Settings::class,
]);

Check warning on line 27 in src/Form/Type/SettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/SettingsType.php#L25-L27

Added lines #L25 - L27 were not covered by tests
}

public function getBlockPrefix(): string

Check warning on line 30 in src/Form/Type/SettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/SettingsType.php#L30

Added line #L30 was not covered by tests
{
return 'setono_sylius_meilisearch_settings';

Check warning on line 32 in src/Form/Type/SettingsType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/SettingsType.php#L32

Added line #L32 was not covered by tests
}
}
47 changes: 47 additions & 0 deletions src/Model/IndexSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Model;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Settings\Settings;

class IndexSettings implements IndexSettingsInterface
{
protected ?int $id = null;

protected ?string $indexName = null;

protected ?Settings $settings = null;

public function getId(): ?int

Check warning on line 18 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L18

Added line #L18 was not covered by tests
{
return $this->id;

Check warning on line 20 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L20

Added line #L20 was not covered by tests
}

public function setId(?int $id): void

Check warning on line 23 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L23

Added line #L23 was not covered by tests
{
$this->id = $id;

Check warning on line 25 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L25

Added line #L25 was not covered by tests
}

public function getIndexName(): ?string

Check warning on line 28 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L28

Added line #L28 was not covered by tests
{
return $this->indexName;

Check warning on line 30 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L30

Added line #L30 was not covered by tests
}

public function setIndexName(Index|string|null $indexName): void

Check warning on line 33 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L33

Added line #L33 was not covered by tests
{
$this->indexName = $indexName instanceof Index ? $indexName->name : $indexName;

Check warning on line 35 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L35

Added line #L35 was not covered by tests
}

public function getSettings(): ?Settings

Check warning on line 38 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L38

Added line #L38 was not covered by tests
{
return $this->settings;

Check warning on line 40 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L40

Added line #L40 was not covered by tests
}

public function setSettings(?Settings $settings): void

Check warning on line 43 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L43

Added line #L43 was not covered by tests
{
$this->settings = $settings;

Check warning on line 45 in src/Model/IndexSettings.php

View check run for this annotation

Codecov / codecov/patch

src/Model/IndexSettings.php#L45

Added line #L45 was not covered by tests
}
}
22 changes: 22 additions & 0 deletions src/Model/IndexSettingsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Model;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Settings\Settings;
use Sylius\Component\Resource\Model\ResourceInterface;

interface IndexSettingsInterface extends ResourceInterface
{
public function getId(): ?int;

public function getIndexName(): ?string;

public function setIndexName(Index|string|null $indexName): void;

public function getSettings(): ?Settings;

public function setSettings(?Settings $settings): void;
}
23 changes: 23 additions & 0 deletions src/Repository/IndexSettingsRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Repository;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Model\IndexSettingsInterface;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Webmozart\Assert\Assert;

class IndexSettingsRepository extends EntityRepository implements IndexSettingsRepositoryInterface

Check failure on line 12 in src/Repository/IndexSettingsRepository.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

src/Repository/IndexSettingsRepository.php:12:67: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 12 in src/Repository/IndexSettingsRepository.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~6.4.0)

MissingDependency

src/Repository/IndexSettingsRepository.php:12:67: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)

Check failure on line 12 in src/Repository/IndexSettingsRepository.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

src/Repository/IndexSettingsRepository.php:12:67: MissingDependency: Setono\SyliusMeilisearchPlugin\Repository\IndexSettingsRepositoryInterface depends on class or interface sylius\resource\doctrine\persistence\repositoryinterface that does not exist (see https://psalm.dev/157)
{
public function findOneByIndex(string|Index $index): ?IndexSettingsInterface

Check warning on line 14 in src/Repository/IndexSettingsRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Repository/IndexSettingsRepository.php#L14

Added line #L14 was not covered by tests
{
$index = $index instanceof Index ? $index->name : $index;

Check warning on line 16 in src/Repository/IndexSettingsRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Repository/IndexSettingsRepository.php#L16

Added line #L16 was not covered by tests

$obj = $this->findOneBy(['index' => $index]);
Assert::nullOrIsInstanceOf($obj, IndexSettingsInterface::class);

Check warning on line 19 in src/Repository/IndexSettingsRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Repository/IndexSettingsRepository.php#L18-L19

Added lines #L18 - L19 were not covered by tests

return $obj;

Check warning on line 21 in src/Repository/IndexSettingsRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Repository/IndexSettingsRepository.php#L21

Added line #L21 was not covered by tests
}
}
17 changes: 17 additions & 0 deletions src/Repository/IndexSettingsRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusMeilisearchPlugin\Repository;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Model\IndexSettingsInterface;
use Sylius\Resource\Doctrine\Persistence\RepositoryInterface;

/**
* @extends RepositoryInterface<IndexSettingsInterface>
*/
interface IndexSettingsRepositoryInterface extends RepositoryInterface
{
public function findOneByIndex(string|Index $index): ?IndexSettingsInterface;
}
16 changes: 16 additions & 0 deletions src/Resources/config/doctrine/model/IndexSettings.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Setono\SyliusMeilisearchPlugin\Model\IndexSettings"
table="setono_sylius_meilisearch__index_settings">
<id name="id" type="integer">
<generator strategy="AUTO"/>
</id>

<field name="indexName" type="string" unique="true"/>
<field name="settings" type="json"/>
</mapped-superclass>
</doctrine-mapping>
16 changes: 16 additions & 0 deletions src/Resources/config/routes/admin.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
setono_sylius_meilisearch_admin_index_settings:
resource: |
section: admin
alias: setono_sylius_meilisearch.index_settings
templates: "@SyliusAdmin\\Crud"
redirect: index
permission: true
grid: setono_sylius_meilisearch_admin_index_settings
vars:
all:
header: setono_sylius_meilisearch.ui.index_settings_header
subheader: setono_sylius_meilisearch.ui.index_settings_subheader
templates:
form: "@SetonoSyliusMeilisearchPlugin/admin/index_settings/_form.html.twig"
type: sylius.resource

setono_sylius_meilisearch_admin_synonym:
resource: |
section: admin
Expand Down
Loading
Loading