Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1615 Executes afterSave after real saved #2994

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 28 additions & 25 deletions ext/mvc/model.c
Expand Up @@ -3363,17 +3363,9 @@ PHP_METHOD(Phalcon_Mvc_Model, _postSave){
}
PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name);

PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "afterSave", 1);
PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name);

RETURN_CTOR(success);
}

PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "notSave", 1);
PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name);
PHALCON_CALL_METHOD(NULL, this_ptr, "_canceloperation");

RETURN_MM_FALSE;
}

Expand Down Expand Up @@ -4224,7 +4216,7 @@ PHP_METHOD(Phalcon_Mvc_Model, save){
zval *attribute = NULL, *value = NULL, *possible_setter = NULL, *write_connection = NULL;
zval *related, *status = NULL, *schema = NULL, *source = NULL, *table = NULL, *read_connection = NULL;
zval *exists = NULL, *error_messages = NULL, *identity_field = NULL;
zval *nesting = NULL, *exception, *success = NULL, *new_success = NULL;
zval *nesting = NULL, *exception, *success = NULL, *new_success = NULL, *event_name = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
Expand Down Expand Up @@ -4360,7 +4352,9 @@ PHP_METHOD(Phalcon_Mvc_Model, save){
* Query the identity field
*/
PHALCON_CALL_METHOD(&identity_field, meta_data, "getidentityfield", this_ptr);


nesting = PHALCON_GLOBAL(z_false);

/**
* _preSave() makes all the validations
*/
Expand All @@ -4371,8 +4365,6 @@ PHP_METHOD(Phalcon_Mvc_Model, save){
* Rollback the current transaction if there was validation errors
*/
if (Z_TYPE_P(related) == IS_ARRAY) {
PHALCON_INIT_VAR(nesting);
ZVAL_BOOL(nesting, 0);
PHALCON_CALL_METHOD(NULL, write_connection, "rollback", nesting);
}

Expand Down Expand Up @@ -4428,21 +4420,32 @@ PHP_METHOD(Phalcon_Mvc_Model, save){
* Rollbacks the implicit transaction if the master save has failed
*/
if (PHALCON_IS_FALSE(new_success)) {
PHALCON_INIT_NVAR(nesting);
ZVAL_BOOL(nesting, 0);
PHALCON_CALL_METHOD(NULL, write_connection, "rollback", nesting);
RETURN_MM_FALSE;
}

/**
* Save the post-related records
*/
PHALCON_CALL_METHOD(&status, this_ptr, "_postsaverelatedrecords", write_connection, related);
if (PHALCON_IS_FALSE(status)) {
RETURN_MM_FALSE;
} else {
/**
* Save the post-related records
*/
PHALCON_CALL_METHOD(&status, this_ptr, "_postsaverelatedrecords", write_connection, related);
if (PHALCON_IS_FALSE(status)) {
PHALCON_CALL_METHOD(NULL, write_connection, "rollback", nesting);
}

PHALCON_CPY_WRT(new_success, status);
}
}


if (PHALCON_IS_FALSE(new_success)) {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "notSave", 1);
PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name);

PHALCON_CALL_METHOD(NULL, this_ptr, "_canceloperation");
} else {
PHALCON_INIT_NVAR(event_name);
ZVAL_STRING(event_name, "afterSave", 1);
PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name);
}

RETURN_CTOR(new_success);
}

Expand Down