Esempio n. 1
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"];
 }
Esempio n. 2
0
 public function creatUserFile($fileDetail)
 {
     $file = new UserFile();
     $file["user_id"] = $fileDetail->user_id;
     $file["file_type"] = $fileDetail->file_type;
     $file["parent_file_id"] = $fileDetail->parent_file_id;
     $file["file_create_time"] = $fileDetail->file_create_time;
     $file["file_update_time"] = $fileDetail->file_update_time;
     $file["file_name"] = $fileDetail->file_name;
     $file["version_id"] = $fileDetail->version_id;
     $file["file_size"] = $fileDetail->file_size;
     $file["file_path"] = $fileDetail->file_path;
     $file["event_uuid"] = $fileDetail->event_uuid;
     $file->save();
 }
Esempio n. 3
0
 /**
  * 创建File对象
  * 这里使用了引用传值,确保event_uuid可传递到外面
  * @param array $file
  * @param int $userId
  * @return mixed
  */
 public function create(&$file, $userId)
 {
     if (!isset($file["version_id"])) {
         $file["version_id"] = 0;
     }
     $file["event_uuid"] = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
     $item = new UserFile();
     $item->user_id = $userId;
     $item->file_type = $file["file_type"];
     $item->parent_file_id = $file["parent_file_id"];
     $item->file_create_time = $file["file_create_time"];
     $item->file_update_time = $file["file_update_time"];
     $item->file_name = $file["file_name"];
     $item->version_id = $file["version_id"];
     $item->file_size = $file["file_size"];
     $item->file_path = $file["file_path"];
     $item->event_uuid = $file["event_uuid"];
     $item->mime_type = $file["mime_type"];
     //有存在NULL的情况
     $item->save();
     $file["id"] = $item->id;
     return $file;
 }
Esempio n. 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);
     }
 }