Skip to content

Commit

Permalink
Add param replace for skipAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamsxin committed Aug 13, 2013
1 parent c876f9b commit 5ba0766
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
35 changes: 25 additions & 10 deletions ext/mvc/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -5013,20 +5013,25 @@ 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;
zval **hd;

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);

Expand All @@ -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();
}
Expand All @@ -5073,20 +5078,25 @@ 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;
zval **hd;

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);

Expand All @@ -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();
}
Expand All @@ -5132,20 +5142,25 @@ 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;
zval **hd;

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);

Expand All @@ -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();
}
Expand Down
18 changes: 9 additions & 9 deletions ext/mvc/model/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ 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;
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");
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
9 changes: 6 additions & 3 deletions ext/mvc/model/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions ext/mvc/model/metadatainterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5ba0766

Please sign in to comment.