Example #1
0
 /**
  * 静态方法, 单例统一访问入口
  * @return object  返回对象的唯一实例
  */
 public static function getInstance()
 {
     if (is_null(self::$_instance) || !isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * 获取当前文件版本列表
  * @param $path
  * @return mixed
  */
 public function getList($path)
 {
     $item = explode("/", $path);
     $permissionArr = UserPermissionBiz::getInstance()->getPermission($path, $this->user['id']);
     if ($item[1] !== $this->user['id'] && count($permissionArr) == 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR), MConst::HTTP_CODE_400);
     }
     $file = MiniFile::getInstance()->getByPath($path);
     $version_id = $file['version_id'];
     $fileMeta = MiniFileMeta::getInstance()->getFileMeta($path, "version");
     $fileVersion = MiniVersion::getInstance()->getVersion($version_id);
     $currentSignature = $fileVersion['file_signature'];
     $historyArr = array_reverse(unserialize($fileMeta['meta_value']));
     // 去掉delete事件版本
     $histories = array();
     foreach ($historyArr as $item) {
         $history = array();
         if ($item['type'] == CConst::DELETE) {
             continue;
         }
         $history['type'] = $item['type'];
         $history['file_size'] = $item['file_size'];
         $history['user_nick'] = $item['user_nick'];
         $history['device_name'] = $item['device_name'];
         $history['datetime'] = MiniUtil::formatTime(strtotime($item['datetime']));
         $fileVersion = MiniVersion::getInstance()->getVersion($item['version_id']);
         $history['signature'] = $fileVersion['file_signature'];
         array_push($histories, $history);
     }
     $data['histories'] = $histories;
     $data['current_signature'] = $currentSignature;
     return $data;
 }
 /**
  * 获取用户全部的共享目录
  * @param integer $userId
  * @return array
  */
 public function handleGetAllSharesFolder($userId)
 {
     $files = MiniFile::getInstance()->getShares($userId);
     $paths = array();
     foreach ($files as $file) {
         $fileMeta = MiniFileMeta::getInstance()->getFileMeta($file['file_path'], 'shared_folders');
         if ($fileMeta === NULL) {
             continue;
         }
         $metaValue = unserialize($fileMeta['meta_value']);
         array_push($paths, $metaValue['path']);
         array_push($paths, $file['file_path']);
     }
     return $paths;
 }
 /**
  * 判断目录是否可发起共享
  * 递归查询父目录file_type情况,file_type=1时返回false,file_type==2||3时返回true
  */
 public function getFolderPrivilege($currentUserId, $file)
 {
     $fileType = intval($file['file_type']);
     //被共享目录本身可以修改和删除
     $privilege = array('resource.read' => 1, 'folder.create' => 1, 'folder.rename' => 1, 'folder.delete' => 1, 'file.create' => 1, 'file.modify' => 1, 'file.rename' => 1, 'file.delete' => 1, 'permission.grant' => 1, 'can_set_share' => 1);
     if ($fileType === 3) {
         $fileMeta = MiniFileMeta::getInstance()->getFileMeta($file['file_path'], MConst::SHARED_FOLDERS);
         $metaValue = unserialize($fileMeta['meta_value']);
         $masterPath = $metaValue['path'];
         $item = $this->getSpecifyPrivilege($currentUserId, $masterPath);
         $privilege = unserialize($item['permission']);
         //被共享着不能发起共享
         $privilege["folder.delete"] = 1;
         $privilege["can_set_share"] = 0;
     }
     if ($fileType === 1) {
         //判断下级目录是否有共享目录
         $filePath = $file['file_path'];
         $key = MConst::SHARED_FOLDERS;
         $childrenMeta = MiniFileMeta::getInstance()->getChildrenFileMetaByPath($filePath, $key);
         if (!empty($childrenMeta)) {
             //子目录已经共享则不能二次共享
             $privilege["can_set_share"] = 0;
         } else {
             //判断上级目录是否有共享目录,获得父目录权限
             $arr = explode('/', $filePath);
             $userId = $file['user_id'];
             $parentPath = "/" . $userId;
             for ($i = 2; $i < count($arr); $i++) {
                 $parentPath = $parentPath . "/" . $arr[$i];
                 $fileMeta = MiniFileMeta::getInstance()->getFileMeta($parentPath, MConst::SHARED_FOLDERS);
                 if (!empty($fileMeta)) {
                     $metaValue = unserialize($fileMeta['meta_value']);
                     $masterPath = $metaValue['path'];
                     $item = $this->getSpecifyPrivilege($currentUserId, $masterPath);
                     if (!empty($item)) {
                         //权限列表只有被共享目录的信息,所以必须判断(非空则为被共享目录)
                         $privilege = unserialize($item['permission']);
                     } else {
                         $privilege = array('resource.read' => 1, 'folder.create' => 1, 'folder.rename' => 1, 'folder.delete' => 1, 'file.create' => 1, 'file.modify' => 1, 'file.rename' => 1, 'file.delete' => 1, 'permission.grant' => 1);
                     }
                     $privilege["can_set_share"] = 0;
                     break;
                 }
             }
         }
     }
     return $privilege;
 }
Example #5
0
 /**
  * 由外部控制文件输出类型
  * @param string $path
  * @param string $signature
  * @throws MFilesException
  * @return string
  */
 public function getTxtContent($path, $signature)
 {
     $file = $this->getByPath($path);
     $version = MiniVersion::getInstance()->getVersion($file["version_id"]);
     $hasPrivilege = false;
     $fileMeta = MiniFileMeta::getInstance()->getFileMeta($path, 'version');
     $versions = unserialize($fileMeta['meta_value']);
     if (isset($fileMeta)) {
         foreach ($versions as $item) {
             if (intval($item['version_id']) === intval($version['id'])) {
                 $hasPrivilege = true;
                 break;
             }
         }
     }
     if ($hasPrivilege) {
         //检测是否是历史版本浏览
         if (empty($signature)) {
             $signature = $version["file_signature"];
         }
         return $this->getText($signature);
     }
     return null;
 }
Example #6
0
 /**
  * 取消共享,删除权限
  */
 public function delete($filePath)
 {
     $arr = explode('/', $filePath);
     $isRoot = false;
     $isMine = false;
     if (count($arr) == 3) {
         $isRoot = true;
     }
     $fileOwnerId = $arr[1];
     $currentUser = $this->user;
     $currentUserId = $currentUser['user_id'];
     if ($fileOwnerId == $currentUserId) {
         $isMine = true;
     }
     if ($isRoot && !$isMine) {
         //如果是在根目录下且不是自己的目录 则后台控制不准取消共享
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_409);
     }
     $this->share_filter = MSharesFilter::init();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $userDeviceId = $device["device_id"];
     $this->share_filter->slaves = $this->getSlaveIdsByPath($filePath);
     MiniUserPrivilege::getInstance()->deleteByFilePath($filePath);
     MiniGroupPrivilege::getInstance()->deleteByFilePath($filePath);
     MiniFile::getInstance()->cancelPublic($filePath);
     $eventAction = MConst::CANCEL_SHARED;
     MiniEvent::getInstance()->createEvent($this->user['id'], $userDeviceId, $eventAction, $filePath, $filePath, MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID), $this->share_filter->type);
     $this->share_filter->is_shared = true;
     //把共享目录下的共享目录设置记录删除
     MiniFileMeta::getInstance()->deleteFileMetaByPath($filePath, "share_model");
     // 为每个共享用户创建事件
     $this->share_filter->handlerAction($eventAction, $userDeviceId, $filePath, $filePath);
     return true;
 }
Example #7
0
 /**
  * 控制器执行主逻辑函数, 处理移动文件或者文件夹
  *
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $this->setAction(MConst::MOVE);
     $params = $_REQUEST;
     // 检查参数
     if (isset($params) === false) {
         throw new MException(Yii::t('api', 'Bad Request 7'));
     }
     //
     // 获取用户数据,如user_id
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $this->_userId = $user["user_id"];
     $this->master = $user["user_id"];
     $user_nick = $user["user_name"];
     $user_device_id = $device["device_id"];
     $this->_user_device_name = $device["user_device_name"];
     // 文件大小格式化参数
     $this->_locale = "bytes";
     if (isset($params["locale"])) {
         $this->_locale = $params["locale"];
     }
     if (isset($params["root"]) === false || isset($params["from_path"]) === false || isset($params["to_path"]) === false) {
         throw new MFileopsException(Yii::t('api', 'Bad Request'), MConst::HTTP_CODE_400);
     }
     $this->_root = $params["root"];
     $from_path = $params["from_path"];
     $to_path = $params["to_path"];
     $arr = explode('/', $from_path);
     $isRoot = false;
     $isMine = false;
     if (count($arr) == 3) {
         $isRoot = true;
     }
     $fileOwnerId = $arr[1];
     $currentUserId = $this->_userId;
     if ($fileOwnerId == $currentUserId) {
         $isMine = true;
     }
     if ($isRoot && !$isMine) {
         //如果是在根目录下且不是自己的目录 则后台控制不准取消共享
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_409);
     }
     $to_parts = explode('/', $to_path);
     $from_parts = explode('/', $from_path);
     if (count($to_parts) == 2) {
         $to_path = '/' . $this->_userId . $to_path;
     }
     $to_parts = explode('/', $to_path);
     $file = MiniFile::getInstance()->getByPath($from_path);
     $isSelfFile = false;
     if (!empty($file) && $file['user_id'] == $this->_userId) {
         $isSelfFile = true;
     }
     // 转换路径分隔符,便于以后跨平台,如:将 "\"=>"/"
     $from_path = MUtils::convertStandardPath($from_path);
     $to_path = MUtils::convertStandardPath($to_path);
     if ($to_path[strlen($to_path) - 1] == "/") {
         // 目标文件无效,403 error
         throw new MFileopsException(Yii::t('api', 'The file or folder name is invalid'), MConst::HTTP_CODE_403);
     }
     // 检查共享
     $this->from_share_filter = MSharesFilter::init();
     $this->to_share_filter = MSharesFilter::init();
     $isSharedPath = true;
     $this->rename = false;
     // 检查移动方式
     if ($this->rename == true) {
         // 先copy再删除,如果是移动共享文件夹则只copy,再执行shareManager取消共享
         $copy_handler = new MCopyController();
         $copy_handler->isOutput = false;
         $response = $copy_handler->invoke();
         $_REQUEST['path'] = $params["from_path"];
         $delete_handler = new MDeleteController();
         $delete_handler->isOutput = false;
         $delete_handler->completely_remove = true;
         $delete_handler->invoke();
         if (MUserManager::getInstance()->isWeb() === true) {
             $this->buildWebResponse();
             exit;
             return;
         }
         echo json_encode($response);
         return;
     }
     $file_name = MUtils::get_basename($to_path);
     // 检查文件名是否有效
     $is_invalid = MUtils::checkNameInvalid($file_name);
     if ($is_invalid) {
         throw new MFileopsException(Yii::t('api', 'The file or folder name is invalid'), MConst::HTTP_CODE_400);
     }
     // 检查是否移动到其子目录下
     if (strpos($to_path, $from_path . "/") === 0) {
         throw new MFileopsException(Yii::t('api', 'Can not be moved to the subdirectory'), MConst::HTTP_CODE_403);
     }
     if ($to_path == "/{$this->_userId}" || $to_path == "/{$this->_userId}/") {
         throw new MFileopsException(Yii::t('api', 'Can not be moved to the error directory'), MConst::HTTP_CODE_403);
     }
     $from_parent = CUtils::pathinfo_utf($from_path);
     $to_parent = CUtils::pathinfo_utf($to_path);
     $privilegeModel = new PrivilegeBiz();
     if (!(count($to_parts) == 3)) {
         $isSharedPath = false;
         $toPathArr = explode('/', $to_path);
         $masterId = $toPathArr[1];
         if ($masterId != $this->_userId) {
             $isSharedPath = true;
         } else {
             $model = new GeneralFolderPermissionBiz($to_parent['dirname']);
             if ($model->isParentShared($to_parent['dirname'])) {
                 //如果是父目录被共享
                 $isSharedPath = true;
             }
         }
         if ($isSharedPath) {
             $toPrivilege = UserPermissionBiz::getInstance()->getPermission($to_parent['dirname'], $this->_userId);
             if (empty($toPrivilege)) {
                 $toPrivilege['permission'] = MConst::SUPREME_PERMISSION;
             } else {
                 $this->to_share_filter->slaves = $privilegeModel->getSlaveIdsByPath($toPrivilege['share_root_path']);
                 $this->to_share_filter->is_shared = true;
             }
         } else {
             $toPrivilege['permission'] = MConst::SUPREME_PERMISSION;
         }
         $toFilter = new MiniPermission($toPrivilege['permission']);
     } else {
         if ($to_parent['dirname'] == $from_parent['dirname']) {
             $isSharedPath = false;
             $fromPathArr = explode('/', $from_path);
             $masterId = $fromPathArr[1];
             if ($masterId != $this->_userId) {
                 $isSharedPath = true;
             } else {
                 $model = new GeneralFolderPermissionBiz($from_path);
                 if ($model->isParentShared($from_path)) {
                     //如果是父目录被共享
                     $isSharedPath = true;
                 }
             }
             if ($isSharedPath) {
                 $toPrivilege = UserPermissionBiz::getInstance()->getPermission($from_path, $this->_userId);
                 if (!empty($toPrivilege)) {
                     $this->to_share_filter->slaves = $privilegeModel->getSlaveIdsByPath($toPrivilege['share_root_path']);
                     $this->to_share_filter->is_shared = true;
                 } else {
                     $toPrivilege['permission'] = MConst::SUPREME_PERMISSION;
                 }
             } else {
                 $toPrivilege['permission'] = MConst::SUPREME_PERMISSION;
             }
         }
         $toFilter = new MiniPermission(MConst::SUPREME_PERMISSION);
     }
     $isSharedPath = false;
     $fromPathArr = explode('/', $from_path);
     $masterId = $fromPathArr[1];
     if ($masterId != $this->_userId) {
         $isSharedPath = true;
     } else {
         $model = new GeneralFolderPermissionBiz($from_path);
         if ($model->isParentShared($from_path)) {
             //如果是父目录被共享
             $isSharedPath = true;
         }
     }
     if ($isSharedPath) {
         $fromPrivilege = UserPermissionBiz::getInstance()->getPermission($from_path, $this->_userId);
         if (empty($fromPrivilege)) {
             $fromPrivilege['permission'] = MConst::SUPREME_PERMISSION;
         } else {
             $this->from_share_filter->slaves = $privilegeModel->getSlaveIdsByPath($fromPrivilege['share_root_path']);
             $this->from_share_filter->is_shared = true;
         }
     } else {
         $fromPrivilege['permission'] = MConst::SUPREME_PERMISSION;
     }
     $fromFilter = new MiniPermission($fromPrivilege['permission']);
     if ($to_parent['dirname'] == $from_parent['dirname']) {
         $this->setAction(MConst::RENAME);
         $this->isRename = true;
         $canRenameFile = $fromFilter->canModifyFileName();
         $canRenameFolder = $fromFilter->canModifyFolderName();
         $canRenameFile2 = $toFilter->canModifyFileName();
         $canRenameFolder2 = $toFilter->canModifyFolderName();
         if ($file['file_type'] > 0 && !$canRenameFolder && !$isSelfFile) {
             //如果目标是目录,则当其不为己文件,且无更名权限时 exception
             throw new MFileopsException(Yii::t('api', 'have no permission to rename folder'), MConst::HTTP_CODE_409);
         }
         if ($file['file_type'] == 0 && !$canRenameFile && !$isSelfFile) {
             //如果目标是文件,则当其不为己文件,且无更名权限时 exception
             throw new MFileopsException(Yii::t('api', 'have no permission to rename file'), MConst::HTTP_CODE_409);
         }
         if ($file['file_type'] > 0 && !$canRenameFolder2 && !$isSelfFile) {
             //如果目标是目录,则当其不为己文件,且无更名权限时 exception
             throw new MFileopsException(Yii::t('api', 'have no permission to rename folder'), MConst::HTTP_CODE_409);
         }
         if ($file['file_type'] == 0 && !$canRenameFile2 && !$isSelfFile) {
             //如果目标是文件,则当其不为己文件,且无更名权限时 exception
             throw new MFileopsException(Yii::t('api', 'have no permission to rename file'), MConst::HTTP_CODE_409);
         }
     } else {
         $canDeleteFile = $fromFilter->canDeleteFile();
         $canDeleteFile2 = $toFilter->canDeleteFile();
         if (!$canDeleteFile || !$canDeleteFile2) {
             throw new MFileopsException(Yii::t('api', 'have no permission to move file'), MConst::HTTP_CODE_409);
         }
     }
     // 先检查源目录是否存在,如果不存在抛出404错误
     //
     $query_db_file = MFiles::queryFilesByPath($from_path);
     if ($query_db_file === false || empty($query_db_file)) {
         throw new MFileopsException(Yii::t('api', 'The source file was not found at the specified path'), MConst::HTTP_CODE_404);
     }
     //
     // 检查目标是否存在(包括已被删除的状态)
     //
     $deleted = null;
     $query_db_goal_file = MFiles::queryAllFilesByPath($to_path);
     if ($query_db_goal_file) {
         if ($from_path !== $to_path && $query_db_goal_file[0]["is_deleted"] == false) {
             throw new MFileopsException(Yii::t('api', 'There is already a item at the given destination'), MConst::HTTP_CODE_403);
         }
         // 已删除文件的处理
         if ($query_db_goal_file[0]["is_deleted"] == 1) {
             MFiles::deleteById($query_db_goal_file[0]["id"]);
             if ($query_db_goal_file[0]["file_type"] != 0) {
                 // 文件则直接删除
                 $deleted = $query_db_goal_file[0]["id"];
             }
         }
     }
     $query_db_file = MFiles::queryFilesByPath($from_path);
     if ($query_db_file === false || empty($query_db_file)) {
         throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
     }
     //
     // 检查移动原路径与目标路径是否一致,一致则则返回其文件信息
     //
     if ($from_path === $to_path) {
         $this->buildResult($query_db_file[0]);
         return;
     }
     //
     // 查询目标路径父目录信息
     //
     $pathInfo = MUtils::pathinfo_utf($to_path);
     $parent_path = $pathInfo["dirname"];
     $create_folder = new MCreateFolderController();
     $create_folder->_user_device_id = $user_device_id;
     $create_folder->_user_id = $this->_userId;
     if (count(explode('/', $parent_path)) == 2) {
         $parent_file_id = 0;
     } else {
         $parent_file_id = $create_folder->handlerParentFolder($parent_path);
     }
     $fromUserId = $from_parts[1];
     $toUserId = $to_parts[1];
     //
     // 组装对象信息
     //
     $file_detail = new MFiles();
     $file_detail->file_name = $file_name;
     $file_detail->file_path = $to_path;
     $file_detail->file_type = $query_db_file[0]["file_type"];
     $file_detail->id = $query_db_file[0]["id"];
     $file_detail->from_path = $from_path;
     $file_detail->parent_file_id = $parent_file_id;
     $file_detail->user_id = $toUserId;
     $file_detail->mime_type = NULL;
     $create_array = array();
     //
     // 判断操作的是文件夹,还是文件
     //
     if ($file_detail->file_type > MConst::OBJECT_TYPE_FILE) {
         if ($file['user_id'] != $this->_userId) {
             $updateUserId = $query_db_file[0]["user_id"];
         } else {
             $updateUserId = $this->master;
         }
         //
         // 文件夹,将会对其子文件做进一步处理
         //
         $ret_value = MFiles::updateMoveChildrenFileDetail($updateUserId, $file_detail);
         if ($ret_value === false) {
             throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
         }
         //
         // 针对文件夹下的文件,组装需要添加版本信息的文件
         //
         $create_array = $this->handleChildrenVersions($create_array, $this->_userId, $user_nick, $from_path, $to_path, $query_db_file[0]["id"], $this->_user_device_name, $query_db_file[0]["file_size"]);
     } else {
         $file_detail->mime_type = MiniUtil::getMimeType($file_name);
         $file_meta = new MFileMetas();
         $file_meta->version_id = $query_db_file[0]["version_id"];
         //
         // 查询之前是否包含其版本
         //
         $file_version = MFileMetas::queryFileMeta($to_path, MConst::VERSION);
         if ($file_version) {
             $meta_value = MUtils::getFileVersions($this->_user_device_name, $query_db_file[0]['file_size'], $file_meta->version_id, MConst::CREATE_FILE, $this->_userId, $user_nick, $file_version[0]["meta_value"]);
             $file_meta->is_add = false;
         } else {
             $meta_value = MUtils::getFileVersions($this->_user_device_name, $query_db_file[0]['file_size'], $file_meta->version_id, MConst::CREATE_FILE, $this->_userId, $user_nick);
             $file_meta->is_add = true;
         }
         $file_meta->meta_value = $meta_value;
         $file_meta->file_path = $to_path;
         $create_array[$to_path] = $file_meta;
         //
         // 添加到需要更新的版本ref
         //
         array_push($this->versions, $file_meta->version_id);
     }
     if ($file['file_type'] == 2 || $file['file_type'] == 4) {
         MiniUserPrivilege::getInstance()->updateByPath($from_path, $to_path);
         MiniGroupPrivilege::getInstance()->updateByPath($from_path, $to_path);
         if ($to_parent['dirname'] != $from_parent['dirname']) {
             MiniUserPrivilege::getInstance()->deleteByFilePath($to_path);
             MiniGroupPrivilege::getInstance()->deleteByFilePath($to_path);
         }
     }
     //
     // 创建版本信息
     //
     $ret = MFileMetas::batchCreateFileMetas($create_array, MConst::VERSION);
     //        if ($ret === false)
     //        {
     //            throw new MFileopsException(
     //            Yii::t('api','Internal Server Error'),
     //            MConst::HTTP_CODE_500);
     //        }
     //
     // 更新版本
     //
     foreach ($create_array as $file_meta) {
         if ($file_meta->is_add === true) {
             // 不存在记录,不需要更新
             continue;
         }
         MFileMetas::updateFileMeta($file_meta->file_path, MConst::VERSION, $file_meta->meta_value);
     }
     //
     // 更新版本引用次数
     //
     foreach ($this->versions as $vid) {
         MiniVersion::getInstance()->updateRefCount($vid);
     }
     //
     // 更新该对象元数据
     //
     $file_detail->event_uuid = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
     $ret_value = MFiles::updateMoveFileDetail($file_detail);
     // 移动目录 or 文件
     if ($ret_value === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     $updates = array();
     if ($file['file_type'] == 2 || $file['file_type'] == 4) {
         if ($to_parent['dirname'] != $from_parent['dirname']) {
             $updates['file_type'] = 1;
             $updates['user_id'] = $this->_userId;
         }
     }
     if ($fromUserId != $toUserId) {
         $updates['user_id'] = $toUserId;
     }
     MiniFile::getInstance()->updateByPath($to_path, $updates);
     //被共享者更改文件名更新file_meta记录
     MiniFileMeta::getInstance()->modifyFilePath($from_path, 'create_id', $to_path, $file['file_type']);
     //
     // 保存移动事件
     // by Kindac;
     //
     $event_action = $this->getGroupMove($file_detail->from_path, $file_detail->file_path);
     $ret_value = MiniEvent::getInstance()->createEvent($this->_userId, $user_device_id, $event_action, $file_detail->from_path, $file_detail->file_path, $file_detail->event_uuid, $this->to_share_filter->type);
     if ($ret_value === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     if ($file['type'] != 0) {
         $eventAction = MConst::CREATE_DIRECTORY;
     } else {
         $eventAction = MConst::CREATE_FILE;
     }
     if ($to_parent['dirname'] == $from_parent['dirname']) {
         $this->to_share_filter->handlerAction($event_action, $user_device_id, $file_detail->from_path, $file_detail->file_path);
     } else {
         if ($this->to_share_filter->is_shared) {
             $this->to_share_filter->handlerAction($eventAction, $user_device_id, $file_detail->file_path, $file_detail->file_path);
         }
         if ($this->from_share_filter->is_shared) {
             $this->from_share_filter->handlerAction(MConst::DELETE, $user_device_id, $file_detail->from_path, $file_detail->from_path);
         }
     }
     $query_db_file[0]["file_path"] = $file_detail->file_path;
     $query_db_file[0]["event_uuid"] = $file_detail->event_uuid;
     if (!empty($deleted)) {
         MFiles::updateParentId($deleted, $file_detail->id);
     }
     //进行扩展操作
     $this->extend($from_path, $to_path);
     //执行完删除操作后执行的额外事物
     $after = new MMoveAfter();
     $after->action = self::$scene;
     //        $after->from_share_filter = $from_share_filter;
     $after->to_share_filter = $this->to_share_filter;
     $after->from_path = $from_path;
     $after->to_path = $to_path;
     $after->file_detail = $file_detail;
     $after->execute();
     $this->buildResult($query_db_file[0], $to_path);
 }
Example #8
0
 /**
  * 根据path检查是否属于共享
  * @param integer $userId
  * @param string $path        -  不含user_id的路径
  */
 public function handlerCheck($userId, $path, $action = false)
 {
     $this->is_shared = false;
     $this->operator = $userId;
     $this->master = $userId;
     $this->src_path = $path;
     $this->_path = $path;
     $parts = explode('/', $path);
     // 去掉空值
     $parts = array_filter($parts);
     // 组装路径
     $paths = array();
     for ($i = 0; $i < count($parts); $i++) {
         $tarray = array_slice($parts, 0, $i + 1);
         $tmp = join('/', $tarray);
         $paths['/' . $userId . '/' . $tmp] = $tmp;
     }
     //根据用户查询属于用户的共享
     $files = MiniFile::getInstance()->getShares($userId);
     $sharedPath = '';
     foreach ($files as $file) {
         //表示这是共享目录
         if (isset($paths[$file['file_path']])) {
             $sharedPath = $file['file_path'];
             break;
         }
     }
     if ($sharedPath == '') {
         return false;
     }
     $file_meta = MiniFileMeta::getInstance()->getFileMeta($sharedPath, "shared_folders");
     if ($file_meta === NULL) {
         return $this->is_shared;
     }
     $meta_value = unserialize($file_meta['meta_value']);
     $this->master = $meta_value['master'];
     $this->slaves = $meta_value['slaves'];
     // 共享者的共享目录path
     $this->_shared_path = $meta_value['path'];
     $path = '/' . $this->operator . $path;
     $this->_path = substr_replace($path, $this->_shared_path, 0, strlen($sharedPath));
     $this->_path = substr_replace($this->_path, '', 0, strlen('/' . $this->master));
     // 如果这两个地址相同,则表示是共享目录本身的操作
     if ($this->_shared_path == '/' . $this->master . $this->_path) {
         $this->_is_shared_path = true;
     }
     // 判断用户是否对共享文件夹下面的文件拥有权限
     $this->hasPermission($this->_shared_path, $action);
     $this->file_type = $file['file_type'];
     $muser = User::model()->findByPk($this->master);
     if (!$muser) {
         throw new Exception(Yii::t('api', 'Internal Server Error'), '500');
     }
     $this->master_nick = $muser['user_name'];
     $this->is_shared = true;
     return $this->is_shared;
 }
Example #9
0
 /**
  * @param $filePath
  * @return mixed
  */
 public function delete($filePath)
 {
     $fileMeta = MiniFileMeta::getInstance()->getFileMeta($filePath, 'lock');
     $items = array();
     $userId = $this->user['id'];
     $metaValues = unserialize($fileMeta['meta_value']);
     foreach ($metaValues as $metaValue) {
         if ($metaValue['user_id'] == $userId) {
             continue;
         }
         $items[] = $metaValue;
     }
     if (count($items) == 0) {
         return MiniFileMeta::getInstance()->deleteFileMetaByPath($filePath, "lock");
     }
     return MiniFileMeta::getInstance()->updateFileMeta($filePath, 'lock', serialize($items));
 }
 /**
  * 处理非根目录下文件查询
  * @param $path
  * @param $includeDeleted
  * @return array
  * @throws MFileopsException
  */
 private function handleNotRootPath($path, $includeDeleted)
 {
     // 查询其是否存在信息
     $currentFile = MiniFile::getInstance()->getByPath($path);
     if (empty($currentFile)) {
         throw new MFileopsException(Yii::t('api', 'not existed'), MConst::HTTP_CODE_404);
     }
     //查询文件类型
     $version = MiniVersion::getInstance()->getVersion($currentFile["version_id"]);
     $mimeType = null;
     if ($version != NULL) {
         $currentFile["signature"] = $version["file_signature"];
         $mimeType = $version["mime_type"];
     }
     $response = array();
     $shareKeyPrivilege = MiniFile::getInstance()->getFileExtendProperty($currentFile);
     $response['share_key'] = $shareKeyPrivilege['share_key'];
     $response = $this->assembleResponse($response, $currentFile, $mimeType);
     // 组装子文件数据
     $childrenFiles = MiniFile::getInstance()->getChildrenByFileID($parentFileId = $currentFile['id'], $includeDeleted);
     $contents = array();
     if (!empty($childrenFiles)) {
         foreach ($childrenFiles as $childrenFile) {
             $childrenFileMeta = MiniFileMeta::getInstance()->getFileMeta($childrenFile['file_path'], 'create_id');
             if (!empty($childrenFileMeta)) {
                 $filePathArr = explode('/', $childrenFile['file_path']);
                 $fileOwnerId = $filePathArr[1];
                 $childrenFileCreateId = $childrenFileMeta['meta_value'];
                 $currentUser = Yii::app()->session["user"];
                 if ((int) $fileOwnerId !== (int) $currentUser['user_id']) {
                     //当前目录不为当前用户所有(共享目录/公共目录)
                     if ($response['share']['permission'] === '000000000') {
                         continue;
                     }
                     $readPrivilege = substr($response['share']['permission'], 0, 1);
                     if ($readPrivilege === '0') {
                         //如果父目录没有只读权限
                         if ($childrenFileCreateId != $currentUser['user_id']) {
                             //当没有只读权限时,过滤(用户只能看见共享目录中自己的文件)
                             continue;
                         }
                     }
                 }
             }
             $content = array();
             $version = MiniVersion::getInstance()->getVersion($childrenFile["version_id"]);
             $mimeType = null;
             if ($version != NULL) {
                 $mimeType = $version["mime_type"];
                 $childrenFile["signature"] = $version["file_signature"];
             }
             $content = $this->assembleResponse($content, $childrenFile, $mimeType);
             if (!empty($content) && $childrenFile['is_deleted'] == 0) {
                 array_push($contents, $content);
             }
         }
     }
     $response['contents'] = $contents;
     return $response;
 }