Skip to content

Commit ca1a3a3

Browse files
committed
feat: implement MappingGenerator indexes filtering
Implement the previously unused $indexes parameter in MappingGenerator::reload() to allow selective index reloading. * Add index name filtering logic - skip indexes not in the filter list * Add file_exists() check before include() to prevent warnings * Add @mixin annotation to Connection class for better IDE support When $indexes is null, all indexes are reloaded (default behavior). When an array is provided, only matching indexes are processed.
1 parent ba0fdd2 commit ca1a3a3

6 files changed

Lines changed: 366 additions & 11 deletions

File tree

phpstan.neon

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,23 @@ parameters:
1515
identifier: trait.unused
1616
count: 1
1717
path: src/Datasource/IndexLocatorAwareTrait.php
18-
1918
-
2019
message: '#^Access to an undefined property Cake\\Datasource\\EntityInterface\:\:\$version\.$#'
2120
identifier: property.notFound
2221
count: 1
2322
path: src/Index.php
24-
2523
-
2624
message: '#^Method Cake\\ElasticSearch\\Query\:\:all\(\) should return Cake\\Datasource\\ResultSetInterface but returns iterable\.$#'
2725
identifier: return.type
2826
count: 1
2927
path: src/Query.php
30-
31-
32-
33-
3428
-
3529
message: '#^Method Cake\\ElasticSearch\\Query\:\:find\(\) should return static\(Cake\\ElasticSearch\\Query\<TSubject of array\|Cake\\ElasticSearch\\Document\>\) but returns Cake\\ElasticSearch\\Query\<Cake\\ElasticSearch\\Document\>\.$#'
3630
identifier: return.type
3731
count: 1
3832
path: src/Query.php
39-
4033
-
4134
message: '#^Class Cake\\ElasticSearch\\ResultSet @implements tag contains incompatible type Cake\\Datasource\\ResultSetInterface&iterable\<T of array\|Cake\\Datasource\\EntityInterface\>\.$#'
4235
identifier: generics.notCompatible
4336
count: 1
44-
path: src/ResultSet.php
37+
path: src/ResultSet.php

src/Datasource/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
use Psr\SimpleCache\CacheInterface;
3030
use RuntimeException;
3131

32+
/**
33+
* @mixin \Elastica\Client
34+
* @package Cake\ElasticSearch\Datasource
35+
*/
3236
class Connection implements ConnectionInterface
3337
{
3438
protected array $_config;

src/TestSuite/Fixture/MappingGenerator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(string $file, string $connection)
5050
/**
5151
* Drop and re-create indexes defined in the mapping schema file.
5252
*
53-
* @param array<string> $indexes A subset of indexes to reload. Used for testing.
53+
* @param array<string>|null $indexes A subset of index names to reload. If null, all indexes are reloaded.
5454
*/
5555
public function reload(?array $indexes = null): void
5656
{
@@ -62,6 +62,10 @@ public function reload(?array $indexes = null): void
6262
));
6363
}
6464

65+
if (!file_exists($this->file)) {
66+
throw new RuntimeException(sprintf('The `%s` file does not exist.', $this->file));
67+
}
68+
6569
$mappings = include $this->file;
6670
if (empty($mappings)) {
6771
throw new RuntimeException(sprintf('The `%s` file did not return any mapping data.', $this->file));
@@ -72,6 +76,11 @@ public function reload(?array $indexes = null): void
7276
throw new RuntimeException(sprintf('The mapping at index %s does not have a name.', $i));
7377
}
7478

79+
// Skip if indexes filter is provided and this index is not in the list
80+
if ($indexes !== null && !in_array($mapping['name'], $indexes, true)) {
81+
continue;
82+
}
83+
7584
$this->dropIndex($db, $mapping['name']);
7685
$this->createIndex($db, $mapping);
7786
}

tests/TestCase/MarshallerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testOneFieldList(): void
142142
/**
143143
* test marshalling with accessibleFields
144144
*/
145-
public function testOneAccsesibleFields(): void
145+
public function testOneAccessibleFields(): void
146146
{
147147
$data = [
148148
'title' => 'Testing',

0 commit comments

Comments
 (0)