예제 #1
0
 /**
  *   获取events数据
  */
 public function getList($path, $time, $deviceUuid, $pageSize, $currentPage)
 {
     $user = $this->user;
     $userId = $user['id'];
     $time = $this->getTime($time);
     if ($path != "") {
         $path = MiniUtil::joinPath($path);
     }
     $total = MiniEvent::getInstance()->getTotal($path, $time, $userId, $deviceUuid);
     $totalPage = ceil($total / $pageSize);
     $events = MiniEvent::getInstance()->getByCondition($path, $userId, $time, $deviceUuid, $pageSize, ($currentPage - 1) * $pageSize);
     $itemList = array();
     $data = array();
     foreach ($events as $event) {
         $item = array();
         $device = MiniUserDevice::getInstance()->getUserDevice($event['user_device_id']);
         $item['create_user_id'] = $device['user_id'];
         $item['file_path'] = MiniUtil::getRelativePath($event['file_path']);
         $item['action'] = $event['action'];
         $item['user_name'] = $user['user_name'];
         $item['user_device_type'] = $device['user_device_type'];
         if ($device['user_id'] == $userId) {
             $item['user_self'] = true;
         } else {
             $item['user_self'] = false;
             $user = MiniUser::getInstance()->getById($device['user_id']);
             $userMetas = MiniUserMeta::getInstance()->getUserMetas($device['user_id']);
             if (isset($userMetas['nick'])) {
                 $item['user_name'] = $userMetas['nick'];
             } else {
                 $item['user_name'] = $user['user_name'];
             }
         }
         $item['created_at'] = MiniUtil::formatTime(strtotime($event['created_at']));
         $item['user_device_name'] = $device['user_device_name'];
         $item['context'] = MiniUtil::getRelativePath($event['context']);
         $item['device_uuid'] = $device['user_device_uuid'];
         if ($event['action'] == 2) {
             //判断是否是重命名还是创建
             $fromParent = CUtils::pathinfo_utf($event['file_path']);
             $toParent = CUtils::pathinfo_utf($event['context']);
             if ($fromParent['dirname'] == $toParent['dirname']) {
                 $item['action'] = MConst::RENAME;
             }
         }
         $itemList[] = $item;
     }
     $data['events'] = $itemList;
     $data['totalPage'] = $totalPage;
     return $data;
 }
예제 #2
0
 /**
  * 
  * 根据路径创建目录
  */
 public function handleCreateByPath($path)
 {
     if ($path == "/{$this->_userId}" || $path == "\\" || $path == "/{$this->_userId}/") {
         return 0;
     }
     $event_uuid = MiniUtil::getEventRandomString(46);
     $file = UserFile::model()->find(array('condition' => 'file_path=:file_path', 'params' => array(':file_path' => $path)));
     if (empty($file) || is_null($file)) {
         $pathInfo = CUtils::pathinfo_utf($path);
         $parenPath = $pathInfo["dirname"];
         $fileName = $pathInfo["basename"];
         $parentId = $this->handleCreateByPath($parenPath);
         $file = new UserFile();
         $file['user_id'] = $this->_userId;
         $file['file_type'] = 1;
         $file['parent_file_id'] = $parentId;
         $file['file_create_time'] = time();
         $file['file_update_time'] = time();
         $file['file_name'] = $fileName;
         $file['file_path'] = $path;
         $file['is_deleted'] = 0;
         $file['version_id'] = 0;
         $file['file_size'] = 0;
         $file["event_uuid"] = $event_uuid;
         $file->save();
         $file['sort'] = $file['id'];
         $file->save();
         // 创建事件
         MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $path, $path, $event_uuid, $this->share_filter->type);
         $this->share_filter->handlerAction($this->_action, $this->_deviceId, $path, $path);
     } else {
         //
         // 回收站插件: -1保留值 0正常 1删除
         // 这里由is_deleted==1 特别修改为 is_deleted!=0
         // By Kindac 2012/11/5
         //
         if ($file["is_deleted"] != 0) {
             $file["is_deleted"] = 0;
             $file["file_update_time"] = time();
             $file["event_uuid"] = $event_uuid;
             //
             // 递归创建父目录
             //
             $pathInfo = CUtils::pathinfo_utf($path);
             $parenPath = $pathInfo["dirname"];
             $this->handleCreateByPath($parenPath);
             $file->save();
             MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $path, $path, $event_uuid, $this->share_filter->type);
             $this->share_filter->handlerAction($this->_action, $this->_deviceId, $path, $path);
         }
     }
     return $file["id"];
 }
예제 #3
0
 /**
  * 还原回收站文件
  */
 public function revertFile($fileIds)
 {
     if ($fileIds === '' && strlen($fileIds) <= 0) {
         return 0;
     }
     $models = $this->findAll("id in(" . $fileIds . ")");
     $device_id = Yii::app()->session["deviceId"];
     foreach ($models as $model) {
         $share_filter = MSharesFilter::init();
         $user_id = $model['user_id'];
         $path = $model['file_path'];
         $context = $path;
         $share_filter->handlerCheckByFile($user_id, $model);
         // 确保父目录被还原
         $createFolder = new CreateFolder();
         $createFolder->_deviceId = $device_id;
         $createFolder->_userId = $user_id;
         $createFolder->share_filter = $share_filter;
         $pathInfo = CUtils::pathinfo_utf($path);
         try {
             $parentId = $createFolder->handleCreateByPath($pathInfo["dirname"]);
         } catch (ApiException $e) {
             Yii::log($e->getMessage());
             continue;
         }
         $event_uuid = MiniUtil::getEventRandomString(46);
         $action = 0;
         // 创建文件夹
         if ($model['file_type'] == 0) {
             //
             // 如果是文件,需要创建版本
             //
             $user = Yii::app()->session['user'];
             $device = UserDevice::model()->findByUserIdAndType($user['id'], CConst::DEVICE_WEB);
             $deviceName = $device["user_device_name"];
             $this->_saveFileMeta($path, $model['version_id'], $user['id'], $user['name'], CConst::WEB_RESTORE, $deviceName, $model['file_size']);
             $action = CConst::CREATE_FILE;
             $version = FileVersion::model()->findByPk((int) $model['version_id']);
             $context = array("hash" => $version['file_signature'], "rev" => (int) $model["version_id"], "bytes" => (int) $model["file_size"]);
             $context = serialize($context);
         }
         MiniEvent::getInstance()->createEvent($user_id, $device_id, $action, $path, $context, $event_uuid, $share_filter->type);
         $model['event_uuid'] = $event_uuid;
         $model['file_update_time'] = time();
         $model["is_deleted"] = 0;
         $model->save();
         $share_filter->handlerAction($action, $device_id, $path, unserialize($context));
     }
     return TRUE;
 }
예제 #4
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);
 }
예제 #5
0
 /**
  *
  * 获取一个本地的文件地址,如果是远程文件则先进行下载
  * @param unknown_type $path
  */
 function get_local_path($path)
 {
     $direct = new MFilesystemDirect();
     if ($this->isExistLocal()) {
         return $direct->localPath($path);
     }
     $from = $this->documentStorePath($path) . $path;
     $pathArray = CUtils::pathinfo_utf($path);
     $to = DOCUMENT_TEMP . $pathArray["filename"];
     $direct->touch($to);
     $this->getFileSystemObject()->get($from, $to, $resumepos = 0);
     return $to;
 }
예제 #6
0
파일: Move.php 프로젝트: youngsun45/miniyun
 /**
  * 
  * 移动文件
  * @param string $fromPath
  * @param string $toPath
  */
 private function handleMoveFile($fromPath, $toPath)
 {
     $createFolder = new CreateFolder();
     $createFolder->_deviceId = $this->to_share_filter->master;
     $createFolder->_userId = $this->_userId;
     $pathInfo = CUtils::pathinfo_utf($this->toPath);
     $parentId = $createFolder->handleCreateByPath($pathInfo["dirname"]);
     // 重命名
     $name = $this->handleRename($parentId, $pathInfo["basename"]);
     $this->toPath = $pathInfo["dirname"] . "/" . $name;
     //
     // 如果是存在同名的已经删除的记录,则删除之
     //
     $deleted = UserFile::model()->findByAttributes(array("user_id" => $this->_userId, "file_path" => $this->toPath, "is_deleted" => 1));
     if ($deleted) {
         $deleted->delete();
     }
     // 修改属性后 保存
     $this->from["file_path"] = $this->toPath;
     $this->from["file_name"] = $name;
     $this->from["event_uuid"] = MiniUtil::getEventRandomString(46);
     $this->from["parent_file_id"] = $parentId;
     $this->from["user_id"] = $this->to_share_filter->master;
     $this->from->save();
     // 更新meta
     $this->handleFileMeta($this->toPath, $this->from["version_id"], $this->_userId, $this->_userNick, CConst::CREATE_FILE, $this->_deviceName, $this->from['file_size']);
     // 创建事件
     MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $this->fromPath, $this->toPath, $this->from["event_uuid"]);
     $this->to_share_filter->handlerAction($this->_action, $this->_deviceId, $this->fromPath, $this->toPath);
 }
예제 #7
0
 /**
  * 检查是否在同一个共享目录下移动
  * @param integer $from_master
  * @param integer $to_master
  * @param string $from_path
  * @param string $to_path
  * @return boolean
  */
 public function handlerCheckMove($from_master, $to_master, $from_path, $to_path, $to_is_shared = FALSE)
 {
     if ($this->is_shared == false && $to_is_shared == false) {
         return false;
     }
     //
     // 在共享目录内部拷贝
     //
     $to = '/' . $to_master . $to_path;
     if (!empty($this->_shared_path) && strpos($to, $this->_shared_path . '/') === 0) {
         return false;
     }
     $from_parent = CUtils::pathinfo_utf($from_path);
     $to_parent = CUtils::pathinfo_utf($to_path);
     if ($from_master == $to_master && $to_parent['dirname'] == $from_parent['dirname']) {
         return false;
     }
     return true;
 }
예제 #8
0
파일: Copy.php 프로젝트: youngsun45/miniyun
 /**
  * 
  * 复制文件夹
  * @param string $fromPath
  * @param string $toPath
  */
 public function handleCopyFolder($fromPath, $toPath)
 {
     $createFolder = new CreateFolder();
     $createFolder->_deviceId = $this->_deviceId;
     $createFolder->_userId = $this->_userId;
     $createFolder->share_filter = $this->to_share_filter;
     $pathInfo = CUtils::pathinfo_utf($toPath);
     $parentId = $createFolder->handleCreateByPath($pathInfo["dirname"]);
     // 重命名
     $name = $this->handleRename($parentId, $pathInfo["basename"]);
     $this->toPath = $pathInfo["dirname"] . "/" . $name;
     //
     // 如果是存在同名的已经删除的记录,则还原之
     //
     $target = UserFile::model()->findByAttributes(array("user_id" => $this->_userId, "file_path" => $toPath, "is_deleted" => 1));
     if (!$target) {
         $target = new UserFile();
         $target["user_id"] = $this->_userId;
         $target["parent_file_id"] = $parentId;
         $target["file_create_time"] = time();
     }
     $target["file_type"] = 1;
     $target["is_deleted"] = 0;
     $target["version_id"] = $this->from["version_id"];
     $target["file_size"] = $this->from["file_size"];
     $target["file_path"] = $toPath;
     $target["file_name"] = $name;
     $target["file_update_time"] = time();
     $target["event_uuid"] = MiniUtil::getEventRandomString(46);
     $target->save();
     // 创建事件
     MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, 0, $toPath, $toPath, $target["event_uuid"]);
     $this->to_share_filter->handlerAction(0, $this->_deviceId, $toPath, $toPath);
     // copy 所有的文件,创建文件的时候会将父目录创建
     $handler = new UserFile();
     $children = $handler->getChildrenFileByPath($fromPath);
     foreach ($children as $child) {
         $this->from = $child;
         $childFromPath = $child["file_path"];
         $index = strlen($this->fromPath);
         $childtoPath = substr_replace($childFromPath, $this->toPath, 0, $index);
         $this->handleCopyFile($childFromPath, $childtoPath);
     }
     // copy 所有的文件夹,补偿没有子文件的 路径
     $folders = $handler->getChildrenFileByPath($fromPath, 1);
     $createFolder = new CreateFolder();
     $createFolder->_deviceId = $this->_deviceId;
     $createFolder->_userId = $this->_userId;
     $createFolder->share_filter = $this->to_share_filter;
     foreach ($folders as $folder) {
         $childFromPath = $folder["file_path"];
         $index = strlen($this->fromPath);
         $childtoPath = substr_replace($childFromPath, $this->toPath, 0, $index);
         $parentId = $createFolder->handleCreateByPath($childtoPath);
     }
 }