Exemplo n.º 1
0
 /**
  * 删除用户共享数据
  * @since 1.0.6
  * @param integer $userId
  */
 public function deleteSharedFolders($userId)
 {
     //
     // 删除共享文件
     //
     $shares = $this->findAll('user_id=:user_id and file_type > 1', array(':user_id' => $userId));
     foreach ($shares as $file) {
         $handler = new ShareManager();
         $handler->_userId = $file['user_id'];
         $handler->_id = $file['id'];
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             continue;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 处理删除子文件
  * @param int $user_id
  * @param string $parent_path  文件路径,传入路径中已经加入用户id:"/".$this->_user_id.$parent_path
  * @param array $files
  * @throws MFileopsException
  * @return mixed $value 返回最终需要执行完的结果
  * 
  * @since 1.0.7
  */
 private function handleChildrenFile($parent_path, $files)
 {
     //
     // 查询所有子文件, 不包含已删除的
     //
     $db_children_files = MFiles::queryChildrenFilesByPath($parent_path, true, false);
     if ($db_children_files === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     //
     // 检查文件数量,复制数量限制在10000条内
     //
     if (count($db_children_files) > MConst::MAX_FILES_COUNT) {
         throw new MFileopsException(Yii::t('api', 'Too many files or folders need to be deleted'), MConst::HTTP_CODE_406);
     }
     //
     // 转换数据
     //
     foreach ($db_children_files as $db_file) {
         $file_detail = new MFiles();
         //
         // 排除已被删除的对象
         //
         if ($db_file["is_deleted"] == true) {
             continue;
         }
         $this->assembleFileDetail($file_detail, $db_file);
         array_push($files, $file_detail);
         //
         // 处理共享文件夹
         //
         if ($db_file['file_type'] >= MConst::OBJECT_TYPE_SHARED) {
             $handler = new ShareManager();
             $handler->_userId = $db_file['user_id'];
             $handler->_id = $db_file['id'];
             try {
                 $handler->invoke(ShareManager::CANCEL_SHARED);
             } catch (Exception $e) {
                 continue;
             }
         }
     }
     //
     // 更新其为删除状态
     //
     $ret_value = MFiles::updateRemoveChildrenFile($parent_path);
     if ($ret_value === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     return $files;
 }
Exemplo n.º 3
0
 /**
  * 
  * 执行文件夹删除
  * @param UserFile $file
  */
 public function delete($parenFile)
 {
     $share_filter = MSharesFilter::init();
     $share_filter->handlerCheckByFile($this->_userId, $parenFile);
     //
     // 取消共享
     //
     if ($parenFile['file_type'] == 2 && $parenFile['user_id'] != $this->_userId || $parenFile['file_type'] == 3) {
         $parenFile = UserFile::model()->findByAttributes(array('file_path' => $share_filter->slaves[$this->_userId], 'is_deleted' => 0));
         if (!$parenFile) {
             throw new ApiException("Not found");
         }
         $handler = new ShareManager();
         $handler->_userId = $share_filter->operator;
         $handler->_id = $parenFile["id"];
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             throw new ApiException("Not found");
         }
         return;
     }
     // 更新每个元素以及子元素
     $parentPath = $parenFile["file_path"];
     $handler = new UserFile();
     $files = $handler->getFilesByPath($parentPath);
     // 轮询删除
     foreach ($files as $file) {
         if ($file["is_deleted"]) {
             continue;
         }
         // 已经删除的文件不做操作
         $file["event_uuid"] = MiniUtil::getEventRandomString(46);
         if ($file["file_type"] == 0) {
             if ($file["is_deleted"]) {
                 continue;
             }
             // 已经删除的文件不做操作
             $file["is_deleted"] = 1;
             $file->save();
             // 创建版本信息
             $this->handleFileMeta($file["file_path"], $file["version_id"], $file['user_id'], $this->_userNick, $this->_deviceName, $file['file_size']);
             // 创建事件
             MiniEvent::getInstance()->createEvent($file['user_id'], $this->_deviceId, $this->_action, $file["file_path"], $file["file_path"], $file["event_uuid"]);
             $share_filter->handlerAction($this->_action, $this->_deviceId, $file["file_path"], $file["file_path"]);
             continue;
         }
         $this->delete($file);
         $file["is_deleted"] = 1;
         $file->save();
         // 创建事件
         MiniEvent::getInstance()->createEvent($file['user_id'], $this->_deviceId, $this->_action, $file["file_path"], $file["file_path"], $file["event_uuid"]);
         $share_filter->handlerAction($this->_action, $this->_deviceId, $file["file_path"], $file["file_path"]);
     }
     $parenFile["event_uuid"] = MiniUtil::getEventRandomString(46);
     $parenFile["is_deleted"] = 1;
     $parenFile->save();
     // 创建事件
     MiniEvent::getInstance()->createEvent($parenFile['user_id'], $this->_deviceId, $this->_action, $parenFile["file_path"], $parenFile["file_path"], $parenFile["event_uuid"]);
     $share_filter->handlerAction($this->_action, $this->_deviceId, $parenFile["file_path"], $parenFile["file_path"]);
     //
     // 删除共享目录
     //
     if ($share_filter->_is_shared_path && $share_filter->operator == $share_filter->master) {
         $id = $parenFile["id"];
         $handler = new ShareManager();
         $handler->_userId = $share_filter->operator;
         $handler->_id = $id;
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             throw new ApiException('Internal Server Error');
         }
     }
 }
Exemplo n.º 4
0
 /**
  *
  * 重命名共享目录
  * @param string $from_path
  * @param string $to_path
  */
 public function handlerRenameShared($from_path, $to_path)
 {
     $share_manager = new ShareManager();
     $share_manager->_userId = $this->operator;
     $share_manager->_from = $from_path;
     $share_manager->_to = $to_path;
     $share_manager->invoke(ShareManager::RENAME_SHARED);
 }