@@ -65,6 +65,35 @@ static inline bool php_phongo_bulkwrite_update_has_operators(bson_t *bupdate) /*
65
65
return false;
66
66
} /* }}} */
67
67
68
+ /* Appends a document field for the given opts document and key. Returns true on
69
+ * success; otherwise, false is returned and an exception is thrown. */
70
+ static bool php_phongo_bulkwrite_opts_append_document (bson_t * opts , const char * opts_key , zval * zarr , const char * zarr_key TSRMLS_DC )
71
+ {
72
+ zval * value = php_array_fetch (zarr , zarr_key );
73
+ bson_t b = BSON_INITIALIZER ;
74
+
75
+ if (Z_TYPE_P (value ) != IS_OBJECT && Z_TYPE_P (value ) != IS_ARRAY ) {
76
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected \"%s\" option to be array or object, %s given" , zarr_key , zend_get_type_by_const (Z_TYPE_P (value )));
77
+ return false;
78
+ }
79
+
80
+ phongo_zval_to_bson (value , PHONGO_BSON_NONE , & b , NULL TSRMLS_CC );
81
+
82
+ if (EG (exception )) {
83
+ bson_destroy (& b );
84
+ return false;
85
+ }
86
+
87
+ if (!BSON_APPEND_DOCUMENT (opts , opts_key , & b )) {
88
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"%s\" option" , opts_key );
89
+ bson_destroy (& b );
90
+ return false;
91
+ }
92
+
93
+ bson_destroy (& b );
94
+ return true;
95
+ }
96
+
68
97
#define PHONGO_BULKWRITE_APPEND_BOOL (opt , value ) \
69
98
if (!BSON_APPEND_BOOL(boptions, (opt), (value))) { \
70
99
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", (opt)); \
@@ -77,6 +106,13 @@ static inline bool php_phongo_bulkwrite_update_has_operators(bson_t *bupdate) /*
77
106
return false; \
78
107
}
79
108
109
+ #define PHONGO_BULKWRITE_OPT_DOCUMENT (opt ) \
110
+ if (zoptions && php_array_existsc(zoptions, (opt))) { \
111
+ if (!php_phongo_bulkwrite_opts_append_document(boptions, (opt), zoptions, (opt) TSRMLS_CC)) { \
112
+ return false; \
113
+ } \
114
+ }
115
+
80
116
/* Applies options (including defaults) for an update operation. */
81
117
static bool php_phongo_bulkwrite_update_apply_options (bson_t * boptions , zval * zoptions TSRMLS_DC )/* {{{ */
82
118
{
@@ -93,6 +129,7 @@ static bool php_phongo_bulkwrite_update_apply_options(bson_t *boptions, zval *zo
93
129
94
130
PHONGO_BULKWRITE_APPEND_BOOL ("multi" , multi );
95
131
PHONGO_BULKWRITE_APPEND_BOOL ("upsert" , upsert );
132
+ PHONGO_BULKWRITE_OPT_DOCUMENT ("collation" );
96
133
97
134
return true;
98
135
} /* }}} */
@@ -109,6 +146,7 @@ static bool php_phongo_bulkwrite_delete_apply_options(bson_t *boptions, zval *zo
109
146
}
110
147
111
148
PHONGO_BULKWRITE_APPEND_INT32 ("limit" , limit );
149
+ PHONGO_BULKWRITE_OPT_DOCUMENT ("collation" );
112
150
113
151
return true;
114
152
} /* }}} */
0 commit comments