Skip to content

Commit 94c7487

Browse files
committed
Merged pull request #816
2 parents c75f89b + 5416775 commit 94c7487

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

src/MongoDB/Query.c

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,20 @@ static bool php_phongo_query_opts_append_document(bson_t* opts, const char* opts
8282
return true;
8383
} /* }}} */
8484

85-
#define PHONGO_QUERY_OPT_BOOL(opt, zarr, key) \
86-
if ((zarr) && php_array_existsc((zarr), (key))) { \
87-
if (!BSON_APPEND_BOOL(intern->opts, (opt), php_array_fetchc_bool((zarr), (key)))) { \
88-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
89-
return false; \
90-
} \
85+
#define PHONGO_QUERY_OPT_BOOL_EX(opt, zarr, key, deprecated) \
86+
if ((zarr) && php_array_existsc((zarr), (key))) { \
87+
if ((deprecated)) { \
88+
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The \"%s\" option is deprecated and will be removed in a future release", key); \
89+
} \
90+
if (!BSON_APPEND_BOOL(intern->opts, (opt), php_array_fetchc_bool((zarr), (key)))) { \
91+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
92+
return false; \
93+
} \
9194
}
9295

96+
#define PHONGO_QUERY_OPT_BOOL(opt, zarr, key) PHONGO_QUERY_OPT_BOOL_EX((opt), (zarr), (key), 0)
97+
#define PHONGO_QUERY_OPT_BOOL_DEPRECATED(opt, zarr, key) PHONGO_QUERY_OPT_BOOL_EX((opt), (zarr), (key), 1)
98+
9399
#define PHONGO_QUERY_OPT_DOCUMENT(opt, zarr, key) \
94100
if ((zarr) && php_array_existsc((zarr), (key))) { \
95101
if (!php_phongo_query_opts_append_document(intern->opts, (opt), (zarr), (key) TSRMLS_CC)) { \
@@ -98,16 +104,22 @@ static bool php_phongo_query_opts_append_document(bson_t* opts, const char* opts
98104
}
99105

100106
/* Note: handling of integer options will depend on SIZEOF_ZEND_LONG and we
101-
* are not converting strings to 64-bit integers for 32-bit platforms. */
102-
103-
#define PHONGO_QUERY_OPT_INT64(opt, zarr, key) \
104-
if ((zarr) && php_array_existsc((zarr), (key))) { \
105-
if (!BSON_APPEND_INT64(intern->opts, (opt), php_array_fetchc_long((zarr), (key)))) { \
106-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
107-
return false; \
108-
} \
107+
* are not converting strings to 64-bit integers for 32-bit platforms. */
108+
109+
#define PHONGO_QUERY_OPT_INT64_EX(opt, zarr, key, deprecated) \
110+
if ((zarr) && php_array_existsc((zarr), (key))) { \
111+
if ((deprecated)) { \
112+
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The \"%s\" option is deprecated and will be removed in a future release", key); \
113+
} \
114+
if (!BSON_APPEND_INT64(intern->opts, (opt), php_array_fetchc_long((zarr), (key)))) { \
115+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
116+
return false; \
117+
} \
109118
}
110119

120+
#define PHONGO_QUERY_OPT_INT64(opt, zarr, key) PHONGO_QUERY_OPT_INT64_EX((opt), (zarr), (key), 0)
121+
#define PHONGO_QUERY_OPT_INT64_DEPRECATED(opt, zarr, key) PHONGO_QUERY_OPT_INT64_EX((opt), (zarr), (key), 1)
122+
111123
#define PHONGO_QUERY_OPT_STRING(opt, zarr, key) \
112124
if ((zarr) && php_array_existsc((zarr), (key))) { \
113125
if (!php_phongo_query_opts_append_string(intern->opts, (opt), (zarr), (key) TSRMLS_CC)) { \
@@ -277,8 +289,8 @@ static bool php_phongo_query_init(php_phongo_query_t* intern, zval* filter, zval
277289
PHONGO_QUERY_OPT_BOOL("exhaust", options, "exhaust");
278290
PHONGO_QUERY_OPT_DOCUMENT("max", options, "max")
279291
else PHONGO_QUERY_OPT_DOCUMENT("max", modifiers, "$max");
280-
PHONGO_QUERY_OPT_INT64("maxScan", options, "maxScan")
281-
else PHONGO_QUERY_OPT_INT64("maxScan", modifiers, "$maxScan");
292+
PHONGO_QUERY_OPT_INT64_DEPRECATED("maxScan", options, "maxScan")
293+
else PHONGO_QUERY_OPT_INT64_DEPRECATED("maxScan", modifiers, "$maxScan");
282294
PHONGO_QUERY_OPT_INT64("maxTimeMS", options, "maxTimeMS")
283295
else PHONGO_QUERY_OPT_INT64("maxTimeMS", modifiers, "$maxTimeMS");
284296
PHONGO_QUERY_OPT_DOCUMENT("min", options, "min")
@@ -293,8 +305,8 @@ static bool php_phongo_query_init(php_phongo_query_t* intern, zval* filter, zval
293305
PHONGO_QUERY_OPT_INT64("skip", options, "skip");
294306
PHONGO_QUERY_OPT_DOCUMENT("sort", options, "sort")
295307
else PHONGO_QUERY_OPT_DOCUMENT("sort", modifiers, "$orderby");
296-
PHONGO_QUERY_OPT_BOOL("snapshot", options, "snapshot")
297-
else PHONGO_QUERY_OPT_BOOL("snapshot", modifiers, "$snapshot");
308+
PHONGO_QUERY_OPT_BOOL_DEPRECATED("snapshot", options, "snapshot")
309+
else PHONGO_QUERY_OPT_BOOL_DEPRECATED("snapshot", modifiers, "$snapshot");
298310
PHONGO_QUERY_OPT_BOOL("tailable", options, "tailable");
299311

300312
/* The "$explain" modifier should be converted to an "explain" option, which

tests/query/query-ctor-002.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ var_dump(new MongoDB\Driver\Query(
4949
===DONE===
5050
<?php exit(0); ?>
5151
--EXPECTF--
52+
Deprecated: MongoDB\Driver\Query::__construct(): The "maxScan" option is deprecated and will be removed in a future release in %s on line %d
53+
54+
Deprecated: MongoDB\Driver\Query::__construct(): The "snapshot" option is deprecated and will be removed in a future release in %s on line %d
5255
object(MongoDB\Driver\Query)#%d (%d) {
5356
["filter"]=>
5457
object(stdClass)#%d (%d) {

tests/query/query-ctor-003.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ var_dump(new MongoDB\Driver\Query(
3939
===DONE===
4040
<?php exit(0); ?>
4141
--EXPECTF--
42+
Deprecated: MongoDB\Driver\Query::__construct(): The "$maxScan" option is deprecated and will be removed in a future release in %s on line %d
43+
44+
Deprecated: MongoDB\Driver\Query::__construct(): The "$snapshot" option is deprecated and will be removed in a future release in %s on line %d
4245
object(MongoDB\Driver\Query)#%d (%d) {
4346
["filter"]=>
4447
object(stdClass)#%d (%d) {

tests/query/query-ctor-004.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ var_dump(new MongoDB\Driver\Query(
4949
===DONE===
5050
<?php exit(0); ?>
5151
--EXPECTF--
52+
Deprecated: MongoDB\Driver\Query::__construct(): The "maxScan" option is deprecated and will be removed in a future release in %s on line %d
53+
54+
Deprecated: MongoDB\Driver\Query::__construct(): The "snapshot" option is deprecated and will be removed in a future release in %s on line %d
5255
object(MongoDB\Driver\Query)#%d (%d) {
5356
["filter"]=>
5457
object(stdClass)#%d (%d) {

0 commit comments

Comments
 (0)