From 8275e5c3f6249e3911f74975b7c86dd8936df479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 24 Sep 2024 13:45:53 +0200 Subject: [PATCH 1/2] PHPC-2348 Remove WriteException and move getWriteResult to BulkWriteException --- config.m4 | 1 - config.w32 | 2 +- php_phongo.c | 1 - src/MongoDB/Exception/BulkWriteException.c | 16 +++++++- .../Exception/BulkWriteException.stub.php | 6 ++- .../Exception/BulkWriteException_arginfo.h | 17 ++++++-- src/MongoDB/Exception/WriteException.c | 41 ------------------- src/MongoDB/Exception/WriteException.stub.php | 17 -------- .../Exception/WriteException_arginfo.h | 31 -------------- src/phongo_classes.h | 2 - 10 files changed, 35 insertions(+), 99 deletions(-) delete mode 100644 src/MongoDB/Exception/WriteException.c delete mode 100644 src/MongoDB/Exception/WriteException.stub.php delete mode 100644 src/MongoDB/Exception/WriteException_arginfo.h diff --git a/config.m4 b/config.m4 index deeb21987..b886ab597 100644 --- a/config.m4 +++ b/config.m4 @@ -197,7 +197,6 @@ if test "$PHP_MONGODB" != "no"; then src/MongoDB/Exception/ServerException.c \ src/MongoDB/Exception/SSLConnectionException.c \ src/MongoDB/Exception/UnexpectedValueException.c \ - src/MongoDB/Exception/WriteException.c \ src/MongoDB/Monitoring/CommandFailedEvent.c \ src/MongoDB/Monitoring/CommandStartedEvent.c \ src/MongoDB/Monitoring/CommandSubscriber.c \ diff --git a/config.w32 b/config.w32 index 7dd7a89b0..620d7fad2 100644 --- a/config.w32 +++ b/config.w32 @@ -117,7 +117,7 @@ if (PHP_MONGODB != "no") { MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_log.c phongo_util.c"); MONGODB_ADD_SOURCES("/src/BSON", "Binary.c BinaryInterface.c Document.c Iterator.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c PackedArray.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c"); MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c"); - MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c"); + MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c"); MONGODB_ADD_SOURCES("/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c LogSubscriber.c SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c"); MONGODB_ADD_SOURCES("/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES); MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/bson", PHP_MONGODB_BSON_SOURCES); diff --git a/php_phongo.c b/php_phongo.c index b21f4d4da..fb7b6d55a 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -273,7 +273,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ php_phongo_runtimeexception_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_serverexception_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_connectionexception_init_ce(INIT_FUNC_ARGS_PASSTHRU); - php_phongo_writeexception_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_authenticationexception_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS_PASSTHRU); diff --git a/src/MongoDB/Exception/BulkWriteException.c b/src/MongoDB/Exception/BulkWriteException.c index 762713e6a..57989ba29 100644 --- a/src/MongoDB/Exception/BulkWriteException.c +++ b/src/MongoDB/Exception/BulkWriteException.c @@ -17,11 +17,25 @@ #include #include "php_phongo.h" +#include "phongo_error.h" #include "BulkWriteException_arginfo.h" zend_class_entry* php_phongo_bulkwriteexception_ce; +/* Returns the WriteResult from the failed write operation. */ +static PHP_METHOD(MongoDB_Driver_Exception_BulkWriteException, getWriteResult) +{ + zval* writeresult; + zval rv; + + PHONGO_PARSE_PARAMETERS_NONE(); + + writeresult = zend_read_property(php_phongo_bulkwriteexception_ce, Z_OBJ_P(getThis()), ZEND_STRL("writeResult"), 0, &rv); + + RETURN_ZVAL(writeresult, 1, 0); +} + void php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS) { - php_phongo_bulkwriteexception_ce = register_class_MongoDB_Driver_Exception_BulkWriteException(php_phongo_writeexception_ce); + php_phongo_bulkwriteexception_ce = register_class_MongoDB_Driver_Exception_BulkWriteException(php_phongo_serverexception_ce); } diff --git a/src/MongoDB/Exception/BulkWriteException.stub.php b/src/MongoDB/Exception/BulkWriteException.stub.php index a8c562b0b..5efaabfed 100644 --- a/src/MongoDB/Exception/BulkWriteException.stub.php +++ b/src/MongoDB/Exception/BulkWriteException.stub.php @@ -7,6 +7,10 @@ namespace MongoDB\Driver\Exception; -class BulkWriteException extends WriteException +class BulkWriteException extends RuntimeException { + /** @var \MongoDB\Driver\WriteResult */ + protected $writeResult; + + final public function getWriteResult(): \MongoDB\Driver\WriteResult {} } diff --git a/src/MongoDB/Exception/BulkWriteException_arginfo.h b/src/MongoDB/Exception/BulkWriteException_arginfo.h index 0646c0fc0..3ea41c95b 100644 --- a/src/MongoDB/Exception/BulkWriteException_arginfo.h +++ b/src/MongoDB/Exception/BulkWriteException_arginfo.h @@ -1,19 +1,30 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 330d290dbbcd19c7f10afd7a08b3f57ad4497cd7 */ + * Stub hash: 8d6c350124574a892c9bbe1c8fda8b0a55e09a8b */ +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Exception_BulkWriteException_getWriteResult, 0, 0, MongoDB\\Driver\\WriteResult, 0) +ZEND_END_ARG_INFO() +static ZEND_METHOD(MongoDB_Driver_Exception_BulkWriteException, getWriteResult); + static const zend_function_entry class_MongoDB_Driver_Exception_BulkWriteException_methods[] = { + ZEND_ME(MongoDB_Driver_Exception_BulkWriteException, getWriteResult, arginfo_class_MongoDB_Driver_Exception_BulkWriteException_getWriteResult, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_FE_END }; -static zend_class_entry *register_class_MongoDB_Driver_Exception_BulkWriteException(zend_class_entry *class_entry_MongoDB_Driver_Exception_WriteException) +static zend_class_entry *register_class_MongoDB_Driver_Exception_BulkWriteException(zend_class_entry *class_entry_MongoDB_Driver_Exception_RuntimeException) { zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "BulkWriteException", class_MongoDB_Driver_Exception_BulkWriteException_methods); - class_entry = zend_register_internal_class_ex(&ce, class_entry_MongoDB_Driver_Exception_WriteException); + class_entry = zend_register_internal_class_ex(&ce, class_entry_MongoDB_Driver_Exception_RuntimeException); + + zval property_writeResult_default_value; + ZVAL_NULL(&property_writeResult_default_value); + zend_string *property_writeResult_name = zend_string_init("writeResult", sizeof("writeResult") - 1, 1); + zend_declare_typed_property(class_entry, property_writeResult_name, &property_writeResult_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); + zend_string_release(property_writeResult_name); return class_entry; } diff --git a/src/MongoDB/Exception/WriteException.c b/src/MongoDB/Exception/WriteException.c deleted file mode 100644 index c866a04cf..000000000 --- a/src/MongoDB/Exception/WriteException.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2014-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "php_phongo.h" -#include "phongo_error.h" -#include "WriteException_arginfo.h" - -zend_class_entry* php_phongo_writeexception_ce; - -/* Returns the WriteResult from the failed write operation. */ -static PHP_METHOD(MongoDB_Driver_Exception_WriteException, getWriteResult) -{ - zval* writeresult; - zval rv; - - PHONGO_PARSE_PARAMETERS_NONE(); - - writeresult = zend_read_property(php_phongo_writeexception_ce, Z_OBJ_P(getThis()), ZEND_STRL("writeResult"), 0, &rv); - - RETURN_ZVAL(writeresult, 1, 0); -} - -void php_phongo_writeexception_init_ce(INIT_FUNC_ARGS) -{ - php_phongo_writeexception_ce = register_class_MongoDB_Driver_Exception_WriteException(php_phongo_serverexception_ce); -} diff --git a/src/MongoDB/Exception/WriteException.stub.php b/src/MongoDB/Exception/WriteException.stub.php deleted file mode 100644 index 4372e933a..000000000 --- a/src/MongoDB/Exception/WriteException.stub.php +++ /dev/null @@ -1,17 +0,0 @@ -ce_flags |= ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED; - - zval property_writeResult_default_value; - ZVAL_NULL(&property_writeResult_default_value); - zend_string *property_writeResult_name = zend_string_init("writeResult", sizeof("writeResult") - 1, 1); - zend_declare_property_ex(class_entry, property_writeResult_name, &property_writeResult_default_value, ZEND_ACC_PROTECTED, NULL); - zend_string_release(property_writeResult_name); - - return class_entry; -} diff --git a/src/phongo_classes.h b/src/phongo_classes.h index 090e4e7da..af8c42e5b 100644 --- a/src/phongo_classes.h +++ b/src/phongo_classes.h @@ -328,7 +328,6 @@ extern zend_class_entry* php_phongo_sslconnectionexception_ce; extern zend_class_entry* php_phongo_encryptionexception_ce; extern zend_class_entry* php_phongo_executiontimeoutexception_ce; extern zend_class_entry* php_phongo_connectiontimeoutexception_ce; -extern zend_class_entry* php_phongo_writeexception_ce; extern zend_class_entry* php_phongo_bulkwriteexception_ce; extern zend_class_entry* php_phongo_type_ce; @@ -444,7 +443,6 @@ extern void php_phongo_runtimeexception_init_ce(INIT_FUNC_ARGS); extern void php_phongo_serverexception_init_ce(INIT_FUNC_ARGS); extern void php_phongo_sslconnectionexception_init_ce(INIT_FUNC_ARGS); extern void php_phongo_unexpectedvalueexception_init_ce(INIT_FUNC_ARGS); -extern void php_phongo_writeexception_init_ce(INIT_FUNC_ARGS); extern void php_phongo_commandfailedevent_init_ce(INIT_FUNC_ARGS); extern void php_phongo_commandstartedevent_init_ce(INIT_FUNC_ARGS); From be69c0d2aa4e4d775feacce1b6660e843696e3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 24 Sep 2024 14:18:13 +0200 Subject: [PATCH 2/2] Fix BulkWriteException_arginfo.h from php ./build/gen_stub.php --force-regeneration --- src/MongoDB/Exception/BulkWriteException_arginfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MongoDB/Exception/BulkWriteException_arginfo.h b/src/MongoDB/Exception/BulkWriteException_arginfo.h index 3ea41c95b..3d4da702f 100644 --- a/src/MongoDB/Exception/BulkWriteException_arginfo.h +++ b/src/MongoDB/Exception/BulkWriteException_arginfo.h @@ -23,7 +23,7 @@ static zend_class_entry *register_class_MongoDB_Driver_Exception_BulkWriteExcept zval property_writeResult_default_value; ZVAL_NULL(&property_writeResult_default_value); zend_string *property_writeResult_name = zend_string_init("writeResult", sizeof("writeResult") - 1, 1); - zend_declare_typed_property(class_entry, property_writeResult_name, &property_writeResult_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); + zend_declare_property_ex(class_entry, property_writeResult_name, &property_writeResult_default_value, ZEND_ACC_PROTECTED, NULL); zend_string_release(property_writeResult_name); return class_entry;