orchardcms - 以编程方式删除 Orchard 中的用户

标签 orchardcms

我不是 Orchard 大师。我是一名桌面应用程序人员,肩负着很多责任,继承了大量 Orchard 代码,并负责一些维护工具。我尝试用谷歌搜索互联网,但没有成功,所以我绝望地转向 Stack,希望有人拥有简单按钮...

基本上(这是一个过于简化的用例)- 我们经常有用户使用错误的电子邮件地址进行注册在一天之内忘记他们的帐户信息再次注册,但胖手指密码然后第三次注册,依此类推...

我有一个维护控制台,允许管理员“定位”与第一个或第二个帐户(在我的示例中)关联的数据(在我们自己的非 Orchard SQL 表中),并将该数据与第三个“当前”帐户重新关联。/正确的帐户。

在这次重新映射结束时,我想以编程方式清理(读取:删除)前两个帐户的 Orchard 登录信息,这些帐户现在已正式成为 kruft。

我在Stack here上找到了一些信息谈论 Orchard 用户帐户:

Users are content types and Orchard creates content items for each user. When you create a new user Orchard adds records to xxx_Orchard_Users_UserPartRecord, xxx_Orchard_Framework_ContentItemRecord, xxx_Orchard_Framework_ContentItemVersionRecord and xxx_Orchard_Roles_UserRolesPartRecord if you linked any roles to the user.

The xxx_Orchard_Framework_ContentItemVersionRecord table keeps track of the version number and whether or not a content item is published or not and which version of the published content item is the latest.

When you delete the user Orchard does not delete the records from the tables, but simply creates a new version record and sets Published and Latest columns to 0 for the new version and the old version. Because there is no published and latest version the content item does not show up on the list of users.

我在概念上理解这一点,但我不敢相信要删除一个用户,我需要从 Orchard 中的每个“私有(private)”表中删除记录。相反,我希望有一个类/方法/技术来删除内容类型或部分或记录或其他什么(我仍然没有完全在我的脑海中得到 Orchard 对象命名)。

任何人都可以分享一个在代码中删除用户的示例(通过 ID、用户名或电子邮件)吗?或者给我指点相关文档?我在这里像鱼离开水一样摸索......

一如既往,提前致谢!

最佳答案

正如你所说,在 Orchard 中,UI 中的大多数删除都是软删除,保留所有数据并在数据库中设置一个标志来表明此人已被删除。要以编程方式执行此操作,其中 _contentManagerIContentManager 的实例。

var userItem = _contentManager.Get<IUser>(userId);
_contentManager.Remove(userItem);

进行硬删除,这将删除项目记录、所有项目版本记录和所有内容部分记录(标题部分、用户部分等)

var userItem = _contentManager.Get<IUser>(userId);
_contentManager.Destroy(userItem);

这是在 1.9 版本中添加到 Orchard 中的。

关于orchardcms - 以编程方式删除 Orchard 中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50183491/

相关文章:

orchardcms - 了解 Orchardplacement.info 文件

azure - Azure 中托管的 Orchard 中的主题

c# - 如何在 Orchard cms 中添加网站元数据

sql - 为什么 Orchard 在执行内容项查询时这么慢?

c# - Orchard - 移动页面标题

postgresql - Mono 上的 Orchard CMS

orchardcms - Orchard CMS Multi-Tenancy 崩溃提防

c# - 如何在 Orchard CMS 数据库中保存自定义数据

c# - 如何在 ASP.NET MVC (Orchard CMS) 中禁用防伪造?

c# - 如何访问整个 AutoFac 容器以在 Orchard 中注册依赖项?