Skip to content

Commit 7dc9d50

Browse files
committed
Require ext-mongodb >= 1.7.0
- Enforce that ReadPreference is a string - Switch from ReadPreference->getMode() to getModeString()
1 parent a16a0c3 commit 7dc9d50

15 files changed

Lines changed: 95 additions & 141 deletions

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"require": {
2424
"php" : ">=7.4",
25+
"ext-mongodb": ">=1.7.0",
2526
"mongodb/mongodb": "*",
2627
"monolog/monolog" : "~1.13",
2728
"semsol/arc2": "2.2.6"

phpstan.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ parameters:
55
max: 80599 # PHP 8.5
66
tips:
77
treatPhpDocTypesAsCertain: false
8-
ignoreErrors:
9-
- '#Access to undefined constant MongoDB\\Driver\\ReadPreference\:\:RP_.*#'
10-
- '#Call to an undefined method MongoDB\\Driver\\ReadPreference\:\:getMode\(\)#'
11-
- identifier: missingType.iterableValue
12-
reportUnmatched: false
13-
- identifier: unset.possiblyHookedProperty
14-
reportUnmatched: false
158
paths:
169
- src
1710
- test

src/mongo/Config.php

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,9 @@ public function getSearchProviderClassName(string $storeName): ?string
571571
}
572572

573573
/**
574-
* @param int|string $readPreference
575-
*
576574
* @throws ConfigException
577575
*/
578-
public function getDatabase(string $storeName, ?string $dataSource = null, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Database
576+
public function getDatabase(string $storeName, ?string $dataSource = null, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Database
579577
{
580578
if (!isset($this->dbConfig[$storeName])) {
581579
throw new ConfigException(sprintf("Store name '%s' not in configuration", $storeName));
@@ -593,11 +591,9 @@ public function getDatabase(string $storeName, ?string $dataSource = null, $read
593591
}
594592

595593
/**
596-
* @param int|string $readPreference
597-
*
598594
* @throws ConfigException
599595
*/
600-
public function getCollectionForCBD(string $storeName, string $podName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
596+
public function getCollectionForCBD(string $storeName, string $podName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
601597
{
602598
if (isset($this->podConnections[$storeName], $this->podConnections[$storeName][$podName])) {
603599
return $this->getMongoCollection(
@@ -610,11 +606,9 @@ public function getCollectionForCBD(string $storeName, string $podName, $readPre
610606
}
611607

612608
/**
613-
* @param int|string $readPreference
614-
*
615609
* @throws ConfigException
616610
*/
617-
public function getCollectionForView(string $storeName, string $viewId, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
611+
public function getCollectionForView(string $storeName, string $viewId, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
618612
{
619613
if (!isset($this->viewSpecs[$storeName][$viewId])) {
620614
throw new ConfigException(sprintf("View id '%s' not in configuration for store '%s'", $viewId, $storeName));
@@ -629,11 +623,9 @@ public function getCollectionForView(string $storeName, string $viewId, $readPre
629623
}
630624

631625
/**
632-
* @param int|string $readPreference
633-
*
634626
* @throws ConfigException
635627
*/
636-
public function getCollectionForSearchDocument(string $storeName, string $searchDocumentId, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
628+
public function getCollectionForSearchDocument(string $storeName, string $searchDocumentId, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
637629
{
638630
if (!isset($this->searchDocSpecs[$storeName][$searchDocumentId])) {
639631
throw new ConfigException(sprintf("Search document id '%s' not in configuration for store '%s'", $searchDocumentId, $storeName));
@@ -648,11 +640,9 @@ public function getCollectionForSearchDocument(string $storeName, string $search
648640
}
649641

650642
/**
651-
* @param int|string $readPreference
652-
*
653643
* @throws ConfigException
654644
*/
655-
public function getCollectionForTable(string $storeName, string $tableId, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
645+
public function getCollectionForTable(string $storeName, string $tableId, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
656646
{
657647
if (!isset($this->tableSpecs[$storeName][$tableId])) {
658648
throw new ConfigException(sprintf("Table id '%s' not in configuration for store '%s'", $tableId, $storeName));
@@ -667,13 +657,11 @@ public function getCollectionForTable(string $storeName, string $tableId, $readP
667657
}
668658

669659
/**
670-
* @param int|string $readPreference
671-
*
672660
* @return Collection[]
673661
*
674662
* @throws ConfigException
675663
*/
676-
public function getCollectionsForTables(string $storeName, array $tables = [], $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): array
664+
public function getCollectionsForTables(string $storeName, array $tables = [], string $readPreference = ReadPreference::PRIMARY_PREFERRED): array
677665
{
678666
if (!isset($this->tableSpecs[$storeName])) {
679667
return [];
@@ -704,13 +692,11 @@ public function getCollectionsForTables(string $storeName, array $tables = [], $
704692
}
705693

706694
/**
707-
* @param int|string $readPreference
708-
*
709695
* @return Collection[]
710696
*
711697
* @throws ConfigException
712698
*/
713-
public function getCollectionsForViews(string $storeName, array $views = [], $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): array
699+
public function getCollectionsForViews(string $storeName, array $views = [], string $readPreference = ReadPreference::PRIMARY_PREFERRED): array
714700
{
715701
if (!isset($this->viewSpecs[$storeName])) {
716702
return [];
@@ -741,13 +727,11 @@ public function getCollectionsForViews(string $storeName, array $views = [], $re
741727
}
742728

743729
/**
744-
* @param int|string $readPreference
745-
*
746730
* @return Collection[]
747731
*
748732
* @throws ConfigException
749733
*/
750-
public function getCollectionsForSearch(string $storeName, array $searchSpecIds = [], $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): array
734+
public function getCollectionsForSearch(string $storeName, array $searchSpecIds = [], string $readPreference = ReadPreference::PRIMARY_PREFERRED): array
751735
{
752736
if (!isset($this->searchDocSpecs[$storeName])) {
753737
return [];
@@ -777,43 +761,31 @@ public function getCollectionsForSearch(string $storeName, array $searchSpecIds
777761
return $collections;
778762
}
779763

780-
/**
781-
* @param int|string $readPreference
782-
*/
783-
public function getCollectionForTTLCache(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
764+
public function getCollectionForTTLCache(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
784765
{
785766
return $this->getMongoCollection(
786767
$this->getDatabase($storeName, $this->dbConfig[$storeName]['data_source'], $readPreference),
787768
TTL_CACHE_COLLECTION
788769
);
789770
}
790771

791-
/**
792-
* @param int|string $readPreference
793-
*/
794-
public function getCollectionForLocks(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
772+
public function getCollectionForLocks(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
795773
{
796774
return $this->getMongoCollection(
797775
$this->getDatabase($storeName, $this->dbConfig[$storeName]['data_source'], $readPreference),
798776
LOCKS_COLLECTION
799777
);
800778
}
801779

802-
/**
803-
* @param int|string $readPreference
804-
*/
805-
public function getCollectionForManualRollbackAudit(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
780+
public function getCollectionForManualRollbackAudit(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
806781
{
807782
return $this->getMongoCollection(
808783
$this->getDatabase($storeName, $this->dbConfig[$storeName]['data_source'], $readPreference),
809784
AUDIT_MANUAL_ROLLBACKS_COLLECTION
810785
);
811786
}
812787

813-
/**
814-
* @param int|string $readPreference
815-
*/
816-
public function getCollectionForJobGroups(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection
788+
public function getCollectionForJobGroups(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection
817789
{
818790
return $this->getMongoCollection(
819791
$this->getDatabase($storeName, $this->dbConfig[$storeName]['data_source'], $readPreference),
@@ -822,11 +794,11 @@ public function getCollectionForJobGroups(string $storeName, $readPreference = R
822794
}
823795

824796
/**
825-
* @param int|string $readPreference
797+
* @param string $readPreference
826798
*
827799
* @throws ConfigException
828800
*/
829-
public function getTransactionLogDatabase($readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Database
801+
public function getTransactionLogDatabase($readPreference = ReadPreference::PRIMARY_PREFERRED): Database
830802
{
831803
$client = $this->getConnectionForDataSource($this->tConfig['data_source']);
832804
$db = $client->selectDatabase($this->tConfig['database']);

src/mongo/Driver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Driver extends DriverBase implements IDriver
4141
* <li>defaultContext: (string) to use where a specific default context is not defined. Default is Null</li>
4242
* <li>async: (array) determines the async behaviour of views, tables and search. For each of these array keys, if set to true, generation of these elements will be done asyncronously on save. Default is array(OP_VIEWS=>false,OP_TABLES=>true,OP_SEARCH=>true)</li>
4343
* <li>stat: this sets the stats object to use to record statistics around operations performed by Driver. Default is null</li>
44-
* <li>readPreference: The Read preference to set for Mongo: Default is ReadPreference::RP_PRIMARY_PREFERRED</li>
44+
* <li>readPreference: The Read preference to set for Mongo: Default is ReadPreference::PRIMARY_PREFERRED</li>
4545
* <li>retriesToGetLock: Retries to do when unable to get lock on a document, default is 20</li></ul>
4646
*/
4747
public function __construct(string $podName, string $storeName, array $opts = [])
@@ -50,7 +50,7 @@ public function __construct(string $podName, string $storeName, array $opts = []
5050
'defaultContext' => null,
5151
OP_ASYNC => [OP_VIEWS => false, OP_TABLES => true, OP_SEARCH => true],
5252
'statsConfig' => [],
53-
'readPreference' => ReadPreference::RP_PRIMARY_PREFERRED,
53+
'readPreference' => ReadPreference::PRIMARY_PREFERRED,
5454
'retriesToGetLock' => 20,
5555
], $opts);
5656

@@ -618,7 +618,7 @@ protected function getLabeller(): Labeller
618618
protected function getDataUpdater(): Updates
619619
{
620620
if ($this->updates === null) {
621-
$readPreference = $this->collection->getReadPreference()->getMode();
621+
$readPreference = $this->collection->getReadPreference()->getModeString();
622622

623623
$opts = [
624624
'defaultContext' => $this->defaultContext,

src/mongo/IConfigInstance.php

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -184,56 +184,56 @@ public function getSearchProviderClassName(string $storeName): ?string;
184184
/**
185185
* @param string $storeName Store (database) name
186186
* @param string|null $dataSource Database server identifier
187-
* @param int|string $readPreference Mongo read preference
187+
* @param string $readPreference Mongo read preference
188188
*
189189
* @throws ConfigException
190190
*/
191-
public function getDatabase(string $storeName, ?string $dataSource = null, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Database;
191+
public function getDatabase(string $storeName, ?string $dataSource = null, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Database;
192192

193193
/**
194-
* @param string $storeName Store (database) name
195-
* @param string $podName Pod (collection) name
196-
* @param int|string $readPreference Mongo read preference
194+
* @param string $storeName Store (database) name
195+
* @param string $podName Pod (collection) name
196+
* @param string $readPreference Mongo read preference
197197
*
198198
* @throws ConfigException
199199
*/
200-
public function getCollectionForCBD(string $storeName, string $podName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection;
200+
public function getCollectionForCBD(string $storeName, string $podName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection;
201201

202202
/**
203-
* @param string $storeName Store (database) name
204-
* @param string $viewId View spec ID
205-
* @param int|string $readPreference Mongo read preference
203+
* @param string $storeName Store (database) name
204+
* @param string $viewId View spec ID
205+
* @param string $readPreference Mongo read preference
206206
*
207207
* @throws ConfigException
208208
*/
209-
public function getCollectionForView(string $storeName, string $viewId, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection;
209+
public function getCollectionForView(string $storeName, string $viewId, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection;
210210

211211
/**
212-
* @param string $storeName Store (database) name
213-
* @param string $searchDocumentId Search document spec ID
214-
* @param int|string $readPreference Mongo read preference
212+
* @param string $storeName Store (database) name
213+
* @param string $searchDocumentId Search document spec ID
214+
* @param string $readPreference Mongo read preference
215215
*
216216
* @throws ConfigException
217217
*/
218218
public function getCollectionForSearchDocument(
219219
string $storeName,
220220
string $searchDocumentId,
221-
$readPreference = ReadPreference::RP_PRIMARY_PREFERRED
221+
string $readPreference = ReadPreference::PRIMARY_PREFERRED
222222
): Collection;
223223

224224
/**
225-
* @param string $storeName Store (database) name
226-
* @param string $tableId Table spec ID
227-
* @param int|string $readPreference Mongo read preference
225+
* @param string $storeName Store (database) name
226+
* @param string $tableId Table spec ID
227+
* @param string $readPreference Mongo read preference
228228
*
229229
* @throws ConfigException
230230
*/
231-
public function getCollectionForTable(string $storeName, string $tableId, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection;
231+
public function getCollectionForTable(string $storeName, string $tableId, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection;
232232

233233
/**
234-
* @param string $storeName Store (database) name
235-
* @param array $tables Array of table spec IDs
236-
* @param int|string $readPreference Mongo read preference
234+
* @param string $storeName Store (database) name
235+
* @param array $tables Array of table spec IDs
236+
* @param string $readPreference Mongo read preference
237237
*
238238
* @return Collection[]
239239
*
@@ -242,13 +242,13 @@ public function getCollectionForTable(string $storeName, string $tableId, $readP
242242
public function getCollectionsForTables(
243243
string $storeName,
244244
array $tables = [],
245-
$readPreference = ReadPreference::RP_PRIMARY_PREFERRED
245+
string $readPreference = ReadPreference::PRIMARY_PREFERRED
246246
): array;
247247

248248
/**
249-
* @param string $storeName Store (database) name
250-
* @param array $views Array of view spec IDs
251-
* @param int|string $readPreference Mongo read preference
249+
* @param string $storeName Store (database) name
250+
* @param array $views Array of view spec IDs
251+
* @param string $readPreference Mongo read preference
252252
*
253253
* @return Collection[]
254254
*
@@ -257,13 +257,13 @@ public function getCollectionsForTables(
257257
public function getCollectionsForViews(
258258
string $storeName,
259259
array $views = [],
260-
$readPreference = ReadPreference::RP_PRIMARY_PREFERRED
260+
string $readPreference = ReadPreference::PRIMARY_PREFERRED
261261
): array;
262262

263263
/**
264-
* @param string $storeName Store (database) name
265-
* @param array $searchSpecIds Array of search document spec IDs
266-
* @param int|string $readPreference Mongo read preference
264+
* @param string $storeName Store (database) name
265+
* @param array $searchSpecIds Array of search document spec IDs
266+
* @param string $readPreference Mongo read preference
267267
*
268268
* @return Collection[]
269269
*
@@ -272,41 +272,38 @@ public function getCollectionsForViews(
272272
public function getCollectionsForSearch(
273273
string $storeName,
274274
array $searchSpecIds = [],
275-
$readPreference = ReadPreference::RP_PRIMARY_PREFERRED
275+
string $readPreference = ReadPreference::PRIMARY_PREFERRED
276276
): array;
277277

278278
/**
279-
* @param string $storeName Store (database) name
280-
* @param int|string $readPreference Mongo read preference
279+
* @param string $storeName Store (database) name
280+
* @param string $readPreference Mongo read preference
281281
*/
282-
public function getCollectionForTTLCache(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection;
282+
public function getCollectionForTTLCache(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection;
283283

284-
/**
285-
* @param int|string $readPreference
286-
*/
287-
public function getCollectionForLocks(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection;
284+
public function getCollectionForLocks(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection;
288285

289286
/**
290-
* @param string $storeName Store (database) name
291-
* @param int|string $readPreference Mongo read preference
287+
* @param string $storeName Store (database) name
288+
* @param string $readPreference Mongo read preference
292289
*/
293290
public function getCollectionForManualRollbackAudit(
294291
string $storeName,
295-
$readPreference = ReadPreference::RP_PRIMARY_PREFERRED
292+
string $readPreference = ReadPreference::PRIMARY_PREFERRED
296293
): Collection;
297294

298295
/**
299-
* @param string $storeName Store (database) name
300-
* @param int|string $readPreference Mongo read preference
296+
* @param string $storeName Store (database) name
297+
* @param string $readPreference Mongo read preference
301298
*/
302-
public function getCollectionForJobGroups(string $storeName, $readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Collection;
299+
public function getCollectionForJobGroups(string $storeName, string $readPreference = ReadPreference::PRIMARY_PREFERRED): Collection;
303300

304301
/**
305-
* @param int|string $readPreference Mongo read preference
302+
* @param string $readPreference Mongo read preference
306303
*
307304
* @throws ConfigException
308305
*/
309-
public function getTransactionLogDatabase($readPreference = ReadPreference::RP_PRIMARY_PREFERRED): Database;
306+
public function getTransactionLogDatabase(string $readPreference = ReadPreference::PRIMARY_PREFERRED): Database;
310307

311308
/**
312309
* Return the maximum batch size for async operations.

src/mongo/ImpactedSubject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function update(): void
126126
protected function getTripod(): Driver
127127
{
128128
return new Driver($this->getPodName(), $this->getStoreName(), [
129-
'readPreference' => ReadPreference::RP_PRIMARY,
129+
'readPreference' => ReadPreference::PRIMARY,
130130
]);
131131
}
132132
}

0 commit comments

Comments
 (0)