Exemplo n.º 1
0
 /**
  * 处理删除子文件
  * @param int $user_id
  * @param string $parent_path  文件路径,传入路径中已经加入用户id:"/".$this->_user_id.$parent_path
  * @param array $files
  * @throws MFileopsException
  * @return mixed $value 返回最终需要执行完的结果
  * 
  * @since 1.0.7
  */
 private function handleChildrenFile($parent_path, $files)
 {
     //
     // 查询所有子文件, 不包含已删除的
     //
     $db_children_files = MFiles::queryChildrenFilesByPath($parent_path, true, false);
     if ($db_children_files === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     //
     // 检查文件数量,复制数量限制在10000条内
     //
     if (count($db_children_files) > MConst::MAX_FILES_COUNT) {
         throw new MFileopsException(Yii::t('api', 'Too many files or folders need to be deleted'), MConst::HTTP_CODE_406);
     }
     //
     // 转换数据
     //
     foreach ($db_children_files as $db_file) {
         $file_detail = new MFiles();
         //
         // 排除已被删除的对象
         //
         if ($db_file["is_deleted"] == true) {
             continue;
         }
         $this->assembleFileDetail($file_detail, $db_file);
         array_push($files, $file_detail);
         //
         // 处理共享文件夹
         //
         if ($db_file['file_type'] >= MConst::OBJECT_TYPE_SHARED) {
             $handler = new ShareManager();
             $handler->_userId = $db_file['user_id'];
             $handler->_id = $db_file['id'];
             try {
                 $handler->invoke(ShareManager::CANCEL_SHARED);
             } catch (Exception $e) {
                 continue;
             }
         }
     }
     //
     // 更新其为删除状态
     //
     $ret_value = MFiles::updateRemoveChildrenFile($parent_path);
     if ($ret_value === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     return $files;
 }