diff --git a/ext/mvc/model.c b/ext/mvc/model.c index 1e3d2cda31a..d319a343c45 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -5011,7 +5011,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; @@ -5019,12 +5019,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); @@ -5044,8 +5049,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(); } @@ -5071,7 +5076,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; @@ -5079,12 +5084,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); @@ -5104,7 +5114,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(); } @@ -5130,7 +5140,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; @@ -5138,12 +5148,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); @@ -5163,7 +5178,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 664805c25cb..b5b95f6c487 100644 --- a/ext/mvc/model/metadata.c +++ b/ext/mvc/model/metadata.c @@ -33,6 +33,7 @@ #include "kernel/fcall.h" #include "kernel/object.h" +#include "kernel/hash.h" #include "kernel/array.h" #include "kernel/concat.h" #include "kernel/exception.h" @@ -444,12 +445,15 @@ PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaDataIndex){ */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex){ - zval *model, *index, *data, *table, *schema, *class_name; - zval *key, *meta_data = NULL; + zval *model, *index, *data, *replace, *table, *schema, *class_name; + zval *key, *meta_data = NULL, *arr, *value; + HashTable *ah2; + HashPosition hp2; + zval **hd; 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"); @@ -491,6 +495,25 @@ 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 if (!zend_is_true(replace)) { + PHALCON_OBS_VAR(arr); + phalcon_array_fetch(&arr, meta_data, key, PH_NOISY); + + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, arr, index, PH_NOISY); + + PHALCON_SEPARATE_PARAM(data); + phalcon_is_iterable(value, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + zval key2 = phalcon_get_current_key_w(ah2, &hp2); + + if (!phalcon_array_isset(data, &key2)) { + phalcon_array_update_zval(&data, &key2, hd, PH_COPY | PH_SEPARATE); + } + + zend_hash_move_forward_ex(ah2, &hp2); + } } phalcon_array_update_multi_2(&meta_data, key, index, &data, 0); @@ -909,15 +932,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(); } @@ -934,15 +957,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)