Exemplo n.º 1
0
 /**
  * 查找该路径下所有子文件:文件存入数组
  * @param string $parent_file_id 父目录id
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function findAllChildrenFiles($parent_file_id, $user_nick, $from_path, $to_path, $file_array, $device_name, $file_size)
 {
     $query_db_files = MFiles::queryChildrenFilesByParentFileID($parent_file_id);
     if ($query_db_files === false) {
         return false;
     }
     foreach ($query_db_files as $key => $db_file) {
         if ($db_file["file_type"] != MConst::OBJECT_TYPE_FILE) {
             $file_array = $this->findAllChildrenFiles($db_file["id"], $user_nick, $from_path, $to_path, $file_array, $device_name, $file_size);
             continue;
         }
         //
         // 转换路径
         //
         $file_path = $db_file["file_path"];
         //
         // 文件存入数组
         //
         $file = new MFiles();
         $file->file_path = $file_path;
         $file->version_id = $db_file["version_id"];
         $meta_value = MUtils::getFileVersions($device_name, $db_file['file_size'], $file->version_id, MConst::CREATE_FILE, $db_file["user_id"], $user_nick);
         $file->meta_value = $meta_value;
         $file->is_add = true;
         // 记录是否需要添加
         $file_array[$file_path] = $file;
     }
     return $file_array;
 }
Exemplo n.º 2
0
 public function handlerChildrenFile($fileDetail)
 {
     $directories = array();
     // 记录这层中文件夹的对象
     $files = array();
     // 记录需要处理的文件对象(包括文件夹)
     //
     // 文件夹,查询其子文件这一层数据
     //
     $dbChildrenFiles = MFiles::queryChildrenFilesByParentFileID($fileDetail->from_id);
     if ($dbChildrenFiles === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     if (empty($dbChildrenFiles)) {
         $p = $fileDetail->file_path;
         return;
         // 没有子文件,返回
     }
     //
     // 检查文件数量,复制数量限制在10000条内
     //
     if (count($dbChildrenFiles) > MConst::MAX_FILES_COUNT) {
         throw new MFileopsException(Yii::t('api', 'Too many files or folders need to be copied'), MConst::HTTP_CODE_406);
     }
     //
     // 转换数据
     //
     foreach ($dbChildrenFiles as $dbFile) {
         $newFileDetail = new MFiles();
         //
         // 排除已被删除的对象
         //
         if ($dbFile["is_deleted"] == true) {
             continue;
         }
         $this->assembleFileDetail($dbFile['file_name'], $fileDetail->id, $newFileDetail, $dbFile);
         array_push($files, $newFileDetail);
         if ($dbFile["file_type"] == MConst::OBJECT_TYPE_DIRECTORY) {
             array_push($directories, $newFileDetail);
         }
     }
     if (empty($files)) {
         return;
     }
     //
     // 批量处理这批数据
     //
     $ret = MFiles::batchCreateFileDetails($this->_user_id, $files);
     if ($ret === false || empty($ret)) {
         throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
     }
     $this->updateVerRef($files);
     $ret = MiniEvent::getInstance()->createEvents($this->_user_id, $this->_user_device_id, $files, $this->to_share_filter->type);
     if ($ret === false || empty($ret)) {
         throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
     }
     //
     // 为共享创建事件
     //
     if ($this->to_share_filter->is_shared) {
         foreach ($files as $v) {
             $context = $v->context;
             if ($v->event_action == MConst::CREATE_FILE || $v->event_action == MConst::MODIFY_FILE) {
                 $context = unserialize($context);
             }
             $this->to_share_filter->handlerAction($v->event_action, $this->_user_device_id, $v->from_path, $context);
         }
     }
     //
     // 处理这层中的文件夹
     //
     foreach ($directories as $file) {
         //
         // 查询其复制目录路径id
         //
         $queryDbDirectory = MFiles::queryFilesByPath($file->file_path);
         if ($queryDbDirectory === false || empty($queryDbDirectory)) {
             throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
         }
         $file->id = $queryDbDirectory[0]["id"];
         $this->handlerChildrenFile($file);
     }
 }