Add Recylce Bin feature
hishamco opened this issue · 8 comments
Adding a recylce bin like feature for deleted content items is great
- Show the deleted contents
- Ability to restore the deleted contents
- Ability to remove the deleted contents permenantly
Show the deleted contents
Ability to restore the deleted contents
Perhaps the audit module can already do this
remove the deleted contents permenantly
This feature should be restricted to the development environment
If this happens in production, a database update is the recommended approach
I implemented a Jint extension method
Name="clearContentByContentType",
Method= sp=>(string contentTypeName)=>{
var logger= sp.GetRequiredService<ILogger<ContentMethodsProvider>>();
var session= sp.GetRequiredService<ISession>();
var freeSql=sp.GetFreeSql();
var ids=new List<int>();
var transection=session.BeginTransactionAsync().GetAwaiter().GetResult();
try
{
logger.LogWarning("准备清理类型{contentTypeName}",contentTypeName);
freeSql.Delete<ContentPickerFieldDIndex>().Where(c=>c.ContentType==contentTypeName)
.WithTransaction(transection)
.ExecuteAffrows();
freeSql.Delete<ContentItemIndex>().Where(c=>c.ContentType==contentTypeName)
.WithTransaction(transection)
.ExecuteAffrows();
var indexService = sp.GetRequiredService<IDynamicIndexAppService>();
var type = indexService.GetDynamicIndexType(contentTypeName);
if (type != null)
{
try
{
var tbE= freeSql.CodeFirst.GetTableByEntity(type);
if (freeSql.DbFirst.ExistsTable(tbE.DbName))
{
freeSql.Delete<object>().AsType(type).Where("1=1")
.WithTransaction(transection)
.ExecuteAffrows();
}
}
catch (Exception)
{
logger.LogWarning("类型{contentTypeName} 动态类型清理失败,可能尚未创建",contentTypeName);
}
}
logger.LogWarning("类型{contentTypeName} 已清理",contentTypeName);
}
catch (Exception)
{
freeSql.Update<ContentItemIndex>().SetSource(new ContentItemIndex
{
Published=false,
Latest=false
}) .WithTransaction(transection).Where(x=>x.ContentType==contentTypeName).ExecuteAffrows();
logger.LogWarning("类型{contentTypeName} 清理失败,所有内容已取消发布",contentTypeName);
}
return ids.Count;
}
Why should be restricted to the development environment?
Because it is a dangerous operation, if the data is deleted and there is no way to restore it without any backup
We should keep the complexity of high-risk operations
Ya it's risky but we can do it at your risk if there feature is on. We could enable it for admins only