Skip to content

Option to listen to postRemove event #96

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

Merged
merged 13 commits into from
Jul 1, 2021
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
15 changes: 1 addition & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
charset = utf-8
tab_width = 4
indent_style = space

[*.php]
indent_size = 4

[*{.xml, .dist}]
indent_size = 4
max_line_length = 120

[*.md]
max_line_length = 80

[*{.yaml, .yml}]
indent_size = 4

[*.json]
indent_size = 4
34 changes: 24 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
version: 2

updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
labels:
- dependencies
- skip-changelog
rebase-strategy: disabled
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
labels:
- dependencies
- skip-changelog
rebase-strategy: disabled

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
time: "04:00"
commit-message:
include: "scope"
prefix: "github-actions"
labels:
- dependencies
- skip-changelog
open-pull-requests-limit: 10
19 changes: 14 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,33 @@ jobs:
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress --quiet
- name: MeiliSearch setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics=true
- name: Check
run: curl http://127.0.0.1:7700
- name: Run test suite
run: composer test:unit

linter:
code-style:
runs-on: ubuntu-latest
name: linter-check
name: 'Code style'
steps:
- uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run linter
run: composer install --prefer-dist --no-progress --quiet

- name: PHP CS Fixer
run: composer lint:check

- name: PHPstan
run: composer phpstan
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.idea
/composer.lock

composer.lock
/vendor/
.phpunit.result.cache
/var/

# Meilisearch
/data.ms/*

# PhpUnit
.phpunit.result.cache
.php-cs-fixer.cache
/tests/coverage
7 changes: 2 additions & 5 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

declare(strict_types=1);

if (!file_exists(__DIR__.'/src')) {
exit(0);
}

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->append([__FILE__]);
$config = new PhpCsFixer\Config();

$config->setRules([
'@Symfony' => true,
'declare_strict_types' => true,
'@PHP80Migration:risky' => true,
'global_namespace_import' => [
'import_classes' => false,
'import_functions' => false,
Expand Down
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
"doctrine/orm": "^2.9",
"friendsofphp/php-cs-fixer": "^3.0",
"nyholm/psr7": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan-doctrine": "^0.12.39",
"phpstan/phpstan-phpunit": "^0.12.20",
"phpstan/phpstan-symfony": "^0.12.37",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
"symfony/doctrine-bridge": "^4.0 || ^5.0",
"symfony/http-client": "^4.0 || ^5.0",
Expand All @@ -51,8 +57,10 @@
"sort-packages": true
},
"scripts": {
"test:unit": "phpunit --colors=always --verbose",
"lint:check": "php-cs-fixer fix -v --using-cache=no --dry-run",
"lint:fix": "php-cs-fixer fix -v --using-cache=no"
"phpstan": "./vendor/bin/phpstan --memory-limit=128 --ansi",
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5
paths:
- src
- tests
51 changes: 26 additions & 25 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" convertDeprecationsToExceptions="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>src/</directory>
</include>
<exclude>
<file>src/DependencyInjection/MeiliSearchExtension.php</file>
<file>src/Services/NullSearchService.php</file>
</exclude>
</coverage>
<php>
<env name="KERNEL_CLASS" value="MeiliSearch\Bundle\Test\Kernel"/>
<env name="APP_ENV" value="test"/>
<env name="APP_DEBUG" value="false"/>
<env name="MEILISEARCH_PREFIX" value="sf_phpunit_"/>
<env name="MEILISEARCH_URL" value="http://127.0.0.1:7700"/>
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
<env name="TRAVIS_JOB_NUMBER" value=""/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
</php>
<testsuites>
<testsuite name="TestCase">
<directory suffix=".php">tests/TestCase/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php"
convertDeprecationsToExceptions="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
<coverage>
<include>
<directory>src/</directory>
</include>
</coverage>
<php>
<env name="KERNEL_CLASS" value="MeiliSearch\Bundle\Test\Kernel"/>
<env name="APP_ENV" value="test"/>
<env name="APP_DEBUG" value="false"/>
<env name="MEILISEARCH_PREFIX" value="sf_phpunit_"/>
<env name="MEILISEARCH_URL" value="http://127.0.0.1:7700"/>
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
<env name="TRAVIS_JOB_NUMBER" value=""/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
</php>
<testsuites>
<testsuite name="Integration">
<directory suffix=".php">tests/Integration</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix=".php">tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
6 changes: 2 additions & 4 deletions src/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o

if ($indexList = $input->getOption('indices')) {
$list = \explode(',', $indexList);
$indexNames = collect($list)->transform(function (string $item) {
$indexNames = collect($list)->transform(function (string $item): string {
// Check if the given index name already contains the prefix
if (false === strpos($item, $this->prefix)) {
return $this->prefix.$item;
Expand All @@ -64,8 +64,6 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
);
}

return collect($this->getIndices())->reject(function (array $item) use ($indexNames) {
return !in_array($item['name'], $indexNames->toArray(), true);
});
return collect($this->getIndices())->reject(fn (array $item) => !in_array($item['name'], $indexNames->toArray(), true));
}
}
4 changes: 2 additions & 2 deletions src/Command/MeiliSearchClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class MeiliSearchClearCommand extends IndexCommand
{
protected static $defaultName = 'meili:clear';

protected function configure()
protected function configure(): void
{
$this
->setDescription('Clear the index documents')
Expand All @@ -26,7 +26,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$indexToClear = $this->getEntitiesFromArgs($input, $output);

/** @var array $index */
/** @var array<string, mixed> $index */
foreach ($indexToClear as $index) {
$indexName = $index['name'];
$className = $index['class'];
Expand Down
10 changes: 5 additions & 5 deletions src/Command/MeiliSearchImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(SearchService $searchService, ManagerRegistry $manag
$this->searchClient = $searchClient;
}

protected function configure()
protected function configure(): void
{
$this
->setDescription('Import given entity into search engine')
Expand All @@ -56,9 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$indexes = collect(array_merge(
$indexes->toArray(),
array_map(
function ($entity) {
return ['class' => $entity];
},
fn ($entity) => ['class' => $entity],
$entityClassName::getEntities()
)
));
Expand Down Expand Up @@ -101,7 +99,9 @@ function ($entity) {
);
}

if (!empty($index['settings'])) {
if (isset($index['settings'])
&& is_array($index['settings'])
&& count($index['settings']) > 0) {
$indexInstance = $this->searchClient->getOrCreateIndex($index['name']);
foreach ($index['settings'] as $variable => $value) {
$method = sprintf('update%s', ucfirst($variable));
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Class Configuration.
*/
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
Expand Down
2 changes: 1 addition & 1 deletion src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function remove($searchableEntities): array
/** @var SearchableEntity $entity */
foreach ($searchableEntities as $entity) {
$searchableArray = $entity->getSearchableArray();
if (null === $searchableArray || 0 === \count($searchableArray)) {
if (0 === \count($searchableArray)) {
continue;
}
$indexUid = $entity->getIndexUid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
use Doctrine\Persistence\Event\LifecycleEventArgs;
use MeiliSearch\Bundle\SearchService;

/**
* Class MeiliSearchIndexerSubscriber.
*/
final class MeiliSearchIndexerSubscriber implements EventSubscriber
final class DoctrineEventSubscriber implements EventSubscriber
{
private SearchService $searchService;
private array $subscribedEvents;
Expand Down
11 changes: 4 additions & 7 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults autowire="true" autoconfigure="true"/>

<prototype namespace="MeiliSearch\Bundle\Command\" resource="../../Command" autowire="true"
autoconfigure="true"/>

<service id="MeiliSearch\Bundle\Command\MeiliSearchImportCommand" autowire="true" autoconfigure="true"/>
<prototype namespace="MeiliSearch\Bundle\Command\" resource="../../Command" />

<service id="search.search_indexer_subscriber"
class="MeiliSearch\Bundle\EventListener\MeiliSearchIndexerSubscriber"
class="MeiliSearch\Bundle\EventListener\DoctrineEventSubscriber"
public="true">
<argument type="service" id="search.service"/>
<argument type="collection"/> <!-- doctrine subscribed events -->
Expand All @@ -25,7 +23,6 @@
</service>

<service id="MeiliSearch\Client" alias="search.client"/>

<service id="MeiliSearch\Bundle\SearchService" alias="search.service"/>
</services>
</container>
7 changes: 6 additions & 1 deletion src/SearchableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public function getIndexUid(): string
*/
public function getSearchableArray(): array
{
$context = ['fieldsMapping' => $this->entityMetadata->fieldMappings];
/** @var \Doctrine\ORM\Mapping\ClassMetadataInfo&\Doctrine\Persistence\Mapping\ClassMetadata $metadata */
$metadata = $this->entityMetadata;

$context = [
'fieldsMapping' => $metadata->fieldMappings,
];

if ($this->useSerializerGroups) {
$context['groups'] = [Searchable::NORMALIZATION_GROUP];
Expand Down
Loading