Ejemplo n.º 1
0
 /**
  * 场景1:针对处理错误的文件,重新提交转换请求,这种场景针对的是文件转换中,CPU超时导致的文件转换失败
  * 本次操作将一次性把系统中所有的转换失败的文件转换一次
  * 使用方式:手动执行
  */
 public function actionConvertFailFile()
 {
     $versions = PluginMiniDocVersion::getInstance()->getDocConvertList(-1);
     echo "第二次转换文件有:" . count($versions) . "个\n";
     foreach ($versions as $version) {
         echo $version["file_signature"] . "\n";
     }
     PluginMiniDocVersion::getInstance()->pushConvert($versions);
 }
Ejemplo n.º 2
0
 /**
  *根据文件的Hash值下载内容
  *@param string $signature 文件hash值
  *@return array
  *
  */
 function pullText($signature)
 {
     $version = PluginMiniDocVersion::getInstance()->getBySignature($signature);
     if (isset($version)) {
         $mimeTypeList = array("text/plain", "text/html", "application/javascript", "text/css", "application/xml");
         foreach ($mimeTypeList as $mimeType) {
             if ($mimeType === $version["mime_type"]) {
                 PluginMiniSearchFile::getInstance()->create($signature);
                 return;
             }
         }
         $mimeTypeList = array("application/mspowerpoint", "application/msword", "application/msexcel", "application/pdf");
         foreach ($mimeTypeList as $mimeType) {
             if ($mimeType === $version["mime_type"]) {
                 //文档类增量转换
                 //doc/ppt/xls/pdf全文检索需要通过迷你文档拉取文本内容
                 PluginMiniSearchFile::getInstance()->create($signature);
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  *
  * 文件上传成功后,向迷你文档服务器发送文档转换请求
  * @param $data 文件sha1编码
  * @return bool
  */
 function fileUploadAfter($data)
 {
     $signature = $data["signature"];
     $fileName = $data["file_name"];
     $newMimeType = MiniUtil::getMimeType($fileName);
     $mimeTypeList = array("text/plain", "text/html", "application/javascript", "text/css", "application/xml");
     foreach ($mimeTypeList as $mimeType) {
         if ($mimeType === $newMimeType) {
             //文本类文件直接把内容存储到数据库中,便于全文检索
             do_action("pull_text_search", $signature);
             return;
         }
     }
     $mimeTypeList = array("application/mspowerpoint", "application/msword", "application/msexcel", "application/pdf");
     foreach ($mimeTypeList as $mimeType) {
         if ($mimeType === $newMimeType) {
             //文档类增量转换
             PluginMiniDocVersion::getInstance()->pushConvertSignature($signature, $newMimeType);
             break;
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * 获得迷你文档转换服务器节点
  * @param string $signature
  * @return string
  */
 public function getConvertNode($signature)
 {
     //寻找以前迷你文档节点
     $version = PluginMiniDocVersion::getInstance()->getBySignature($signature);
     if (!empty($version)) {
         $meta = MiniVersionMeta::getInstance()->getMeta($version["id"], "doc_id");
         if (!empty($meta)) {
             $nodeId = $meta["meta_value"];
             $node = $this->getNodeById($nodeId);
             if ($node["status"] == 1) {
                 return $node;
             }
         }
     }
     //返回随机converted_file_count最小的节点
     $nodes = $this->getNodeList();
     $validNodes = array();
     foreach ($nodes as $itemNode) {
         if ($itemNode["status"] == 1) {
             array_push($validNodes, $itemNode);
         }
     }
     //选出converted_file_count最小的个节点
     $validNodes = MiniUtil::arraySort($validNodes, "converted_file_count", SORT_ASC);
     $nodes = MiniUtil::getFistArray($validNodes, 1);
     if (count($nodes) > 0) {
         return $nodes[0];
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * 获得当前文档转换状态
  * 如状态为0,可能是老文件,以补偿形式开始转换
  * @param string $path 文件路径 
  */
 public function convertStatus($path)
 {
     $file = MiniFile::getInstance()->getByPath($path);
     $version = PluginMiniDocVersion::getInstance()->getVersion($file['version_id']);
     if ($version["doc_convert_status"] == 0) {
         PluginMiniDocVersion::getInstance()->pushConvertSignature($version["file_signature"], "");
     }
     return array('status' => $version['doc_convert_status']);
 }