Skip to content

Commit 4f7d08a

Browse files
authored
PHPC-2485: Remove WriteConcern and ReadPreference from execute method arginfo (#1783)
This functionality was deprecated by PHPC-2489 and can be removed for 2.0.
1 parent 13c0d4f commit 4f7d08a

14 files changed

+33
-369
lines changed

src/MongoDB/Manager.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeCommand)
280280
size_t db_len;
281281
zval* command;
282282
zval* options = NULL;
283-
bool free_options = false;
284283
zval* zreadPreference = NULL;
285284
zval* zsession = NULL;
286285
uint32_t server_id = 0;
@@ -294,21 +293,19 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeCommand)
294293

295294
intern = Z_MANAGER_OBJ_P(getThis());
296295

297-
options = php_phongo_prep_legacy_option(options, "readPreference", &free_options);
298-
299296
if (!phongo_parse_session(options, intern->client, NULL, &zsession)) {
300297
/* Exception should already have been thrown */
301-
goto cleanup;
298+
return;
302299
}
303300

304301
if (!phongo_parse_read_preference(options, &zreadPreference)) {
305302
/* Exception should already have been thrown */
306-
goto cleanup;
303+
return;
307304
}
308305

309306
if (!php_phongo_manager_select_server(false, false, zreadPreference, zsession, intern->client, &server_id)) {
310307
/* Exception should already have been thrown */
311-
goto cleanup;
308+
return;
312309
}
313310

314311
/* If the Manager was created in a different process, reset the client so
@@ -317,11 +314,6 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeCommand)
317314
PHONGO_RESET_CLIENT_IF_PID_DIFFERS(intern, intern);
318315

319316
phongo_execute_command(getThis(), PHONGO_COMMAND_RAW, db, command, options, server_id, return_value);
320-
321-
cleanup:
322-
if (free_options) {
323-
php_phongo_prep_legacy_option_free(options);
324-
}
325317
}
326318

327319
/* Execute a ReadCommand */
@@ -452,7 +444,6 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeQuery)
452444
size_t namespace_len;
453445
zval* query;
454446
zval* options = NULL;
455-
bool free_options = false;
456447
zval* zreadPreference = NULL;
457448
uint32_t server_id = 0;
458449
zval* zsession = NULL;
@@ -466,21 +457,19 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeQuery)
466457

467458
intern = Z_MANAGER_OBJ_P(getThis());
468459

469-
options = php_phongo_prep_legacy_option(options, "readPreference", &free_options);
470-
471460
if (!phongo_parse_session(options, intern->client, NULL, &zsession)) {
472461
/* Exception should already have been thrown */
473-
goto cleanup;
462+
return;
474463
}
475464

476465
if (!phongo_parse_read_preference(options, &zreadPreference)) {
477466
/* Exception should already have been thrown */
478-
goto cleanup;
467+
return;
479468
}
480469

481470
if (!php_phongo_manager_select_server(false, true, zreadPreference, zsession, intern->client, &server_id)) {
482471
/* Exception should already have been thrown */
483-
goto cleanup;
472+
return;
484473
}
485474

486475
/* If the Manager was created in a different process, reset the client so
@@ -489,11 +478,6 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeQuery)
489478
PHONGO_RESET_CLIENT_IF_PID_DIFFERS(intern, intern);
490479

491480
phongo_execute_query(getThis(), namespace, query, options, server_id, return_value);
492-
493-
cleanup:
494-
if (free_options) {
495-
php_phongo_prep_legacy_option_free(options);
496-
}
497481
}
498482

499483
/* Executes a BulkWrite (i.e. any number of insert, update, and delete ops) */
@@ -504,10 +488,9 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeBulkWrite)
504488
size_t namespace_len;
505489
zval* zbulk;
506490
php_phongo_bulkwrite_t* bulk;
507-
zval* options = NULL;
508-
bool free_options = false;
509-
uint32_t server_id = 0;
510-
zval* zsession = NULL;
491+
zval* options = NULL;
492+
uint32_t server_id = 0;
493+
zval* zsession = NULL;
511494

512495
PHONGO_PARSE_PARAMETERS_START(2, 3)
513496
Z_PARAM_STRING_OR_NULL(namespace, namespace_len)
@@ -519,28 +502,21 @@ static PHP_METHOD(MongoDB_Driver_Manager, executeBulkWrite)
519502
intern = Z_MANAGER_OBJ_P(getThis());
520503
bulk = Z_BULKWRITE_OBJ_P(zbulk);
521504

522-
options = php_phongo_prep_legacy_option(options, "writeConcern", &free_options);
523-
524505
if (!phongo_parse_session(options, intern->client, NULL, &zsession)) {
525506
/* Exception should already have been thrown */
526507
return;
527508
}
528509

529510
if (!php_phongo_manager_select_server(true, false, NULL, zsession, intern->client, &server_id)) {
530511
/* Exception should already have been thrown */
531-
goto cleanup;
512+
return;
532513
}
533514

534515
/* If the Server was created in a different process, reset the client so
535516
* that its session pool is cleared. */
536517
PHONGO_RESET_CLIENT_IF_PID_DIFFERS(intern, intern);
537518

538519
phongo_execute_bulk_write(getThis(), namespace, bulk, options, server_id, return_value);
539-
540-
cleanup:
541-
if (free_options) {
542-
php_phongo_prep_legacy_option_free(options);
543-
}
544520
}
545521

546522
/* Returns the autoEncryption.encryptedFieldsMap driver option */

src/MongoDB/Manager.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ final public function addSubscriber(Monitoring\Subscriber $subscriber): void {}
1616

1717
final public function createClientEncryption(array $options): ClientEncryption {}
1818

19-
final public function executeBulkWrite(string $namespace, BulkWrite $bulk, array|WriteConcern|null $options = null): WriteResult {}
19+
final public function executeBulkWrite(string $namespace, BulkWrite $bulk, array|null $options = null): WriteResult {}
2020

21-
final public function executeCommand(string $db, Command $command, array|ReadPreference|null $options = null): CursorInterface {}
21+
final public function executeCommand(string $db, Command $command, array|null $options = null): CursorInterface {}
2222

23-
final public function executeQuery(string $namespace, Query $query, array|ReadPreference|null $options = null): CursorInterface {}
23+
final public function executeQuery(string $namespace, Query $query, array|null $options = null): CursorInterface {}
2424

2525
final public function executeReadCommand(string $db, Command $command, ?array $options = null): CursorInterface {}
2626

src/MongoDB/Manager_arginfo.h

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Server.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ static PHP_METHOD(MongoDB_Driver_Server, executeCommand)
4242
char* db;
4343
size_t db_len;
4444
zval* command;
45-
zval* options = NULL;
46-
bool free_options = false;
45+
zval* options = NULL;
4746

4847
intern = Z_SERVER_OBJ_P(getThis());
4948

@@ -54,18 +53,12 @@ static PHP_METHOD(MongoDB_Driver_Server, executeCommand)
5453
Z_PARAM_ZVAL_OR_NULL(options)
5554
PHONGO_PARSE_PARAMETERS_END();
5655

57-
options = php_phongo_prep_legacy_option(options, "readPreference", &free_options);
58-
5956
/* If the Server was created in a different process, reset the client so
6057
* that cursors created by this process can be differentiated and its
6158
* session pool is cleared. */
6259
PHONGO_RESET_CLIENT_IF_PID_DIFFERS(intern, Z_MANAGER_OBJ_P(&intern->manager));
6360

6461
phongo_execute_command(&intern->manager, PHONGO_COMMAND_RAW, db, command, options, intern->server_id, return_value);
65-
66-
if (free_options) {
67-
php_phongo_prep_legacy_option_free(options);
68-
}
6962
}
7063

7164
/* Executes a ReadCommand on this Server */
@@ -153,8 +146,7 @@ static PHP_METHOD(MongoDB_Driver_Server, executeQuery)
153146
char* namespace;
154147
size_t namespace_len;
155148
zval* query;
156-
zval* options = NULL;
157-
bool free_options = false;
149+
zval* options = NULL;
158150

159151
intern = Z_SERVER_OBJ_P(getThis());
160152

@@ -165,18 +157,12 @@ static PHP_METHOD(MongoDB_Driver_Server, executeQuery)
165157
Z_PARAM_ZVAL_OR_NULL(options)
166158
PHONGO_PARSE_PARAMETERS_END();
167159

168-
options = php_phongo_prep_legacy_option(options, "readPreference", &free_options);
169-
170160
/* If the Server was created in a different process, reset the client so
171161
* that cursors created by this process can be differentiated and its
172162
* session pool is cleared. */
173163
PHONGO_RESET_CLIENT_IF_PID_DIFFERS(intern, Z_MANAGER_OBJ_P(&intern->manager));
174164

175165
phongo_execute_query(&intern->manager, namespace, query, options, intern->server_id, return_value);
176-
177-
if (free_options) {
178-
php_phongo_prep_legacy_option_free(options);
179-
}
180166
}
181167

182168
/* Executes a BulkWrite (i.e. any number of insert, update, and delete ops) on
@@ -188,8 +174,7 @@ static PHP_METHOD(MongoDB_Driver_Server, executeBulkWrite)
188174
size_t namespace_len;
189175
zval* zbulk;
190176
php_phongo_bulkwrite_t* bulk;
191-
zval* options = NULL;
192-
bool free_options = false;
177+
zval* options = NULL;
193178

194179
intern = Z_SERVER_OBJ_P(getThis());
195180

@@ -202,17 +187,11 @@ static PHP_METHOD(MongoDB_Driver_Server, executeBulkWrite)
202187

203188
bulk = Z_BULKWRITE_OBJ_P(zbulk);
204189

205-
options = php_phongo_prep_legacy_option(options, "writeConcern", &free_options);
206-
207190
/* If the Server was created in a different process, reset the client so
208191
* that its session pool is cleared. */
209192
PHONGO_RESET_CLIENT_IF_PID_DIFFERS(intern, Z_MANAGER_OBJ_P(&intern->manager));
210193

211194
phongo_execute_bulk_write(&intern->manager, namespace, bulk, options, intern->server_id, return_value);
212-
213-
if (free_options) {
214-
php_phongo_prep_legacy_option_free(options);
215-
}
216195
}
217196

218197
/* Returns the hostname for this Server */

src/MongoDB/Server.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ final class Server
7272

7373
final private function __construct() {}
7474

75-
final public function executeBulkWrite(string $namespace, BulkWrite $bulkWrite, array|WriteConcern|null $options = null): WriteResult {}
75+
final public function executeBulkWrite(string $namespace, BulkWrite $bulkWrite, array|null $options = null): WriteResult {}
7676

77-
final public function executeCommand(string $db, Command $command, array|ReadPreference|null $options = null): CursorInterface {}
77+
final public function executeCommand(string $db, Command $command, array|null $options = null): CursorInterface {}
7878

79-
final public function executeQuery(string $namespace, Query $query, array|ReadPreference|null $options = null): CursorInterface {}
79+
final public function executeQuery(string $namespace, Query $query, array|null $options = null): CursorInterface {}
8080

8181
final public function executeReadCommand(string $db, Command $command, ?array $options = null): CursorInterface {}
8282

src/MongoDB/Server_arginfo.h

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/phongo_util.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,6 @@ const char* php_phongo_bson_type_to_string(bson_type_t type)
7373
}
7474
}
7575

76-
/* If options is not an array, insert it as a field in a newly allocated array.
77-
* This may be used to convert legacy options (e.g. ReadPreference option for
78-
* an executeQuery method) into an options array.
79-
*
80-
* A pointer to the array zval will always be returned. If allocated is set to
81-
* true, php_phongo_prep_legacy_option_free() should be used to free the array
82-
* zval later. */
83-
zval* php_phongo_prep_legacy_option(zval* options, const char* key, bool* allocated)
84-
{
85-
*allocated = false;
86-
87-
if (options && Z_TYPE_P(options) != IS_ARRAY) {
88-
zval* new_options = ecalloc(1, sizeof(zval));
89-
90-
array_init_size(new_options, 1);
91-
add_assoc_zval(new_options, key, options);
92-
Z_ADDREF_P(options);
93-
*allocated = true;
94-
95-
php_error_docref(NULL, E_DEPRECATED, "Passing the \"%s\" option directly is deprecated and will be removed in ext-mongodb 2.0", key);
96-
97-
return new_options;
98-
}
99-
100-
return options;
101-
}
102-
103-
void php_phongo_prep_legacy_option_free(zval* options)
104-
{
105-
zval_ptr_dtor(options);
106-
efree(options);
107-
}
108-
10976
bool php_phongo_parse_int64(int64_t* retval, const char* data, size_t data_len)
11077
{
11178
int64_t value;

src/phongo_util.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
const char* php_phongo_bson_type_to_string(bson_type_t type);
2323

24-
zval* php_phongo_prep_legacy_option(zval* options, const char* key, bool* allocated);
25-
void php_phongo_prep_legacy_option_free(zval* options);
26-
2724
bool php_phongo_parse_int64(int64_t* retval, const char* data, size_t data_len);
2825

2926
bool phongo_split_namespace(const char* namespace, char** dbname, char** cname);

0 commit comments

Comments
 (0)