Index: branches/pap_mops/ippTools/src/pubtool.c
===================================================================
--- branches/pap_mops/ippTools/src/pubtool.c	(revision 24413)
+++ branches/pap_mops/ippTools/src/pubtool.c	(revision 24427)
@@ -36,5 +36,4 @@
 static bool addMode(pxConfig *config);
 static bool revertMode(pxConfig *config);
-static bool advanceMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -62,5 +61,4 @@
         MODECASE(PUBTOOL_MODE_ADD, addMode);
         MODECASE(PUBTOOL_MODE_REVERT, revertMode);
-        MODECASE(PUBTOOL_MODE_ADVANCE, advanceMode);
       default:
         psAbort("invalid option (this should not happen)");
@@ -89,12 +87,11 @@
 
     // required
+    PXOPT_LOOKUP_STR(product, config->args, "-product",  true, false);
     PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
-    PXOPT_LOOKUP_STR(destination, config->args, "-destination",  true, false);
 
     // optional
-    PXOPT_LOOKUP_STR(format, config->args, "-format",  false, false);
     PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
 
-    if (!publishClientInsert(config->dbh, 0, stage, destination, format, comment)) {
+    if (!publishClientInsert(config->dbh, 0, product, stage, comment)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
@@ -109,4 +106,7 @@
 
     psMetadata *where = psMetadataAlloc(); // WHERE conditions
+
+    // required
+    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir",  true, false);
 
     // optional
@@ -141,5 +141,5 @@
         psFree(query);
         psFree(whereClause);
-        if (!psDBTransaction(config->dbh)) {
+        if (!psDBRollback(config->dbh)) {
             psError(PS_ERR_UNKNOWN, false, "Database error");
         }
@@ -152,5 +152,5 @@
     if (!output) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
-        if (!psDBTransaction(config->dbh)) {
+        if (!psDBRollback(config->dbh)) {
             psError(PS_ERR_UNKNOWN, false, "Database error");
         }
@@ -160,5 +160,5 @@
         psTrace("pubtool", PS_LOG_INFO, "No rows found");
         psFree(output);
-        if (!psDBTransaction(config->dbh)) {
+        if (!psDBRollback(config->dbh)) {
             psError(PS_ERR_UNKNOWN, false, "Database error");
         }
@@ -171,8 +171,8 @@
         psS64 stage = psMetadataLookupS64(NULL, row, "stage_id");   // Stage identifier
 
-        if (!publishRunInsert(config->dbh, 0, client, stage, set_label, "new")) {
+        if (!publishRunInsert(config->dbh, 0, client, stage, workdir, set_label, "new")) {
             psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
             psFree(output);
-            if (!psDBTransaction(config->dbh)) {
+            if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "Database error");
             }
@@ -182,5 +182,5 @@
     psFree(output);
 
-    if (!psDBTransaction(config->dbh)) {
+    if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
@@ -259,11 +259,34 @@
     // required
     PXOPT_LOOKUP_S64(pub_id, config->args, "-pub_id", true, false);
-    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
+    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base",  true, false);
 
     // optional
     PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
 
-    if (!publishFileInsert(config->dbh, pub_id, component, fault)) {
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+
+    if (!publishDoneInsert(config->dbh, pub_id, path_base, fault)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to add file");
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "Database error");
+        }
+        return false;
+    }
+
+    if (!p_psDBRunQueryF(config->dbh,
+                         "UPDATE publishRun SET state = 'full' WHERE pub_id = %" PRId64,
+                         pub_id)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "Database error");
+        }
+        return false;
+    }
+
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
         return false;
     }
@@ -283,5 +306,4 @@
     PXOPT_COPY_S32(config->args, where, "-fault", "fault", "==");
     PXOPT_COPY_STR(config->args, where, "-client_id", "client_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     PXOPT_COPY_STR(config->args, where, "-comment", "comment", "LIKE");
     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
@@ -310,21 +332,3 @@
     return true;
 }
-static bool advanceMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psString query = pxDataGet("pubtool_advance.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
-        return false;
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    return true;
-}
+
