IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30671


Ignore:
Timestamp:
Feb 17, 2011, 11:28:02 AM (15 years ago)
Author:
bills
Message:

when restoring original images be sure to clear the underlying run and files magicked values

File:
1 edited

Legend:

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

    r30548 r30671  
    709709
    710710
     711// update the magicked column for the underlying component
     712// Note: Must be called inside a transaction
     713
    711714static bool
    712 setMagicked(pxConfig *config, psS64 magic_ds_id, psString component)
     715setMagicked(pxConfig *config, psS64 magic_ds_id, psString component, bool clearMagicked)
    713716{
    714717    // first query the magicDSRun to find the stage and the stage_id
     
    741744    psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id");
    742745    psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id");
     746    psFree(output);
     747
     748    psS64 newMagickedValue;
     749    if (clearMagicked) {
     750        newMagickedValue = 0;
     751    } else {
     752        newMagickedValue = magic_id;
     753    }
    743754
    744755    ippStage stageNum = ippStringToStage(stage);
    745756
    746757    // chose the appropriate query based on the stage
     758    char *clearRunQuery = NULL;
    747759    switch (stageNum) {
    748760    case IPP_STAGE_RAW:
    749761        query = "UPDATE rawImfile SET magicked = %" PRId64 " where exp_id = %" PRId64 " AND class_id = '%s'";
     762        clearRunQuery = "UPDATE rawExp SET magicked = 0 where exp_id = %" PRId64;
    750763        break;
    751764    case IPP_STAGE_CHIP:
    752765        query = "UPDATE chipProcessedImfile SET magicked = %" PRId64 " where chip_id = %" PRId64 " AND class_id = '%s'";
     766        clearRunQuery = "UPDATE chipRun set magicked = 0 where chip_id = %" PRId64;
    753767        break;
    754768    case IPP_STAGE_CHIP_BG:
    755769        query = "UPDATE chipBackgroundImfile SET magicked = %" PRId64 " where chip_bg_id = %" PRId64 " AND class_id = '%s'";
     770        clearRunQuery = "UPDATE chipBackgroundRun SET magicked = 0 where chip_bg_id = %" PRId64;
    756771        break;
    757772    case IPP_STAGE_CAMERA:
    758         // no there is no magicked column in camProcessedExp so we have nothing to do
    759         psFree(output);
    760         return true;
     773        psFree(query);
     774        query = NULL;
     775        clearRunQuery = "UPDATE chipBackgroundRun SET magicked = 0 where chip_bg_id = %" PRId64;
     776        break;
    761777    case IPP_STAGE_WARP:
    762778        query = "UPDATE warpSkyfile SET magicked = %" PRId64 " where warp_id = %" PRId64 " AND skycell_id = '%s'";
     779        clearRunQuery = "UPDATE warpRun SET magicked = 0 where warp_id = %" PRId64;
    763780        break;
    764781    case IPP_STAGE_WARP_BG:
    765782        query = "UPDATE warpBackgroundSkyfile SET magicked = %" PRId64 " where warp_bg_id = %" PRId64 " AND skycell_id = '%s'";
     783        clearRunQuery = "UPDATE warpBackgroundRun SET magicked = 0 where warp_bg_id = %" PRId64;
    766784        break;
    767785    case IPP_STAGE_DIFF:
    768786        query = "UPDATE diffSkyfile SET magicked = %" PRId64 " where diff_id = %" PRId64 " AND skycell_id = '%s'";
     787        clearRunQuery = "UPDATE diffRun SET magicked = 0 where diff_id = %" PRId64;
    769788        break;
    770789    default:
    771790        psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage);
    772         psFree(output);
    773         return false;
    774     }
    775 
    776     if (!p_psDBRunQueryF(config->dbh, query, magic_id, stage_id, component)) {
    777         psError(PS_ERR_UNKNOWN, false, "database error");
    778         return false;
    779     }
    780     psFree(output);
    781 
    782     psU64 affected = psDBAffectedRows(config->dbh);
    783     if (affected != 1) {
    784         psError(PS_ERR_UNKNOWN, false, "should have affected 1 row");
    785         return false;
     791        return false;
     792    }
     793
     794    if (query) {
     795        if (!p_psDBRunQueryF(config->dbh, query, newMagickedValue, stage_id, component)) {
     796            psError(PS_ERR_UNKNOWN, false, "database error");
     797            return false;
     798        }
     799    }
     800
     801    if (clearMagicked && clearRunQuery) {
     802        if (!p_psDBRunQueryF(config->dbh, clearRunQuery, stage_id)) {
     803            psError(PS_ERR_UNKNOWN, false, "database error");
     804            return false;
     805        }
    786806    }
    787807
     
    896916    if (setmagicked) {
    897917        // set the image file's magicked flag
    898         if (!setMagicked(config, magic_ds_id, component)) {
     918        if (!setMagicked(config, magic_ds_id, component, false)) {
    899919            psError(PS_ERR_UNKNOWN, false, "setMagicked failed");
    900920            if (!psDBRollback(config->dbh)) {
     
    11111131    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    11121132
     1133    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     1134    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
    11131135    PXOPT_LOOKUP_STR(state, config->args, "-state", false, false);
    11141136    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     
    11161138    psString queryFile = NULL;
    11171139    bool stateIsUpdate = false;
     1140    bool toRestored = !strcmp(state, "goto_restored");
    11181141    if (state) {
    1119         if (! strcmp(state, "new") || !strcmp(state, "goto_restored")) {
     1142        if (! strcmp(state, "new") || toRestored) {
    11201143            queryFile = "magicdstool_revertdestreakedfile.sql";
    11211144        } else if (!strcmp(state, "update")) {
     
    11531176    }
    11541177
     1178    if (!psDBTransaction(config->dbh)) {
     1179        psError(PS_ERR_UNKNOWN, false, "database error");
     1180        return false;
     1181    }
    11551182    if (!p_psDBRunQuery(config->dbh, query)) {
    11561183        psError(PS_ERR_UNKNOWN, false, "failed to revert");
     
    11591186    }
    11601187    psFree(query);
     1188    if (toRestored) {
     1189        // clear the underlying component's magicked value
     1190        if (!setMagicked(config, magic_ds_id, component, true)) {
     1191            psError(PS_ERR_UNKNOWN, false, "setMagicked failed");
     1192            if (!psDBRollback(config->dbh)) {
     1193                psError(PS_ERR_UNKNOWN, false, "database error");
     1194            }
     1195            return false;
     1196        }
     1197    }
     1198    if (!psDBCommit(config->dbh)) {
     1199        psError(PS_ERR_UNKNOWN, false, "database error");
     1200        return false;
     1201    }
    11611202    return true;
    11621203}
     
    16611702    }
    16621703    if (!strcmp(data_state, "full")) {
    1663         // if -tofullfile optoinally set the magicked value for the component
    1664         PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false);
    1665         // set the image file's magicked flag
    1666         if (!setMagicked(config, magic_ds_id, component)) {
     1704        // set the component's magicked flag
     1705       
     1706        if (!setMagicked(config, magic_ds_id, component, false)) {
    16671707            psError(PS_ERR_UNKNOWN, false, "setMagicked failed");
    16681708            if (!psDBRollback(config->dbh)) {
     
    17161756    return change_file_data_state(config, "full");
    17171757}
    1718 /*
    1719 static bool topurgedimfileMode(pxConfig *config)
    1720 {
    1721     return change_imfile_data_state(config, "purged", "goto_purged");
    1722 }
    1723 static bool toscrubbedfileMode(pxConfig *config)
    1724 {
    1725   return change_file_data_state(config, "scrubbed", "goto_scrubbed");
    1726 }
    1727 */
    17281758
    17291759// a very specfic function to queue a cleaned magicDSFile to be updated
Note: See TracChangeset for help on using the changeset viewer.