Ejemplo n.º 1
0
/**
 * doExecuteImport
 *
 */
function doExecuteImport($fileName, &$argsObj, &$reqSpecMgr, &$reqMgr)
{
    $retval = new stdClass();
    $retval->items = array();
    $retval->msg = '';
    $retval->file_check = array('status_ok' => 1, 'msg' => 'ok');
    $retval->refreshTree = true;
    $context = new stdClass();
    $context->tproject_id = $argsObj->tproject_id;
    $context->req_spec_id = $argsObj->req_spec_id;
    $context->user_id = $argsObj->user_id;
    $context->importType = $argsObj->importType;
    $context->scope = $argsObj->scope;
    $opts = array();
    $opts['skipFrozenReq'] = $argsObj->skip_frozen_req ? true : false;
    $opts['hitCriteria'] = $argsObj->hitCriteria;
    $opts['actionOnHit'] = $argsObj->actionOnHit;
    // manage file upload process
    $file_size_limit = config_get('import_file_max_size_bytes');
    $source = isset($_FILES['uploadedFile']['tmp_name']) ? $_FILES['uploadedFile']['tmp_name'] : null;
    $check = checkUploadOperation($_FILES, $file_size_limit);
    if ($check['status_ok']) {
        if (move_uploaded_file($source, $fileName)) {
            if (strcasecmp($argsObj->importType, 'XML') == 0) {
                $retval->file_check['status_ok'] = !(($xml = simplexml_load_file($fileName)) === FALSE);
            }
        }
    } else {
        $retval->file_check = array('status_ok' => 0, 'msg' => $check['msg']);
    }
    // ----------------------------------------------------------------------------------------------
    if ($retval->file_check['status_ok']) {
        $import_ok = true;
        if ($argsObj->importType == 'XML') {
            try {
                $retval->items = doReqImportFromXML($reqSpecMgr, $reqMgr, $xml, $context, $opts);
            } catch (Exception $e) {
                $import_ok = false;
                $retval->items = null;
                $retval->msg = $e->getMessage();
                $retval->refreshTree = false;
            }
        } else {
            $retval->items = doReqImportOther($reqMgr, $fileName, $context, $opts);
        }
        unlink($fileName);
        if ($import_ok) {
            $retval->msg = lang_get('req_import_finished');
        }
    }
    return $retval;
}
Ejemplo n.º 2
0
/**
 * doExecuteImport
 *
 */
function doExecuteImport($fileName, &$argsObj, &$reqSpecMgr, &$reqMgr)
{
    $retval = new stdClass();
    $retval->items = array();
    $retval->msg = '';
    $retval->file_check = array('status_ok' => 1, 'msg' => 'ok');
    $context = new stdClass();
    $context->tproject_id = $argsObj->tproject_id;
    $context->req_spec_id = $argsObj->req_spec_id;
    $context->user_id = $argsObj->user_id;
    $context->importType = $argsObj->importType;
    $opts = array();
    $opts['skipFrozenReq'] = $argsObj->skip_frozen_req ? true : false;
    $opts['hitCriteria'] = $argsObj->hitCriteria;
    $opts['actionOnHit'] = $argsObj->actionOnHit;
    // manage file upload process
    $source = isset($_FILES['uploadedFile']['tmp_name']) ? $_FILES['uploadedFile']['tmp_name'] : null;
    if ($source != 'none' && $source != '') {
        if (move_uploaded_file($source, $fileName)) {
            if (strcasecmp($argsObj->importType, 'XML') == 0) {
                $retval->file_check['status_ok'] = !(($xml = simplexml_load_file($fileName)) === FALSE);
            }
        }
    } else {
        $retval->file_check = array('status_ok' => 0, 'msg' => lang_get('please_choose_req_file'));
    }
    // ----------------------------------------------------------------------------------------------
    if ($retval->file_check['status_ok']) {
        if ($argsObj->importType == 'XML') {
            $retval->items = doReqImportFromXML($reqSpecMgr, $reqMgr, $xml, $context, $opts);
        } else {
            $retval->items = doReqImportOther($reqMgr, $fileName, $context, $opts);
        }
        unlink($fileName);
        $retval->msg = lang_get('req_import_finished');
    }
    return $retval;
}
Ejemplo n.º 3
0
/**
 * doExecuteImport
 *
 */
function doExecuteImport($fileName, &$argsObj, &$reqSpecMgr, &$reqMgr)
{
    $retval = new stdClass();
    $retval->items = array();
    $retval->msg = '';
    $retval->file_check = array('status_ok' => 1, 'msg' => 'ok');
    $retval->userFeedback = null;
    $context = new stdClass();
    $context->tproject_id = $argsObj->tproject_id;
    $context->req_spec_id = $argsObj->req_spec_id;
    $context->user_id = $argsObj->user_id;
    $context->importType = $argsObj->importType;
    $opts = array();
    $opts['skipFrozenReq'] = $argsObj->skip_frozen_req ? true : false;
    $opts['hitCriteria'] = $argsObj->hitCriteria;
    $opts['actionOnHit'] = $argsObj->actionOnHit;
    // manage file upload process
    $source = isset($_FILES['uploadedFile']['tmp_name']) ? $_FILES['uploadedFile']['tmp_name'] : null;
    if ($source != 'none' && $source != '') {
        if (move_uploaded_file($source, $fileName)) {
            if ($argsObj->importType == 'XML') {
                $retval->file_check['status_ok'] = !(($xml = simplexml_load_file_wrapper($fileName)) === FALSE);
            }
        }
    } else {
        $retval->file_check = array('status_ok' => 0, 'msg' => lang_get('please_choose_req_file'));
    }
    // ----------------------------------------------------------------------------------------------
    /*
    if($retval->file_check['status_ok']) 
    {
      $isReqSpec = property_exists($xml,'req_spec');
      if(!$isReqSpec && $argsObj->req_spec_id <= 0) 
      {
        $retval->file_check = array('status_ok' => FALSE, 'msg' => lang_get('please_create_req_spec_first'));
      }
    }
    */
    if ($retval->file_check['status_ok']) {
        if ($argsObj->importType == 'XML') {
            // If there is no req_spec in XML, and req_spec_id
            // from context is null, we must raise an error, to avoid ghots requirements in DB
            $isReqSpec = property_exists($xml, 'req_spec');
            if (!$isReqSpec && $argsObj->req_spec_id <= 0) {
                $retval->file_check = array('status_ok' => FALSE, 'msg' => lang_get('please_create_req_spec_first'));
            } else {
                $retval->items = doReqImportFromXML($reqSpecMgr, $reqMgr, $xml, $context, $opts);
            }
        } else {
            $dummy = doReqImportOther($reqMgr, $fileName, $context, $opts);
            $retval->items = $dummy['items'];
            $retval->userFeedback = $dummy['userFeedback'];
        }
        unlink($fileName);
        $retval->msg = lang_get('req_import_finished');
    }
    return $retval;
}