/** * * 执行文件夹删除 * @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'); } } }