Пример #1
0
/**
 * Process Job's results logged in a text file.
 * 
 * @param array $scan from table blended_scans
 */
function register_scannedjob($scan)
{
    global $CFG;
    global $scansfoldername;
    $jobid = $scan->id;
    $fieldspath = blended_getOMRFieldsetDir($scan);
    $logfile = blended_getOMRInputLogFilePath($scan);
    try {
        if ($logfile != 'null') {
            $logelements = read_log_file($logfile);
        }
        if (!isset($logelements) || count($logelements) == 0) {
            throw new OMRError("Log file is empty", OMRError::LOG_FILE_IS_EMPTY);
        }
    } catch (OMRError $e) {
        throw $e;
    }
    // open a transaction
    begin_sql();
    foreach ($logelements as $logelement) {
        try {
            //cada elemento es un registro de blended_images.
            $image_result = parse_log_elements($logelement);
            $image_result->jobid = $jobid;
            register_image($image_result);
            $acode = $image_result->activitycode;
            if ($acode != null) {
                if ($acode == 'Undetected') {
                    mtrace("Undetected activity code for result:" . $logelement);
                } else {
                    mtrace('<br>REGISTERING FIELDS...');
                    register_template_fields($image_result, $fieldspath);
                    mtrace('<br>REGISTERING RESULTS...');
                    register_result_files($image_result, $fieldspath);
                    mtrace('<br>CHECKING VALIDITY...');
                    check_invalid_results($image_result);
                }
            }
        } catch (Exception $e) {
            mtrace('OMRError: ' . $e->getMessage());
            register_exception($e, $jobid);
            $errorcode = $e->getCode();
            if ($errorcode == 5 or $errorcode == 6) {
                //print_object($e);
                //throw $e;
                continue;
                // process next result
            }
        }
    }
    mtrace('<br>UPDATING SCANJOB QUEUE...');
    update_record('blended_scans', $scan);
    // End the transaction
    commit_sql();
    return;
}
/**
 * 
 * Delete logfile log.txt from outputscandir
 * @param unknown_type $scan
 */
function blended_delete_log_file($scan)
{
    $logFilePath = blended_getOMRInputLogFilePath($scan);
    if (file_exists($logFilePath)) {
        debugging("<p>Removing {$logFilePath}</p>");
        unlink($logFilePath);
    }
}