Exemplo n.º 1
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);
     }
 }