From a5e7454a3ac3414fc2eeed048f2acad7922dc717 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 29 Oct 2019 16:18:59 +0100 Subject: [PATCH] PHPLIB-477: Deprecate CodeWScope for use within the mapReduce command --- ...oDBCollection-method-mapReduce-option.yaml | 5 ++++ ...goDBCollection-method-mapReduce-param.yaml | 10 ++++++++ src/Operation/MapReduce.php | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/docs/includes/apiargs-MongoDBCollection-method-mapReduce-option.yaml b/docs/includes/apiargs-MongoDBCollection-method-mapReduce-option.yaml index 8d02ffb7e..33ef3892c 100644 --- a/docs/includes/apiargs-MongoDBCollection-method-mapReduce-option.yaml +++ b/docs/includes/apiargs-MongoDBCollection-method-mapReduce-option.yaml @@ -13,6 +13,11 @@ name: finalize type: :php:`MongoDB\\BSON\\Javascript ` description: | 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 operation: ~ optional: true diff --git a/docs/includes/apiargs-MongoDBCollection-method-mapReduce-param.yaml b/docs/includes/apiargs-MongoDBCollection-method-mapReduce-param.yaml index 401d49edc..e8254f3e2 100644 --- a/docs/includes/apiargs-MongoDBCollection-method-mapReduce-param.yaml +++ b/docs/includes/apiargs-MongoDBCollection-method-mapReduce-param.yaml @@ -4,6 +4,11 @@ type: :php:`MongoDB\\BSON\\Javascript ` description: | A JavaScript function that associates or "maps" a value with a key and emits 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 operation: ~ optional: false @@ -14,6 +19,11 @@ type: :php:`MongoDB\\BSON\\Javascript ` description: | A JavaScript function that "reduces" to a single object all the values 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 operation: ~ optional: false diff --git a/src/Operation/MapReduce.php b/src/Operation/MapReduce.php index 22c357dc6..9b6d1df60 100644 --- a/src/Operation/MapReduce.php +++ b/src/Operation/MapReduce.php @@ -40,6 +40,8 @@ use function MongoDB\create_field_path_type_map; use function MongoDB\is_mapreduce_output_inline; use function MongoDB\server_supports_feature; +use function trigger_error; +use const E_USER_DEPRECATED; /** * Operation for the mapReduce command. @@ -88,9 +90,15 @@ class MapReduce implements Executable * * map (MongoDB\BSON\Javascript): A JavaScript function that associates * 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" * 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 * 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 @@ -114,6 +122,9 @@ class MapReduce implements Executable * * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method * 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 * BSON format between the execution of the map and reduce functions. * @@ -242,6 +253,19 @@ public function __construct($databaseName, $collectionName, JavascriptInterface 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->collectionName = (string) $collectionName; $this->map = $map;