r18180 - gnucash/trunk/src - 1) When deleting a sched transaction, delete the recurrence properly (SQL backend)

Phil Longstaff plongstaff at code.gnucash.org
Mon Jul 6 19:11:56 EDT 2009


Author: plongstaff
Date: 2009-07-06 19:11:56 -0400 (Mon, 06 Jul 2009)
New Revision: 18180
Trac: http://svn.gnucash.org/trac/changeset/18180

Modified:
   gnucash/trunk/src/backend/sql/gnc-schedxaction-sql.c
   gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/SchedXaction.h
   gnucash/trunk/src/gnome/dialog-sx-editor.c
   gnucash/trunk/src/gnome/dialog-sx-from-trans.c
   gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c
Log:
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.


Modified: gnucash/trunk/src/backend/sql/gnc-schedxaction-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-schedxaction-sql.c	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/backend/sql/gnc-schedxaction-sql.c	2009-07-06 23:11:56 UTC (rev 18180)
@@ -296,11 +296,15 @@
 	}
     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 );

Modified: gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/backend/xml/gnc-schedxaction-xml-v2.c	2009-07-06 23:11:56 UTC (rev 18180)
@@ -673,7 +673,8 @@
     {
             g_critical("failed to parse scheduled xaction");
             xmlElemDump( stdout, NULL, tree );
-            xaccSchedXactionFree( sx );
+			gnc_sx_begin_edit( sx );
+            xaccSchedXactionDestroy( sx );
             goto done;
     }
 

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/engine/SchedXaction.c	2009-07-06 23:11:56 UTC (rev 18180)
@@ -169,6 +169,13 @@
 }
 
 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 @@
   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 @@
   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);
 }
 
 /* ============================================================ */

Modified: gnucash/trunk/src/engine/SchedXaction.h
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.h	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/engine/SchedXaction.h	2009-07-06 23:11:56 UTC (rev 18180)
@@ -140,9 +140,9 @@
 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);

Modified: gnucash/trunk/src/gnome/dialog-sx-editor.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-editor.c	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/gnome/dialog-sx-editor.c	2009-07-06 23:11:56 UTC (rev 18180)
@@ -1033,7 +1033,8 @@
          * "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;
 

Modified: gnucash/trunk/src/gnome/dialog-sx-from-trans.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-from-trans.c	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/gnome/dialog-sx-from-trans.c	2009-07-06 23:11:56 UTC (rev 18180)
@@ -527,7 +527,8 @@
 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 @@
   SXFromTransInfo *sxfti = (SXFromTransInfo*)user_data;
 
   if ( sxfti->sx ) {
-    xaccSchedXactionFree(sxfti->sx);
+	gnc_sx_begin_edit(sxfti->sx);
+    xaccSchedXactionDestroy(sxfti->sx);
     sxfti->sx = NULL;
   }
 

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c	2009-07-06 18:58:54 UTC (rev 18179)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c	2009-07-06 23:11:56 UTC (rev 18180)
@@ -557,7 +557,8 @@
     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



More information about the gnucash-changes mailing list