PHPLIB-477: Deprecate CodeWScope for use within the mapReduce command

parent 419ef627
...@@ -13,6 +13,11 @@ name: finalize ...@@ -13,6 +13,11 @@ name: finalize
type: :php:`MongoDB\\BSON\\Javascript <class.mongodb-bson-javascript>` type: :php:`MongoDB\\BSON\\Javascript <class.mongodb-bson-javascript>`
description: | description: |
Follows the reduce method and modifies the output. Follows the reduce method and modifies the output.
.. note::
Passing a Javascript instance with a scope is deprecated. Put all scope
variables in the ``scope`` option of the MapReduce operation.
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
......
...@@ -4,6 +4,11 @@ type: :php:`MongoDB\\BSON\\Javascript <mongodb-bson-javascript>` ...@@ -4,6 +4,11 @@ type: :php:`MongoDB\\BSON\\Javascript <mongodb-bson-javascript>`
description: | description: |
A JavaScript function that associates or "maps" a value with a key and emits A JavaScript function that associates or "maps" a value with a key and emits
the key and value pair. the key and value pair.
.. note::
Passing a Javascript instance with a scope is deprecated. Put all scope
variables in the ``scope`` option of the MapReduce operation.
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: false optional: false
...@@ -14,6 +19,11 @@ type: :php:`MongoDB\\BSON\\Javascript <class.mongodb-bson-javascript>` ...@@ -14,6 +19,11 @@ type: :php:`MongoDB\\BSON\\Javascript <class.mongodb-bson-javascript>`
description: | description: |
A JavaScript function that "reduces" to a single object all the values A JavaScript function that "reduces" to a single object all the values
associated with a particular key. associated with a particular key.
.. note::
Passing a Javascript instance with a scope is deprecated. Put all scope
variables in the ``scope`` option of the MapReduce operation.
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: false optional: false
......
...@@ -40,6 +40,8 @@ use function is_string; ...@@ -40,6 +40,8 @@ use function is_string;
use function MongoDB\create_field_path_type_map; use function MongoDB\create_field_path_type_map;
use function MongoDB\is_mapreduce_output_inline; use function MongoDB\is_mapreduce_output_inline;
use function MongoDB\server_supports_feature; use function MongoDB\server_supports_feature;
use function trigger_error;
use const E_USER_DEPRECATED;
/** /**
* Operation for the mapReduce command. * Operation for the mapReduce command.
...@@ -88,9 +90,15 @@ class MapReduce implements Executable ...@@ -88,9 +90,15 @@ class MapReduce implements Executable
* * map (MongoDB\BSON\Javascript): A JavaScript function that associates * * map (MongoDB\BSON\Javascript): A JavaScript function that associates
* or "maps" a value with a key and emits the key and value pair. * or "maps" a value with a key and emits the key and value pair.
* *
* Passing a Javascript instance with a scope is deprecated. Put all
* scope variables in the "scope" option of the MapReduce operation.
*
* * reduce (MongoDB\BSON\Javascript): A JavaScript function that "reduces" * * reduce (MongoDB\BSON\Javascript): A JavaScript function that "reduces"
* to a single object all the values associated with a particular key. * to a single object all the values associated with a particular key.
* *
* Passing a Javascript instance with a scope is deprecated. Put all
* scope variables in the "scope" option of the MapReduce operation.
*
* * out (string|document): Specifies where to output the result of the * * out (string|document): Specifies where to output the result of the
* map-reduce operation. You can either output to a collection or return * map-reduce operation. You can either output to a collection or return
* the result inline. On a primary member of a replica set you can output * the result inline. On a primary member of a replica set you can output
...@@ -114,6 +122,9 @@ class MapReduce implements Executable ...@@ -114,6 +122,9 @@ class MapReduce implements Executable
* * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method * * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method
* and modifies the output. * and modifies the output.
* *
* Passing a Javascript instance with a scope is deprecated. Put all
* scope variables in the "scope" option of the MapReduce operation.
*
* * jsMode (boolean): Specifies whether to convert intermediate data into * * jsMode (boolean): Specifies whether to convert intermediate data into
* BSON format between the execution of the map and reduce functions. * BSON format between the execution of the map and reduce functions.
* *
...@@ -242,6 +253,19 @@ class MapReduce implements Executable ...@@ -242,6 +253,19 @@ class MapReduce implements Executable
unset($options['writeConcern']); unset($options['writeConcern']);
} }
// Handle deprecation of CodeWScope
if ($map->getScope() !== null) {
@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);
}
if ($reduce->getScope() !== null) {
@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);
}
if (isset($options['finalize']) && $options['finalize']->getScope() !== null) {
@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);
}
$this->databaseName = (string) $databaseName; $this->databaseName = (string) $databaseName;
$this->collectionName = (string) $collectionName; $this->collectionName = (string) $collectionName;
$this->map = $map; $this->map = $map;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment