웹마스터 팁

안드로이드 푸시 앱 연동 모듈을 개발하면서 몇가지 직면한 문제들을 해결한 팁을 공개하고자 합니다.

제가 잘 몰라서 우회적으로 해결한 경우인데,

문제는 function triggerAfterInsertDocument(&$obj) 안에서

$oDocumentModel = getModel('document');      
$oDocument = $oDocumentModel->getDocument($document_srl);

이렇게 해서 현재 document 핸들러를 가져온 뒤, 이것으로 작업을 할 때 아래와 같은 첨부파일과 관련된 메소드가 전혀 작동하지 않는다는 것입니다.

 

$file_list =  $oDocument->getUploadedFiles();

 

이런 경우 저는 이렇게 해결했습니다. 바로 triggerBeforeInsertDocument(&$obj) 글이 등록되기 전 트리거를 가져와서 거기서 첨부파일을 받아놓고 그 다음에 triggerAfterInsertDocument(&$obj)으로 첨부파일 관련 변수를 넘겨줌으로 해결했습니다.

 

function triggerBeforeInsertDocument(&$obj)
 {
  $document_srl = $obj->document_srl;

  if($GLOBALS['__androidpushapp__'][$document_srl]) unset($GLOBALS['__androidpushapp__'][$document_srl]);

  $sortIndex = 'file_srl';  
  $args = new stdClass();
  $args->upload_target_srl = $document_srl;
  $args->isvalid = "N";
  $args->sort_index = $sortIndex;

  $output = executeQueryArray("file.getFiles", $args);

  $file_list = $output->data;

  if($file_list && !is_array($file_list)) $file_list = array($file_list);

  $file_count = count($file_list);
  for($i=0;$i<$file_count;$i++)
  {
   $file = $file_list[$i];
   $file->source_filename = stripslashes($file->source_filename);
   $file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl);
   $file_list[$i] = $file;
  }

  $GLOBALS['__androidpushapp__'][$document_srl] = $file_list;
 } 
 

 function triggerAfterInsertDocument(&$obj)
 { 

...

    $arr_file=$GLOBALS['__androidpushapp__'][$document_srl];

...

}

 

저처럼 트리거에서 첨부파일을 가져올 수 없어서 애먹는 분이 계실까봐 도움이 되었으면 하는 바램으로 허접한 팁을 적었습니다.