Example #1
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);
     }
 }