Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 419ccbe

Browse files
committed
PHP-1510: Extra is_gle_op() calls should be silent
The extra is_gle_op() call was causing duplicate "safe" deprecation notices and MongoLog output in some tests. Existing code paths for write commands and legacy ops already include necessary output, so allow is_gle_op() to be silent when invoked for the purpose of routing unacknowledged writes to legacy opcodes.
1 parent ca02282 commit 419ccbe

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

collection.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ZEND_EXTERN_MODULE_GLOBALS(mongo)
4848

4949
zend_class_entry *mongo_ce_Collection = NULL;
5050

51-
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options TSRMLS_DC);
51+
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options, int silent TSRMLS_DC);
5252
static void do_gle_op(mongo_con_manager *manager, mongo_connection *connection, zval *cursor_z, mongo_buffer *buf, zval *return_value TSRMLS_DC);
5353
static zval* append_getlasterror(zval *coll, mongo_buffer *buf, zval *options, mongo_connection *connection TSRMLS_DC);
5454
static char *to_index_string(zval *zkeys, int *key_len TSRMLS_DC);
@@ -609,7 +609,7 @@ static int send_message(zval *this_ptr, mongo_connection *connection, mongo_buff
609609
return 0;
610610
}
611611

612-
if (is_gle_op(this_ptr, options, &link->servers->options TSRMLS_CC)) {
612+
if (is_gle_op(this_ptr, options, &link->servers->options, NOISY TSRMLS_CC)) {
613613
zval *cursor = append_getlasterror(this_ptr, buf, options, connection TSRMLS_CC);
614614
if (cursor) {
615615
do_gle_op(link->manager, connection, cursor, buf, return_value TSRMLS_CC);
@@ -632,7 +632,7 @@ static int send_message(zval *this_ptr, mongo_connection *connection, mongo_buff
632632
* on whether a write concern ("w" or "safe") or fsync/journal options are
633633
* specified.
634634
*/
635-
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options TSRMLS_DC)
635+
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options, int silent TSRMLS_DC)
636636
{
637637
int gle_op = 0, default_fsync, default_journal, coll_w = 0;
638638
zval *z_coll_w;
@@ -674,10 +674,14 @@ static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_opt
674674
}
675675
break;
676676
default:
677-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'w' option either needs to be a integer or string");
677+
if (silent == NOISY) {
678+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'w' option either needs to be a integer or string");
679+
}
678680
}
679681
} else if (zend_hash_find(HASH_P(options), "safe", strlen("safe") + 1, (void**) &gle_pp) == SUCCESS) {
680-
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The 'safe' option is deprecated, please use 'w' instead");
682+
if (silent == NOISY) {
683+
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The 'safe' option is deprecated, please use 'w' instead");
684+
}
681685

682686
switch (Z_TYPE_PP(gle_pp)) {
683687
case IS_STRING:
@@ -691,7 +695,9 @@ static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_opt
691695
}
692696
break;
693697
default:
694-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'safe' option either needs to be a boolean or a string");
698+
if (silent == NOISY) {
699+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'safe' option either needs to be a boolean or a string");
700+
}
695701
}
696702
} else if (coll_w >= 1) {
697703
gle_op = 1;
@@ -722,7 +728,9 @@ static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_opt
722728
gle_op = (coll_w >= 1 || default_fsync == 1 || default_journal == 1);
723729
}
724730

725-
mongo_manager_log(MonGlo(manager), MLOG_IO, MLOG_FINE, "is_gle_op: %s", gle_op ? "yes" : "no");
731+
if (silent == NOISY) {
732+
mongo_manager_log(MonGlo(manager), MLOG_IO, MLOG_FINE, "is_gle_op: %s", gle_op ? "yes" : "no");
733+
}
726734
return gle_op;
727735
}
728736

@@ -1135,7 +1143,7 @@ static void php_mongo_collection_insert(zval *z_collection, zval *document, zval
11351143
RETURN_FALSE;
11361144
}
11371145

1138-
is_acknowledged = is_gle_op(z_collection, z_write_options, &link->servers->options TSRMLS_CC);
1146+
is_acknowledged = is_gle_op(z_collection, z_write_options, &link->servers->options, QUIET TSRMLS_CC);
11391147
supports_command = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_WRITE_API);
11401148
supports_opcode = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_RELEASE_2_4_AND_BEFORE);
11411149

@@ -1518,7 +1526,7 @@ static void php_mongocollection_update(zval *this_ptr, mongo_collection *c, zval
15181526
RETURN_FALSE;
15191527
}
15201528

1521-
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options TSRMLS_CC);
1529+
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options, QUIET TSRMLS_CC);
15221530
supports_command = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_WRITE_API);
15231531
supports_opcode = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_RELEASE_2_4_AND_BEFORE);
15241532

@@ -1637,7 +1645,7 @@ static void php_mongocollection_remove(zval *this_ptr, mongo_collection *c, zval
16371645
RETURN_FALSE;
16381646
}
16391647

1640-
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options TSRMLS_CC);
1648+
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options, QUIET TSRMLS_CC);
16411649
supports_command = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_WRITE_API);
16421650
supports_opcode = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_RELEASE_2_4_AND_BEFORE);
16431651

0 commit comments

Comments
 (0)