OrchardCoreContrib.Modules icon indicating copy to clipboard operation
OrchardCoreContrib.Modules copied to clipboard

Add Recylce Bin feature

Open hishamco opened this issue 3 years ago • 8 comments

Adding a recylce bin like feature for deleted content items is great

hishamco avatar May 12 '22 07:05 hishamco

  • [ ] Show the deleted contents
  • [ ] Ability to restore the deleted contents
  • [ ] Ability to remove the deleted contents permenantly

hishamco avatar Sep 18 '22 13:09 hishamco

Show the deleted contents Ability to restore the deleted contents

Perhaps the audit module can already do this

hyzx86 avatar May 18 '23 16:05 hyzx86

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;
                    }

hyzx86 avatar May 18 '23 16:05 hyzx86

Why should be restricted to the development environment?

hishamco avatar May 18 '23 16:05 hishamco

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

hyzx86 avatar May 18 '23 16:05 hyzx86

Ya it's risky but we can do it at your risk if there feature is on. We could enable it for admins only

hishamco avatar May 18 '23 17:05 hishamco

The Audit Trail module does these.

Piedone avatar Mar 21 '24 21:03 Piedone

Believe it or not, I haven't tried all the features for AuditTrail before, but I will have a quick look

hishamco avatar Mar 21 '24 22:03 hishamco