Пример #1
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;
 }
Пример #2
0
 /**
  * 
  * 移动文件
  * @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);
 }
Пример #3
0
 /**
  *
  * 为共享用户创建文件夹信息
  *
  * @since 1.0.7
  */
 private function handlerCreateFolder($slaves = array(), $types = array())
 {
     $metas = array();
     foreach ($this->_slaves as $key => $slave) {
         // 表示改用户已经被共享
         if (isset($slaves[$slave]) || $this->_master == $slave) {
             continue;
         }
         if (!$this->handlerCheckSlave($slave, $this->_file['file_name'])) {
             $name = $this->handlerRename($this->_file['file_name'], $slave);
             $path = '/' . $slave . '/' . $name;
             $metas[$slave] = $path;
             //
             // 创建文件夹
             //
             $handler = new CreateFolder();
             $handler->_userId = $slave;
             $handler->_deviceId = $this->_deviceId;
             $handler->_action = 5;
             $file_id = $handler->handleCreateByPath($path);
             UserFile::model()->updateByPk($file_id, array('file_type' => 3));
         } else {
             $metas[$slave] = $path = '/' . $slave . '/' . $this->_file['file_name'];
         }
     }
     return $metas;
 }
Пример #4
0
 /**
  * 
  * 复制文件夹
  * @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);
     }
 }