Skip to content

Commit

Permalink
Merge pull request #1064 from dreamsxin/issues_1051_1.3.0
Browse files Browse the repository at this point in the history
Fix issues #1051 for 1.3.0
  • Loading branch information
Phalcon committed Aug 13, 2013
2 parents c7fafb4 + 5ba0766 commit d9c4039
Show file tree
Hide file tree
Showing 4 changed files with 69 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 @@ -5011,20 +5011,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 @@ -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();
}
Expand All @@ -5071,20 +5076,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 @@ -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();
}
Expand All @@ -5130,20 +5140,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 @@ -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();
}
Expand Down
41 changes: 32 additions & 9 deletions ext/mvc/model/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
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 d9c4039

Please sign in to comment.