Skip to content

PHPC-1195: BulkWrite::update() should append arrayFilters as array #842

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 4 commits into from
May 25, 2018

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented May 24, 2018

https://jira.mongodb.org/browse/PHPC-1195

Note: this is waiting on CDRIVER-2661. Once that is merged, this PR can be updated to bump the libmongoc submodule to 1.10-dev (assuming the issue is also backported to the r1.10 branch).

@jmikola jmikola requested a review from derickr May 24, 2018 19:50
@jmikola jmikola changed the title PHPC-1195: BulkWrite::update() should append arrayFilters as array [WAIT] PHPC-1195: BulkWrite::update() should append arrayFilters as array May 24, 2018
Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment, but haven't LGTM'ed it as it says [WAIT], so I expect more changes?

@@ -73,6 +73,67 @@ static inline bool php_phongo_bulkwrite_update_has_operators(bson_t* bupdate) /*
return false;
} /* }}} */

static inline bool php_phongo_bulkwrite_bson_array_has_valid_keys(bson_t* array) /* {{{ */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain with a comment what a "valid key" is?

These tests were only using Mongo Orchestration to ensure a 3.6 server. skip_if_server_version() can be used instead.
@jmikola jmikola changed the title [WAIT] PHPC-1195: BulkWrite::update() should append arrayFilters as array PHPC-1195: BulkWrite::update() should append arrayFilters as array May 25, 2018
Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs the code fix, and I had some questions.

}

if (!php_phongo_bulkwrite_bson_array_has_valid_keys(&b)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "\"%s\" option has invalid keys for a BSON array", zarr_key, zend_get_type_by_const(Z_TYPE_P(value)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has an extra zend_get_type_by_const — Travis says so too: https://travis-ci.org/mongodb/mongo-php-driver/jobs/383741731#L1198

@@ -73,6 +73,70 @@ static inline bool php_phongo_bulkwrite_update_has_operators(bson_t* bupdate) /*
return false;
} /* }}} */

/* Returns whether the BSON array's keys are a sequence of integer strings
* starting with "0". BSON_APPEND_ARRAY considers it the caller's responsibility
* to ensure that the array's keys are properly formatted. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is an equivalent to bson-encode.c's php_phongo_is_array_or_document? Should they be placed together perhaps? I don't mind, so please do what makes sense for you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

php_phongo_is_array_or_document() operates on a zval, while this validates a bson_t.

We can't work with the zval here, as we're not inspecting it until it's already been converted to a bson_t. In theory, this allows a Serializable value to produce a BSON array for this option.

<?php START('THROWAWAY', ["version" => "36-release"]); CLEANUP(THROWAWAY); ?>
<?php skip_if_not_live(); ?>
<?php skip_if_server_version('<', '3.6'); ?>
<?php skip_if_not_clean(); ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit misleading, innit? skip_if_not_clean will also clean first?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was made during #787.

Technically, the function attempts to drop the test collection and skips the test if that fails for some reason. I'll admit it's unlike other skip_if functions because it attempts to change the state of the system; however, it can actually skip if something goes wrong. In the past, CLEAN() ignored any errors.

If you have some ideas for renaming or revising this, a new ticket would be best 👍

Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jmikola jmikola merged commit 3c8fdfd into mongodb:master May 25, 2018
jmikola added a commit that referenced this pull request May 25, 2018
@jmikola jmikola deleted the phpc-1195 branch May 25, 2018 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants