Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ name: finalize
type: :php:`MongoDB\\BSON\\Javascript <class.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ type: :php:`MongoDB\\BSON\\Javascript <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
Expand All @@ -14,6 +19,11 @@ type: :php:`MongoDB\\BSON\\Javascript <class.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
Expand Down
24 changes: 24 additions & 0 deletions src/Operation/MapReduce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down