Index: /branches/pap_mops/dbconfig/ipp.m4
===================================================================
--- /branches/pap_mops/dbconfig/ipp.m4	(revision 24412)
+++ /branches/pap_mops/dbconfig/ipp.m4	(revision 24413)
@@ -26,2 +26,3 @@
 include(rc.md)
 include(receive.md)
+include(publish.md)
Index: /branches/pap_mops/dbconfig/publish.md
===================================================================
--- /branches/pap_mops/dbconfig/publish.md	(revision 24412)
+++ /branches/pap_mops/dbconfig/publish.md	(revision 24413)
@@ -3,8 +3,8 @@
 publishClient   METADATA 
     client_id   S64         0       # Primary Key AUTO_INCREMENT
+    stage	STR	    64
+    destination STR	    255
+    format      STR	    64
     comment     STR         255
-    stage	STR	    64
-    format      STR	    64
-    destination STR	    255
 END
 
Index: /branches/pap_mops/ippTools/doc/publish_flow.txt
===================================================================
--- /branches/pap_mops/ippTools/doc/publish_flow.txt	(revision 24412)
+++ /branches/pap_mops/ippTools/doc/publish_flow.txt	(revision 24413)
@@ -13,4 +13,4 @@
 pubtool -revert
 
-### Regularly run by pantasks to mark running publishing runs as 'full'
+### Regularly run by pantasks to mark running publish runs as 'full'
 pubtool -advance
Index: /branches/pap_mops/ippTools/share/pubtool_advance.sql
===================================================================
--- /branches/pap_mops/ippTools/share/pubtool_advance.sql	(revision 24412)
+++ /branches/pap_mops/ippTools/share/pubtool_advance.sql	(revision 24413)
@@ -1,3 +1,5 @@
-SELECT
+UPDATE publishRun
+SET state = 'full'
+WHERE pub_id IN SELECT
     pub_id
 FROM ((
Index: /branches/pap_mops/ippTools/share/pubtool_revert.sql
===================================================================
--- /branches/pap_mops/ippTools/share/pubtool_revert.sql	(revision 24413)
+++ /branches/pap_mops/ippTools/share/pubtool_revert.sql	(revision 24413)
@@ -0,0 +1,5 @@
+DELETE FROM publishFile
+USING publishFile, publishRun, publishClient
+WHERE publishFile.pub_id = publishRun.pub_id
+    AND publishRun.client_id = publishClient.client_id
+    AND receiveResult.fault != 0
Index: /branches/pap_mops/ippTools/src/pubtool.c
===================================================================
--- /branches/pap_mops/ippTools/src/pubtool.c	(revision 24412)
+++ /branches/pap_mops/ippTools/src/pubtool.c	(revision 24413)
@@ -1,4 +1,4 @@
 /*
- * receivetool.c
+ * pubtool.c
  *
  * Copyright (C) 2008
@@ -29,17 +29,12 @@
 #include "pxtools.h"
 #include "pxdata.h"
-#include "receivetool.h"
-
-static bool definesourceMode(pxConfig *config);
-static bool listMode(pxConfig *config);
-static bool addfilesetMode(pxConfig *config);
-static bool updatelastMode(pxConfig *config);
-static bool pendingfilesetMode(pxConfig *config);
-static bool updatefilesetMode(pxConfig *config);
-static bool addfileMode(pxConfig *config);
-static bool pendingfileMode(pxConfig *config);
-static bool addresultMode(pxConfig *config);
-static bool toadvanceMode(pxConfig *config);
+#include "pubtool.h"
+
+static bool defineclientMode(pxConfig *config);
+static bool definerunMode(pxConfig *config);
+static bool pendingMode(pxConfig *config);
+static bool addMode(pxConfig *config);
 static bool revertMode(pxConfig *config);
+static bool advanceMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -55,5 +50,5 @@
     psLibInit(NULL);
 
-    pxConfig *config = receivetoolConfig(NULL, argc, argv);
+    pxConfig *config = pubtoolConfig(NULL, argc, argv);
     if (!config) {
         psError(PXTOOLS_ERR_CONFIG, false, "failed to configure");
@@ -62,15 +57,10 @@
 
     switch (config->mode) {
-        MODECASE(RECEIVETOOL_MODE_DEFINESOURCE, definesourceMode);
-        MODECASE(RECEIVETOOL_MODE_LIST, listMode);
-        MODECASE(RECEIVETOOL_MODE_ADDFILESET, addfilesetMode);
-        MODECASE(RECEIVETOOL_MODE_UPDATELAST, updatelastMode);
-        MODECASE(RECEIVETOOL_MODE_PENDINGFILESET, pendingfilesetMode);
-        MODECASE(RECEIVETOOL_MODE_UPDATEFILESET, updatefilesetMode);
-        MODECASE(RECEIVETOOL_MODE_TOADVANCE, toadvanceMode);
-        MODECASE(RECEIVETOOL_MODE_ADDFILE, addfileMode);
-        MODECASE(RECEIVETOOL_MODE_PENDINGFILE, pendingfileMode);
-        MODECASE(RECEIVETOOL_MODE_ADDRESULT, addresultMode);
-        MODECASE(RECEIVETOOL_MODE_REVERT, revertMode);
+        MODECASE(PUBTOOL_MODE_DEFINECLIENT, defineclientMode);
+        MODECASE(PUBTOOL_MODE_DEFINERUN, definerunMode);
+        MODECASE(PUBTOOL_MODE_PENDING, pendingMode);
+        MODECASE(PUBTOOL_MODE_ADD, addMode);
+        MODECASE(PUBTOOL_MODE_REVERT, revertMode);
+        MODECASE(PUBTOOL_MODE_ADVANCE, advanceMode);
       default:
         psAbort("invalid option (this should not happen)");
@@ -94,29 +84,25 @@
 }
 
-static bool definesourceMode(pxConfig *config)
+static bool defineclientMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
     // required
-    PXOPT_LOOKUP_STR(source, config->args, "-source", true, false);
-    PXOPT_LOOKUP_STR(product, config->args, "-product",  true, false);
-    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, 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);
-    PXOPT_LOOKUP_STR(last, config->args, "-last",  false, false);
-    PXOPT_LOOKUP_STR(status_product, config->args, "-status_product",  false, false);
-    PXOPT_LOOKUP_STR(ds_dbname, config->args, "-ds_dbname",  false, false);
-    PXOPT_LOOKUP_STR(ds_dbhost, config->args, "-ds_dbhost",  false, false);
-
-    if (!receiveSourceInsert(config->dbh, 0, source, product, workdir, comment, last, status_product, ds_dbname, ds_dbhost)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-
-    return true;
-}
-
-static bool listMode(pxConfig *config)
+
+    if (!publishClientInsert(config->dbh, 0, stage, destination, format, comment)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+
+    return true;
+}
+
+static bool definerunMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -124,14 +110,11 @@
     psMetadata *where = psMetadataAlloc(); // WHERE conditions
 
-    // required
-    PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
-    PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
-    PXOPT_COPY_S64(config->args, where, "-comment", "receiveSource.comment", "LIKE");
-
     // optional
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    psString query = pxDataGet("receivetool_list.sql");
+    PXOPT_COPY_STR(config->args, where, "-client_id", "client_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+
+    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
+
+    psString query = pxDataGet("pubtool_definerun.sql"); // Query to run
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
@@ -140,81 +123,55 @@
     }
 
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        psFree(where);
+        return false;
+    }
+
+    psString whereClause = psStringCopy(""); // Additional constraints to add to query
     if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " WHERE %s", whereClause);
+        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&whereClause, " AND %s", clause);
+        psFree(clause);
+    }
+    psFree(where);
+
+    if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        psFree(query);
         psFree(whereClause);
-    }
-    psFree(where);
-
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        psFree(query);
+        if (!psDBTransaction(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "Database error");
+        }
         return false;
     }
     psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
+    psFree(whereClause);
+
+    psArray *output = p_psDBFetchResult(config->dbh); // Output of SELECT statement
     if (!output) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
+        if (!psDBTransaction(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "Database error");
+        }
         return false;
     }
     if (!psArrayLength(output)) {
-        psTrace("receivetool", PS_LOG_INFO, "No rows found");
+        psTrace("pubtool", PS_LOG_INFO, "No rows found");
         psFree(output);
+        if (!psDBTransaction(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "Database error");
+        }
         return true;
     }
-    if (!ippdbPrintMetadatas(stdout, output, "receiveSource", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
-        psFree(output);
-        return false;
-    }
-    psFree(output);
-
-    return true;
-}
-
-static bool addfilesetMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    // required
-    PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
-    psMetadataItem *filesets = psMetadataLookup(config->args, "-fileset");
-    if (!filesets) {
-        psError(PS_ERR_UNKNOWN, true, "-fileset is required");
-        return false;
-    }
-
-    psString query = pxDataGet("receivetool_addfileset.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
-        return false;
-    }
-
-    if (!psDBTransaction(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-
-    psString source_id_str = NULL;      // source_id as a string
-    psStringAppend(&source_id_str, "%" PRId64, source_id);
-
-    psListIterator *iter = psListIteratorAlloc(filesets->data.list, PS_LIST_HEAD, false); // Iterator
-    psMetadataItem *item = NULL;        // Item from iteration
-    while ((item = psListGetAndIncrement(iter))) {
-        psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
-        const char *fileset = item->data.str; // Fileset name
-
-        if (!p_psDBRunQueryF(config->dbh, query, source_id_str, fileset)) {
-            psError(PS_ERR_UNKNOWN, false, "Database error");
-            psFree(source_id_str);
-            psFree(query);
-            psFree(iter);
+
+    for (int i = 0; i < output->n; i++) {
+        psMetadata *row = output->data[i]; // Row of interest
+        psS64 client = psMetadataLookupS64(NULL, row, "client_id"); // Client identifier
+        psS64 stage = psMetadataLookupS64(NULL, row, "stage_id");   // Stage identifier
+
+        if (!publishRunInsert(config->dbh, 0, client, stage, set_label, "new")) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
+            psFree(output);
             if (!psDBTransaction(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "Database error");
@@ -222,76 +179,26 @@
             return false;
         }
-
-        psArray *output = p_psDBFetchResult(config->dbh); // Output of query
-        if (!output) {
-            psError(PS_ERR_UNKNOWN, false, "Database error");
-            psFree(source_id_str);
-            psFree(query);
-            psFree(iter);
-            return false;
-        }
-        if (psArrayLength(output) > 0) {
-            psTrace("receivetool", PS_LOG_INFO, "Fileset %s is already present", fileset);
-            psFree(output);
-            continue;
-        }
-        psFree(output);
-
-        if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset, "reg", NULL, NULL, 0)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
-            psFree(source_id_str);
-            psFree(query);
-            psFree(iter);
-            if (!psDBTransaction(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "Database error");
-            }
-            return false;
-        }
-    }
-    psFree(iter);
-    psFree(query);
-    psFree(source_id_str);
-
-    if (!psDBCommit(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-
-    return true;
-}
-
-static bool updatelastMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
+    }
+    psFree(output);
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+
+    return true;
+}
+
+static bool pendingMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *where = psMetadataAlloc(); // WHERE conditions
 
     // required
-    PXOPT_LOOKUP_S64(source_id, config->args, "-src_id", true, false);
-    PXOPT_LOOKUP_STR(fileset, config->args, "-fileset",  true, false);
-
-    psString query = NULL;              // Query to execute
-    psStringAppend(&query, "UPDATE receiveSource SET fileset_last = \'%s\' WHERE source_id = %" PRId64,
-                   fileset, source_id);
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    return true;
-}
-
-
-static bool pendingfilesetMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psMetadata *where = psMetadataAlloc(); // WHERE conditions
-
-    // required
-    PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
-    PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
-    PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
+    PXOPT_COPY_STR(config->args, where, "-client_id", "publishClient.client_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-stage", "publishClient.stage", "==");
+    PXOPT_COPY_STR(config->args, where, "-comment", "publishClient.comment", "LIKE");
+    PXOPT_COPY_STR(config->args, where, "-label", "publishRun.label", "==");
 
     // optional
@@ -299,5 +206,5 @@
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
-    psString query = pxDataGet("receivetool_pendingfileset.sql");
+    psString query = pxDataGet("pubtool_pending.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
@@ -332,9 +239,9 @@
     }
     if (!psArrayLength(output)) {
-        psTrace("receivetool", PS_LOG_INFO, "No rows found");
+        psTrace("pubtool", PS_LOG_INFO, "No rows found");
         psFree(output);
         return true;
     }
-    if (!ippdbPrintMetadatas(stdout, output, "receiveFileset", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "publishRun", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "Failed to print array");
         psFree(output);
@@ -346,83 +253,39 @@
 }
 
-static bool addfileMode(pxConfig *config)
+static bool addMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
     // required
-    PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
-    PXOPT_LOOKUP_STR(file_list, config->args, "-file_list", true, false);
-
-    unsigned int numBad;
-    psMetadata *files = psMetadataConfigRead(NULL, &numBad, file_list, false);
-    if (!files) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to cleanly read MDC file with file list.");
-        return false;
-    }
-
-
-    if (!psDBTransaction(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-
-    psMetadataIterator *iter = psMetadataIteratorAlloc(files, PS_LIST_HEAD, NULL); // Iterator
-    psMetadataItem *item;
-    while ((item = psMetadataGetAndIncrement(iter))) {
-        psMetadata *md = item->data.md;
-        psString file = psMetadataLookupStr(NULL, md, "file");
-        psS64    bytes = psMetadataLookupS64(NULL, md, "bytes");
-        psString md5sum = psMetadataLookupStr(NULL, md, "md5sum");
-        psString file_type = psMetadataLookupStr(NULL, md, "file_type");
-        psString component = psMetadataLookupStr(NULL, md, "component");
-        
-        if (!file) {
-            psError(PS_ERR_UNKNOWN, false, "failed to find value for file");
-            return false;
-        }
-        if (!component) {
-            psError(PS_ERR_UNKNOWN, false, "failed to find value for component");
-            return false;
-        }
-
-        if (!receiveFileInsert(config->dbh, 0, fileset_id, file, bytes, md5sum, file_type, component)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to add file");
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "Database error");
-                return false;
-            }
-            psFree(iter);
-            return false;
-        }
-    }
-
-    psFree(iter);
-
-    if (!psDBCommit(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-
-    return true;
-}
-
-static bool pendingfileMode(pxConfig *config)
+    PXOPT_LOOKUP_S64(pub_id, config->args, "-pub_id", true, false);
+    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
+
+    // optional
+    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
+
+    if (!publishFileInsert(config->dbh, pub_id, component, fault)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to add file");
+        return false;
+    }
+
+    return true;
+}
+
+
+
+
+static bool revertMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
     psMetadata *where = psMetadataAlloc(); // WHERE conditions
-
-    // required
-    PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
-    PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
-    PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
-    PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveFile.fileset_id", "==");
-    PXOPT_COPY_S64(config->args, where, "-file_id", "receiveFile.file_id", "==");
-
-    // optional
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    psString query = pxDataGet("receivetool_pendingfile.sql");
+    PXOPT_COPY_S64(config->args, where, "-pub_id", "pub_id", "==");
+    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", "==");
+
+    psString query = pxDataGet("pubtool_revert.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
@@ -438,10 +301,4 @@
     psFree(where);
 
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
     if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
@@ -451,69 +308,15 @@
     psFree(query);
 
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psTrace("receivetool", PS_LOG_INFO, "No rows found");
-        psFree(output);
-        return true;
-    }
-    if (!ippdbPrintMetadatas(stdout, output, "receiveFile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
-        psFree(output);
-        return false;
-    }
-    psFree(output);
-
-    return true;
-}
-
-static bool addresultMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    // required
-    PXOPT_LOOKUP_S64(file_id, config->args, "-file_id", true, false);
-
-    // optional
-    PXOPT_LOOKUP_F32(dtime_copy, config->args, "-dtime_copy", false, false);
-    PXOPT_LOOKUP_F32(dtime_extract, config->args, "-dtime_extract", false, false);
-    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
-
-    if (!receiveResultInsert(config->dbh, file_id, dtime_copy, dtime_extract, fault)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-
-    return true;
-}
-
-static bool revertMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psMetadata *where = psMetadataAlloc(); // WHERE conditions
-
-    PXOPT_COPY_S64(config->args, where, "-fileset_id", "receiveResult.fileset_id", "==");
-    PXOPT_COPY_S32(config->args, where, "-fault", "receiveResult.fault", "==");
-    PXOPT_COPY_STR(config->args, where, "-source", "receiveSource.source", "==");
-    PXOPT_COPY_STR(config->args, where, "-product", "receiveSource.product", "==");
-    PXOPT_COPY_STR(config->args, where, "-comment", "receiveSource.comment", "LIKE");
-
-    psString query = pxDataGet("receivetool_revert.sql");
+    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");
-        psFree(where);
-        return false;
-    }
-
-    if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-    psFree(where);
+        return false;
+    }
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -526,110 +329,2 @@
     return true;
 }
-static bool toadvanceMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psMetadata *where = psMetadataAlloc(); // WHERE conditions
-
-    // optional
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    psString query = pxDataGet("receivetool_toadvance.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
-        psFree(where);
-        return false;
-    }
-
-    if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-    psFree(where);
-
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psTrace("receivetool", PS_LOG_INFO, "No rows found");
-        psFree(output);
-        return true;
-    }
-    if (!ippdbPrintMetadatas(stdout, output, "toadvanceFilesets", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
-        psFree(output);
-        return false;
-    }
-    psFree(output);
-
-    return true;
-}
-
-static bool updatefilesetMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    // required
-    PXOPT_LOOKUP_S64(fileset_id, config->args, "-fileset_id", true, false);
-
-    // to chanage
-    PXOPT_LOOKUP_S32(fault, config->args, "-fault", false, false);
-    PXOPT_LOOKUP_STR(destdir, config->args, "-destdir", false, false);
-    PXOPT_LOOKUP_STR(dirinfo, config->args, "-dirinfo", false, false);
-    PXOPT_LOOKUP_STR(dbinfo, config->args, "-dbinfo", false, false);
-    PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
-
-    if (!fault && !dirinfo &&!dbinfo && !state) {
-        psError(PS_ERR_UNKNOWN, true, "at least one of -fault, -dirinfo, -dbinfo, -set_state are required");
-        return false;
-    }
-
-    psString query = NULL;              // Query to execute
-    psStringAppend(&query, "UPDATE receiveFileset SET ");
-    
-    psString sep = "";
-    if (fault) {
-        psStringAppend(&query, "%s fault = %d", sep, fault);
-        sep = ",";
-    }
-    if (dirinfo) {
-        psStringAppend(&query, "%s dirinfo = '%s'", sep, dirinfo);
-        sep = ",";
-    }
-    if (dbinfo) {
-        psStringAppend(&query, "%s dbinfo = '%s'", sep, dbinfo);
-        sep = ",";
-    }
-    if (state) {
-        psStringAppend(&query, "%s state = '%s'", sep, state);
-        sep = ",";
-    }
-    
-    psStringAppend(&query, " WHERE fileset_id = %" PRId64, fileset_id);
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    return true;
-}
Index: /branches/pap_mops/ippTools/src/pubtoolConfig.c
===================================================================
--- /branches/pap_mops/ippTools/src/pubtoolConfig.c	(revision 24412)
+++ /branches/pap_mops/ippTools/src/pubtoolConfig.c	(revision 24413)
@@ -46,12 +46,12 @@
     psMetadata *defineclientArgs = psMetadataAlloc();
     psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-stage", 0, "define stage (required)", NULL);
-    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
     psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-destination", 0, "define destination (required)", NULL);
     psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-format", 0, "define format", NULL);
+    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
 
     // -definerun
     psMetadata *definerunArgs = psMetadataAlloc();
-    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-client_id", 0, "define client_id (required)", 0);
     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-set_label", 0, "define label", 0);
+    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-client_id", 0, "search by client_id", 0);
     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-label", 0, "search by label", 0);
 
@@ -61,7 +61,7 @@
     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-stage", 0, "search on source", NULL);
     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
     psMetadataAddBool(pendingArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
     psMetadataAddU64(pendingArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
-    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
 
     // -add
@@ -82,6 +82,4 @@
     // -advance
     psMetadata *advanceArgs = psMetadataAlloc();
-    psMetadataAddS64(advanceArgs, PS_LIST_TAIL, "-pub_id", 0, "search on pub_id", 0);
-    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
 
     psMetadata *argSets = psMetadataAlloc();
