IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 22, 2009, 4:51:58 PM (17 years ago)
Author:
Paul Price
Message:

Giving publishClient an 'active' column, and add mode to pubtool to turn this on and off. Only interested in active clients. This is so that I can do a publishing run that only sends data to particular clients.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pubtool.c

    r25256 r25929  
    3232
    3333static bool defineclientMode(pxConfig *config);
     34static bool updateclientMode(pxConfig *config);
    3435static bool definerunMode(pxConfig *config);
    3536static bool pendingMode(pxConfig *config);
     
    5758    switch (config->mode) {
    5859        MODECASE(PUBTOOL_MODE_DEFINECLIENT, defineclientMode);
     60        MODECASE(PUBTOOL_MODE_UPDATECLIENT, updateclientMode);
    5961        MODECASE(PUBTOOL_MODE_DEFINERUN, definerunMode);
    6062        MODECASE(PUBTOOL_MODE_PENDING, pendingMode);
     
    9496    PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
    9597
    96     if (!publishClientInsert(config->dbh, 0, product, stage, workdir, comment)) {
    97         psError(PS_ERR_UNKNOWN, false, "Database error");
    98         return false;
    99     }
     98    if (!publishClientInsert(config->dbh, 0, 0, product, stage, workdir, comment)) {
     99        psError(PS_ERR_UNKNOWN, false, "Database error");
     100        return false;
     101    }
     102
     103    return true;
     104}
     105
     106static bool updateclientMode(pxConfig *config)
     107{
     108    PS_ASSERT_PTR_NON_NULL(config, false);
     109
     110    psMetadata *where = psMetadataAlloc(); // WHERE conditions
     111    PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
     112    PXOPT_COPY_STR(config->args, where, "-product", "product", "==");
     113    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     114    PXOPT_COPY_STR(config->args, where, "-comment", "comment", "LIKE");
     115
     116    PXOPT_LOOKUP_BOOL(active, config->args, "-active",  false);
     117    PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive",  false);
     118
     119    if ((!active && !inactive) || (active && inactive)) {
     120        psError(PS_ERR_UNKNOWN, false, "Must specify one, and only one, of -active and -inactive.");
     121        psFree(where);
     122        return false;
     123    }
     124
     125    psString query = NULL;              // Query to run
     126    psStringAppend(&query, "UPDATE publishRun SET active = %d", active ? 1 : 0);
     127
     128    if (psListLength(where->list)) {
     129        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
     130        psStringAppend(&query, "\n AND %s", clause);
     131        psFree(clause);
     132    }
     133    psFree(where);
     134
     135    if (!p_psDBRunQuery(config->dbh, query)) {
     136        psError(PS_ERR_UNKNOWN, false, "Database error");
     137        psFree(query);
     138        return false;
     139    }
     140    psFree(query);
     141
     142    long numUpdated = psDBAffectedRows(config->dbh);
     143    psLogMsg("pubtool", PS_LOG_INFO, "%ld rows updated.", numUpdated);
    100144
    101145    return true;
Note: See TracChangeset for help on using the changeset viewer.