Example #1
0
/**
 * doExecuteImport
 *
 */
function doExecuteImport(&$dbHandler, $fileName, &$argsObj, &$reqSpecMgr)
{
    $retval = new stdClass();
    $retval->items = null;
    $retval->msg = '';
    if ($argsObj->importType == 'XML') {
        $xml = simplexml_load_file($fileName);
        // if achecked_req is null => user has not selected any requirement, anyway we are going to create reqspec tree
        $filter['requirements'] = $argsObj->achecked_req;
        $retval->items = array();
        $isReqSpec = property_exists($xml, 'req_spec');
        if ($isReqSpec) {
            foreach ($xml->req_spec as $xkm) {
                $dummy = $reqSpecMgr->createFromXML($xkm, $argsObj->tproject_id, $argsObj->req_spec_id, $argsObj->user_id);
                $retval->items = array_merge($retval->items, $dummy);
            }
        } else {
            $selectedKeys = array_keys($argsObj->achecked_req[0]);
            if (count($selectedKeys) > 0) {
                $reqMgr = new requirement_mgr($dbHandler);
                $retval->items = null;
                foreach ($selectedKeys as $kdx) {
                    $retval->items[] = $reqMgr->createFromXML($xml->requirement[$kdx], $argsObj->tproject_id, $argsObj->req_spec_id, $argsObj->user_id);
                }
            }
        }
    } else {
        $retval->items = doReqImport($dbHandler, $argsObj->tproject_id, $argsObj->user_id, $argsObj->req_spec_id, $fileName, $argsObj->importType, $argsObj->emptyScope, $argsObj->conflictSolution, true);
    }
    unlink($fileName);
    $retval->msg = lang_get('req_import_finished');
    return $retval;
}