1) When deleting a sched transaction, delete the recurrence properly (SQL backend)

2) Fix bug 586558 – When a scheduled transaction is deleted, the objects aren't cleaned up properly
The problem is that the xaccSchedXactionFree() function didn't properly call qof to commit the
delete operation.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18180 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2009-07-06 23:11:56 +00:00
parent 06d7cdea42
commit bde496195d
7 changed files with 31 additions and 12 deletions

View File

@ -296,11 +296,15 @@ gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst )
}
is_ok = gnc_sql_do_db_operation( be, op, SCHEDXACTION_TABLE, GNC_SX_ID, pSx, col_table );
guid = qof_instance_get_guid( inst );
gnc_sql_recurrence_save_list( be, guid, gnc_sx_get_schedule( pSx ) );
if( op == OP_DB_INSERT || op == OP_DB_UPDATE ) {
gnc_sql_recurrence_save_list( be, guid, gnc_sx_get_schedule( pSx ) );
} else {
gnc_sql_recurrence_delete( be, guid );
}
if( is_ok ) {
// Now, commit any slots
if( !qof_instance_get_destroying(inst) ) {
if( op == OP_DB_INSERT || op == OP_DB_UPDATE ) {
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
} else {
is_ok = gnc_sql_slots_delete( be, guid );

View File

@ -673,7 +673,8 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
{
g_critical("failed to parse scheduled xaction");
xmlElemDump( stdout, NULL, tree );
xaccSchedXactionFree( sx );
gnc_sx_begin_edit( sx );
xaccSchedXactionDestroy( sx );
goto done;
}

View File

@ -169,6 +169,13 @@ sx_set_template_account (SchedXaction *sx, Account *account)
}
void
xaccSchedXactionDestroy( SchedXaction *sx )
{
qof_instance_set_destroying( QOF_INSTANCE(sx), TRUE );
gnc_sx_commit_edit( sx );
}
static void
xaccSchedXactionFree( SchedXaction *sx )
{
GList *l;
@ -216,6 +223,11 @@ gnc_sx_begin_edit (SchedXaction *sx)
qof_begin_edit (&sx->inst);
}
static void sx_free(QofInstance* inst )
{
xaccSchedXactionFree( GNC_SX(inst) );
}
static void commit_err (QofInstance *inst, QofBackendError errcode)
{
g_critical("Failed to commit: %d", errcode);
@ -227,13 +239,11 @@ static void commit_done(QofInstance *inst)
qof_event_gen (inst, QOF_EVENT_MODIFY, NULL);
}
static void noop(QofInstance *inst) {}
void
gnc_sx_commit_edit (SchedXaction *sx)
{
if (!qof_commit_edit (QOF_INSTANCE(sx))) return;
qof_commit_edit_part2 (&sx->inst, commit_err, commit_done, noop);
qof_commit_edit_part2 (&sx->inst, commit_err, commit_done, sx_free);
}
/* ============================================================ */

View File

@ -140,9 +140,9 @@ SchedXaction *xaccSchedXactionMalloc(QofBook *book);
void sx_set_template_account (SchedXaction *sx, Account *account);
/**
* Cleans up and frees a SchedXaction and it's associated data.
* Cleans up and frees a SchedXaction and its associated data.
*/
void xaccSchedXactionFree( SchedXaction *sx );
void xaccSchedXactionDestroy( SchedXaction *sx );
void gnc_sx_begin_edit (SchedXaction *sx);
void gnc_sx_commit_edit (SchedXaction *sx);

View File

@ -1033,7 +1033,8 @@ scheduledxaction_editor_dialog_destroy(GtkObject *object, gpointer data)
* "Cancel" is clicked, the flag will still be true, and this
* SX will be cleaned, here. -- jsled
*/
xaccSchedXactionFree( sxed->sx );
gnc_sx_begin_edit( sxed->sx );
xaccSchedXactionDestroy( sxed->sx );
}
sxed->sx = NULL;

View File

@ -527,7 +527,8 @@ static void
sxftd_close(SXFromTransInfo *sxfti, gboolean delete_sx)
{
if ( sxfti->sx && delete_sx ) {
xaccSchedXactionFree(sxfti->sx);
gnc_sx_begin_edit(sxfti->sx);
xaccSchedXactionDestroy(sxfti->sx);
}
sxfti->sx = NULL;
@ -627,7 +628,8 @@ sxftd_destroy( GtkWidget *w, gpointer user_data )
SXFromTransInfo *sxfti = (SXFromTransInfo*)user_data;
if ( sxfti->sx ) {
xaccSchedXactionFree(sxfti->sx);
gnc_sx_begin_edit(sxfti->sx);
xaccSchedXactionDestroy(sxfti->sx);
sxfti->sx = NULL;
}

View File

@ -557,7 +557,8 @@ _destroy_sx(gpointer data, gpointer user_data)
book = gnc_get_current_book();
sxes = gnc_book_get_schedxactions(book);
gnc_sxes_del_sx(sxes, sx);
xaccSchedXactionFree(sx);
gnc_sx_begin_edit(sx);
xaccSchedXactionDestroy(sx);
}
static void