diff --git a/modules/importer/importer.admin.controller.php b/modules/importer/importer.admin.controller.php index b54c9534c..67a70d66f 100644 --- a/modules/importer/importer.admin.controller.php +++ b/modules/importer/importer.admin.controller.php @@ -36,7 +36,6 @@ * @brief XML파일을 미리 분석하여 개발 단위로 캐싱 **/ function procImporterAdminPreProcessing() { - DebugPrint('procImporterAdminPreProcessing...'); // 이전할 대상 xml파일을 구함 $xml_file = Context::get('xml_file'); @@ -56,7 +55,6 @@ if($output->toBool()) $oExtract->saveItems(); break; case 'ttxml' : - DebugPrint('preprocessing ttxml started.'); // 카테고리 정보를 구함 $output = $oExtract->set($xml_file, '', '', '', ''); if ($output->toBool()) { @@ -74,7 +72,6 @@ $category_filename = sprintf('%s/%s', $oExtract->cache_path, 'category.xml'); FileHandler::writeFile($category_filename, $buff); - DebugPrint('category finished.'); // 방명록 정보를 구함 $output = $oExtract->set($xml_file, '', '', '', ''); @@ -97,13 +94,11 @@ $guestbook_filename = sprintf('%s/%s', $oExtract->cache_path, 'guestbook.xml'); FileHandler::writeFile($guestbook_filename, $buff); - DebugPrint('guestbook finished.'); // 개별 아이템 구함 $output = $oExtract->set($xml_file,'', ''); if($output->toBool()) $oExtract->saveItems(); - DebugPrint('data finished.'); } } break; @@ -471,6 +466,12 @@ $category_list = $category_titles = array(); $category_list = $oDocumentModel->getCategoryList($module_srl); if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; + + $ek_args->module_srl = $module_srl; + $output = executeQueryArray('document.getDocumentExtraKeys', $ek_args); + if($output->data) { + foreach($output->data as $key => $val) $extra_keys[$val->eid] = true; + } if(!$cur) $cur = 0; @@ -498,6 +499,7 @@ $obj->document_srl = getNextSequence(); $files = array(); + $extra_vars = array(); $started = false; $buff = null; @@ -527,7 +529,7 @@ // 추가 변수 시작 일 경우 } elseif(trim($str) == '') { - $this->importExtraVars($fp, $obj); + $extra_vars = $this->importExtraVars($fp); continue; } @@ -591,6 +593,37 @@ } + // 확장변수 추가 + if(count($extra_vars)) { + foreach($extra_vars as $key => $val) { + if(!$val->value) continue; + unset($e_args); + $e_args->module_srl = $module_srl; + $e_args->document_srl = $obj->document_srl; + $e_args->var_idx = $val->var_idx; + $e_args->value = $val->value; + $e_args->lang_code = $val->lang_code; + $e_args->eid = $val->eid; + + // 등록된 확장변수 키가 없으면 생성(제목/내용 언어별 변수는 제외) + if(!preg_match('/^(title|content)_(.+)$/i',$e_args->eid) && !$extra_keys[$e_args->eid]) { + unset($ek_args); + $ek_args->module_srl = $module_srl; + $ek_args->var_idx = $val->var_idx; + $ek_args->var_name = $val->eid; + $ek_args->var_type = 'text'; + $ek_args->var_is_required = 'N'; + $ek_args->var_default = ''; + $ek_args->eid = $val->eid; + $output = executeQuery('document.insertDocumentExtraKey', $ek_args); + debugPrint($output); + $extra_keys[$ek_args->eid] = true; + } + + $output = executeQuery('document.insertDocumentExtraVar', $e_args); + } + } + fclose($fp); FileHandler::removeFile($target_file); } @@ -893,22 +926,38 @@ /** * @brief 게시글 추가 변수 설정 **/ - function importExtraVars($fp, &$obj) { - $index = 1; + function importExtraVars($fp) { + $buff = null; while(!feof($fp)) { - $str = trim(fgets($fp, 1024)); + $buff .= $str = trim(fgets($fp, 1024)); if(trim($str) == '') break; - - $buff .= $str; - $pos = strpos($buff, '>'); - $key = substr($buff, 1, $pos-1); - if(substr($buff, -1 * ( strlen($key)+3)) == '') { - $val = base64_decode(substr($buff, $pos, strlen($buff)-$pos*2-2)); - $obj->{"extra_vars".$index} = $val; - $buff = null; - $index++; - } } + if(!$buff) return array(); + + $buff = ''.$buff; + $oXmlParser = new XmlParser(); + $xmlDoc = $this->oXmlParser->parse($buff); + if(!count($xmlDoc->extra_vars->key)) return array(); + + $index = 1; + foreach($xmlDoc->extra_vars->key as $k => $v) { + unset($vobj); + if($v->var_idx) { + $vobj->var_idx = base64_decode($v->var_idx->body); + $vobj->lang_code = base64_decode($v->lang_code->body); + $vobj->value = base64_decode($v->value->body); + $vobj->eid = base64_decode($v->eid->body); + + } else if($v->body) { + $vobj->var_idx = $index; + $vobj->lang_code = Context::getLangType(); + $vobj->value = base64_decode($v->body); + $vobj->eid = 'extra_vars'.$index; + } + $extra_vars["extra_vars".$index] = $vobj; + $index++; + } + return $extra_vars; } } ?> diff --git a/modules/importer/ttimport.class.php b/modules/importer/ttimport.class.php index 258bda3b2..2431f93ee 100644 --- a/modules/importer/ttimport.class.php +++ b/modules/importer/ttimport.class.php @@ -16,7 +16,6 @@ * @brief module.xml 형식의 데이터 import **/ function importModule($key, $cur, $index_file, $unit_count, $module_srl, $guestbook_module_srl, $user_id) { - DebugPrint('Import start...'); // 필요한 객체 미리 생성 $this->oXmlParser = new XmlParser(); @@ -30,7 +29,6 @@ // 먼저 카테고리 정보를 입력함 $category_file = preg_replace('/index$/i', 'category.xml', $index_file); if(file_exists($category_file)) { - DebugPrint('Category importing...'); // xmlParser객체 생성 $xmlDoc = $this->oXmlParser->loadXmlFile($category_file); @@ -56,7 +54,6 @@ $oDocumentController->makeCategoryFile($module_srl); } FileHandler::removeFile($category_file); - DebugPrint('Category imported.'); } $category_list = $category_titles = array(); $category_list = $oDocumentModel->getCategoryList($module_srl); @@ -69,13 +66,11 @@ // 방명록 정보를 입력함 $guestbook_file = preg_replace('/index$/i', 'guestbook.xml', $index_file); if (file_exists($guestbook_file)) { - DebugPrint('Guestbook importing...'); // xmlParser객체 생성 $xmlDoc = $this->oXmlParser->loadXmlFile($guestbook_file); // 방명록 정보를 처리 if($guestbook_module_srl && $xmlDoc->guestbook->comment) { - DebugPrint('Started.'); $comment = $xmlDoc->guestbook->comment; if(!is_array($comment)) $comment = array($comment); foreach($comment as $key => $val) { @@ -87,7 +82,6 @@ $obj->is_secret = $val->secret->body=='1'?'Y':'N'; $obj->content = nl2br($val->content->body); - DebugPrint($obj->content); // 본문에서 제목 추출 $obj->title = cut_str(strip_tags($obj->content),20,'...');