Skip to content

Commit a5e7454

Browse files
committed
PHPLIB-477: Deprecate CodeWScope for use within the mapReduce command
1 parent 419ef62 commit a5e7454

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/includes/apiargs-MongoDBCollection-method-mapReduce-option.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ name: finalize
1313
type: :php:`MongoDB\\BSON\\Javascript <class.mongodb-bson-javascript>`
1414
description: |
1515
Follows the reduce method and modifies the output.
16+
17+
.. note::
18+
19+
Passing a Javascript instance with a scope is deprecated. Put all scope
20+
variables in the ``scope`` option of the MapReduce operation.
1621
interface: phpmethod
1722
operation: ~
1823
optional: true

docs/includes/apiargs-MongoDBCollection-method-mapReduce-param.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ type: :php:`MongoDB\\BSON\\Javascript <mongodb-bson-javascript>`
44
description: |
55
A JavaScript function that associates or "maps" a value with a key and emits
66
the key and value pair.
7+
8+
.. note::
9+
10+
Passing a Javascript instance with a scope is deprecated. Put all scope
11+
variables in the ``scope`` option of the MapReduce operation.
712
interface: phpmethod
813
operation: ~
914
optional: false
@@ -14,6 +19,11 @@ type: :php:`MongoDB\\BSON\\Javascript <class.mongodb-bson-javascript>`
1419
description: |
1520
A JavaScript function that "reduces" to a single object all the values
1621
associated with a particular key.
22+
23+
.. note::
24+
25+
Passing a Javascript instance with a scope is deprecated. Put all scope
26+
variables in the ``scope`` option of the MapReduce operation.
1727
interface: phpmethod
1828
operation: ~
1929
optional: false

src/Operation/MapReduce.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
use function MongoDB\create_field_path_type_map;
4141
use function MongoDB\is_mapreduce_output_inline;
4242
use function MongoDB\server_supports_feature;
43+
use function trigger_error;
44+
use const E_USER_DEPRECATED;
4345

4446
/**
4547
* Operation for the mapReduce command.
@@ -88,9 +90,15 @@ class MapReduce implements Executable
8890
* * map (MongoDB\BSON\Javascript): A JavaScript function that associates
8991
* or "maps" a value with a key and emits the key and value pair.
9092
*
93+
* Passing a Javascript instance with a scope is deprecated. Put all
94+
* scope variables in the "scope" option of the MapReduce operation.
95+
*
9196
* * reduce (MongoDB\BSON\Javascript): A JavaScript function that "reduces"
9297
* to a single object all the values associated with a particular key.
9398
*
99+
* Passing a Javascript instance with a scope is deprecated. Put all
100+
* scope variables in the "scope" option of the MapReduce operation.
101+
*
94102
* * out (string|document): Specifies where to output the result of the
95103
* map-reduce operation. You can either output to a collection or return
96104
* the result inline. On a primary member of a replica set you can output
@@ -114,6 +122,9 @@ class MapReduce implements Executable
114122
* * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method
115123
* and modifies the output.
116124
*
125+
* Passing a Javascript instance with a scope is deprecated. Put all
126+
* scope variables in the "scope" option of the MapReduce operation.
127+
*
117128
* * jsMode (boolean): Specifies whether to convert intermediate data into
118129
* BSON format between the execution of the map and reduce functions.
119130
*
@@ -242,6 +253,19 @@ public function __construct($databaseName, $collectionName, JavascriptInterface
242253
unset($options['writeConcern']);
243254
}
244255

256+
// Handle deprecation of CodeWScope
257+
if ($map->getScope() !== null) {
258+
@trigger_error('Use of Javascript with scope in "$map" argument for MapReduce is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.', E_USER_DEPRECATED);
259+
}
260+
261+
if ($reduce->getScope() !== null) {
262+
@trigger_error('Use of Javascript with scope in "$reduce" argument for MapReduce is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.', E_USER_DEPRECATED);
263+
}
264+
265+
if (isset($options['finalize']) && $options['finalize']->getScope() !== null) {
266+
@trigger_error('Use of Javascript with scope in "finalize" option for MapReduce is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.', E_USER_DEPRECATED);
267+
}
268+
245269
$this->databaseName = (string) $databaseName;
246270
$this->collectionName = (string) $collectionName;
247271
$this->map = $map;

0 commit comments

Comments
 (0)