From 5ba0766e17665d20ae6dbc13d98810dc35daa711 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Tue, 13 Aug 2013 10:01:28 +0800 Subject: [PATCH] Add param replace for skipAttributes --- ext/mvc/model.c | 35 ++++++++++++++++++++++--------- ext/mvc/model/metadata.c | 18 ++++++++-------- ext/mvc/model/metadata.h | 9 +++++--- ext/mvc/model/metadatainterface.h | 9 +++++--- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/ext/mvc/model.c b/ext/mvc/model.c index c1084a3f1f9..5c94fc34b3e 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -5013,7 +5013,7 @@ PHP_METHOD(Phalcon_Mvc_Model, writeAttribute){ */ PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ - zval *attributes, *null_value, *keys_attributes; + zval *attributes, *replace = NULL, *null_value, *keys_attributes; zval *attribute = NULL, *meta_data; HashTable *ah0; HashPosition hp0; @@ -5021,12 +5021,17 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &attributes); + phalcon_fetch_params(1, 1, 1, &attributes, &replace); if (Z_TYPE_P(attributes) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); return; } + + if (!replace) { + PHALCON_INIT_VAR(replace); + ZVAL_FALSE(replace); + } PHALCON_INIT_VAR(null_value); @@ -5046,8 +5051,8 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ PHALCON_INIT_VAR(meta_data); phalcon_call_method(meta_data, this_ptr, "getmodelsmetadata"); - phalcon_call_method_p2_noret(meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes); - phalcon_call_method_p2_noret(meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes); + phalcon_call_method_p3_noret(meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes, replace); + phalcon_call_method_p3_noret(meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, replace); PHALCON_MM_RESTORE(); } @@ -5073,7 +5078,7 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ */ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ - zval *attributes, *null_value, *keys_attributes; + zval *attributes, *replace = NULL, *null_value, *keys_attributes; zval *attribute = NULL, *meta_data; HashTable *ah0; HashPosition hp0; @@ -5081,12 +5086,17 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &attributes); + phalcon_fetch_params(1, 1, 1, &attributes, &replace); if (Z_TYPE_P(attributes) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); return; } + + if (!replace) { + PHALCON_INIT_VAR(replace); + ZVAL_FALSE(replace); + } PHALCON_INIT_VAR(null_value); @@ -5106,7 +5116,7 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ PHALCON_INIT_VAR(meta_data); phalcon_call_method(meta_data, this_ptr, "getmodelsmetadata"); - phalcon_call_method_p2_noret(meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes); + phalcon_call_method_p3_noret(meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes, replace); PHALCON_MM_RESTORE(); } @@ -5132,7 +5142,7 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ */ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ - zval *attributes, *null_value, *keys_attributes; + zval *attributes, *replace = NULL, *null_value, *keys_attributes; zval *attribute = NULL, *meta_data; HashTable *ah0; HashPosition hp0; @@ -5140,12 +5150,17 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &attributes); + phalcon_fetch_params(1, 1, 1, &attributes, &replace); if (Z_TYPE_P(attributes) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); return; } + + if (!replace) { + PHALCON_INIT_VAR(replace); + ZVAL_FALSE(replace); + } PHALCON_INIT_VAR(null_value); @@ -5165,7 +5180,7 @@ PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ PHALCON_INIT_VAR(meta_data); phalcon_call_method(meta_data, this_ptr, "getmodelsmetadata"); - phalcon_call_method_p2_noret(meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes); + phalcon_call_method_p3_noret(meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, replace); PHALCON_MM_RESTORE(); } diff --git a/ext/mvc/model/metadata.c b/ext/mvc/model/metadata.c index 583f9e725f7..4e9dc3983a7 100644 --- a/ext/mvc/model/metadata.c +++ b/ext/mvc/model/metadata.c @@ -446,7 +446,7 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaDataIndex){ */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex){ - zval *model, *index, *data, *table, *schema, *class_name; + zval *model, *index, *data, *replace, *table, *schema, *class_name; zval *key, *meta_data = NULL, *arr, *value; HashTable *ah2; HashPosition hp2; @@ -454,7 +454,7 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex){ PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &model, &index, &data); + phalcon_fetch_params(1, 4, 0, &model, &index, &data, &replace); if (Z_TYPE_P(model) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); @@ -496,7 +496,7 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex){ PHALCON_OBS_NVAR(meta_data); phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC); - } else { + } else if (!zend_is_true(replace)) { PHALCON_OBS_VAR(arr); phalcon_array_fetch(&arr, meta_data, key, PH_NOISY); @@ -933,15 +933,15 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, getAutomaticUpdateAttributes){ */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, setAutomaticCreateAttributes){ - zval *model, *attributes, *create_index; + zval *model, *attributes, *replace, *create_index; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &model, &attributes); + phalcon_fetch_params(1, 3, 0, &model, &attributes, &replace); PHALCON_INIT_VAR(create_index); ZVAL_LONG(create_index, 10); - phalcon_call_method_p3_noret(this_ptr, "writemetadataindex", model, create_index, attributes); + phalcon_call_method_p4_noret(this_ptr, "writemetadataindex", model, create_index, attributes, replace); PHALCON_MM_RESTORE(); } @@ -958,15 +958,15 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, setAutomaticCreateAttributes){ */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, setAutomaticUpdateAttributes){ - zval *model, *attributes, *create_index; + zval *model, *attributes, *replace, *create_index; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &model, &attributes); + phalcon_fetch_params(1, 3, 0, &model, &attributes, &replace); PHALCON_INIT_VAR(create_index); ZVAL_LONG(create_index, 11); - phalcon_call_method_p3_noret(this_ptr, "writemetadataindex", model, create_index, attributes); + phalcon_call_method_p4_noret(this_ptr, "writemetadataindex", model, create_index, attributes, replace); PHALCON_MM_RESTORE(); } diff --git a/ext/mvc/model/metadata.h b/ext/mvc/model/metadata.h index fefa5476dd6..1d6f95ca6d1 100644 --- a/ext/mvc/model/metadata.h +++ b/ext/mvc/model/metadata.h @@ -66,10 +66,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_readmetadataindex, 0, ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_writemetadataindex, 0, 0, 3) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_writemetadataindex, 0, 0, 4) ZEND_ARG_INFO(0, model) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, replace) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_readcolumnmap, 0, 0, 1) @@ -121,14 +122,16 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_getautomaticupdateattr ZEND_ARG_INFO(0, model) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_setautomaticcreateattributes, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_setautomaticcreateattributes, 0, 0, 3) ZEND_ARG_INFO(0, model) ZEND_ARG_INFO(0, attributes) + ZEND_ARG_INFO(0, replace) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_setautomaticupdateattributes, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_setautomaticupdateattributes, 0, 0, 3) ZEND_ARG_INFO(0, model) ZEND_ARG_INFO(0, attributes) + ZEND_ARG_INFO(0, replace) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadata_getcolumnmap, 0, 0, 1) diff --git a/ext/mvc/model/metadatainterface.h b/ext/mvc/model/metadatainterface.h index ae520ba7190..4f4506848c6 100644 --- a/ext/mvc/model/metadatainterface.h +++ b/ext/mvc/model/metadatainterface.h @@ -34,10 +34,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_readmetadatai ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_writemetadataindex, 0, 0, 3) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_writemetadataindex, 0, 0, 4) ZEND_ARG_INFO(0, model) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, replace) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_readcolumnmap, 0, 0, 1) @@ -89,14 +90,16 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_getautomaticu ZEND_ARG_INFO(0, model) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_setautomaticcreateattributes, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_setautomaticcreateattributes, 0, 0, 3) ZEND_ARG_INFO(0, model) ZEND_ARG_INFO(0, attributes) + ZEND_ARG_INFO(0, replace) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_setautomaticupdateattributes, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_setautomaticupdateattributes, 0, 0, 3) ZEND_ARG_INFO(0, model) ZEND_ARG_INFO(0, attributes) + ZEND_ARG_INFO(0, replace) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_metadatainterface_getcolumnmap, 0, 0, 1)