Skip to content

Commit b3607d9

Browse files
authored
PHPLIB-1057: Deprecate method IndexInfo::isGeoHaystack() (#1085)
MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release
1 parent 7e63041 commit b3607d9

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ MongoDB\\Model\\IndexInfo::isGeoHaystack()
44

55
.. versionadded:: 1.4
66

7+
.. deprecated:: 1.16
8+
MongoDB 5.0 and later no longer supports geoHaystack indexes.
9+
710
.. default-domain:: mongodb
811

912
.. contents:: On this page
@@ -24,10 +27,6 @@ Definition
2427

2528
function isGeoHaystack(): boolean
2629

27-
.. note::
28-
29-
MongoDB 5.0 and later no longer supports geoHaystack indexes.
30-
3130
Return Values
3231
-------------
3332

src/Model/IndexInfo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
use function array_key_exists;
2525
use function array_search;
26+
use function trigger_error;
27+
28+
use const E_USER_DEPRECATED;
2629

2730
/**
2831
* Index information model class.
@@ -124,9 +127,12 @@ public function is2dSphere()
124127
* Return whether or not this index is of type geoHaystack.
125128
*
126129
* @return boolean
130+
* @deprecated Since 1.16: MongoDB 5.0 removes support for geoHaystack indexes.
127131
*/
128132
public function isGeoHaystack()
129133
{
134+
trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED);
135+
130136
return array_search('geoHaystack', $this->getKey(), true) !== false;
131137
}
132138

tests/Model/IndexInfoFunctionalTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public function testIsGeoHaystack(): void
5050
$index = $result->current();
5151

5252
$this->assertEquals($indexName, $index->getName());
53-
$this->assertTrue($index->isGeoHaystack());
53+
$this->assertDeprecated(function () use ($index): void {
54+
$this->assertTrue($index->isGeoHaystack());
55+
});
5456
$this->assertEquals(5, $index['bucketSize']);
5557
}
5658

tests/Model/IndexInfoTest.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public function testBasicIndex(): void
2222
$this->assertSame('x_1', $info->getName());
2323
$this->assertSame('foo.bar', $info->getNamespace());
2424
$this->assertFalse($info->is2dSphere());
25-
$this->assertFalse($info->isGeoHaystack());
25+
$this->assertDeprecated(function () use ($info): void {
26+
$this->assertFalse($info->isGeoHaystack());
27+
});
2628
$this->assertFalse($info->isSparse());
2729
$this->assertFalse($info->isText());
2830
$this->assertFalse($info->isTtl());
@@ -44,7 +46,9 @@ public function testSparseIndex(): void
4446
$this->assertSame('y_sparse', $info->getName());
4547
$this->assertSame('foo.bar', $info->getNamespace());
4648
$this->assertFalse($info->is2dSphere());
47-
$this->assertFalse($info->isGeoHaystack());
49+
$this->assertDeprecated(function () use ($info): void {
50+
$this->assertFalse($info->isGeoHaystack());
51+
});
4852
$this->assertTrue($info->isSparse());
4953
$this->assertFalse($info->isText());
5054
$this->assertFalse($info->isTtl());
@@ -66,7 +70,9 @@ public function testUniqueIndex(): void
6670
$this->assertSame('z_unique', $info->getName());
6771
$this->assertSame('foo.bar', $info->getNamespace());
6872
$this->assertFalse($info->is2dSphere());
69-
$this->assertFalse($info->isGeoHaystack());
73+
$this->assertDeprecated(function () use ($info): void {
74+
$this->assertFalse($info->isGeoHaystack());
75+
});
7076
$this->assertFalse($info->isSparse());
7177
$this->assertFalse($info->isText());
7278
$this->assertFalse($info->isTtl());
@@ -88,7 +94,9 @@ public function testTtlIndex(): void
8894
$this->assertSame('z_unique', $info->getName());
8995
$this->assertSame('foo.bar', $info->getNamespace());
9096
$this->assertFalse($info->is2dSphere());
91-
$this->assertFalse($info->isGeoHaystack());
97+
$this->assertDeprecated(function () use ($info): void {
98+
$this->assertFalse($info->isGeoHaystack());
99+
});
92100
$this->assertFalse($info->isSparse());
93101
$this->assertFalse($info->isText());
94102
$this->assertTrue($info->isTtl());
@@ -166,7 +174,9 @@ public function testIs2dSphere(): void
166174
$this->assertSame('pos_2dsphere', $info->getName());
167175
$this->assertSame('foo.bar', $info->getNamespace());
168176
$this->assertTrue($info->is2dSphere());
169-
$this->assertFalse($info->isGeoHaystack());
177+
$this->assertDeprecated(function () use ($info): void {
178+
$this->assertFalse($info->isGeoHaystack());
179+
});
170180
$this->assertFalse($info->isSparse());
171181
$this->assertFalse($info->isText());
172182
$this->assertFalse($info->isTtl());
@@ -187,7 +197,9 @@ public function testIsGeoHaystack(): void
187197
$this->assertSame('pos2_geoHaystack_x_1', $info->getName());
188198
$this->assertSame('foo.bar', $info->getNamespace());
189199
$this->assertFalse($info->is2dSphere());
190-
$this->assertTrue($info->isGeoHaystack());
200+
$this->assertDeprecated(function () use ($info): void {
201+
$this->assertTrue($info->isGeoHaystack());
202+
});
191203
$this->assertFalse($info->isSparse());
192204
$this->assertFalse($info->isText());
193205
$this->assertFalse($info->isTtl());
@@ -208,7 +220,9 @@ public function testIsText(): void
208220
$this->assertSame('title_text_description_text', $info->getName());
209221
$this->assertSame('foo.bar', $info->getNamespace());
210222
$this->assertFalse($info->is2dSphere());
211-
$this->assertFalse($info->isGeoHaystack());
223+
$this->assertDeprecated(function () use ($info): void {
224+
$this->assertFalse($info->isGeoHaystack());
225+
});
212226
$this->assertFalse($info->isSparse());
213227
$this->assertTrue($info->isText());
214228
$this->assertFalse($info->isTtl());

0 commit comments

Comments
 (0)