我需要一个项目,客户要求我在给定的时间戳后返回已删除的项目。
/fetch-updates?last-update=[timestamp]
我对此做了一些研究,但找不到任何东西。据我所知,如果一个项目被删除,它就不能再被追踪,但我可能错了。
有办法吗?
如果没有,请你建议一种做这种手术的方法吗?
答案 0 :(得分:2)
默认情况下,当您删除 Sitecore 中的项目时,它会移至Recycle bin
。如果未从回收站中删除该项目,则仍可在删除时找到该信息。
您可以使用以下代码检查回收站中的项目:
Archive archive = Sitecore.Data.Database.GetDatabase("master").Archives["recyclebin"];
List<ArchiveEntry> itemsRemovedAfterSomeDate
= archive.GetEntries(0, int.MaxValue).Where(entry => entry.ArchiveDate > someDate).ToList();
请注意ArchiveEntry.ArchiveDate
属性使用UTC
时间,因此您可能需要使用ArchiveEntry.ArchiveLocalDate
。
您可以在 Sitecore 配置文件中关闭/启用Recycle bin
:
<!-- RECYCLE BIN
If true, when deleting items in the client, they will
be moved to the recycle bin rather than being deleted
Default value: true
-->
<setting name="RecycleBinActive" value="true" />
答案 1 :(得分:1)
您还可以使用HistoryEngine
API从历史记录表中检索项目列表:
var db = Sitecore.Data.Database.GetDatabase("master");
var historyEngine = new Sitecore.Data.Engines.HistoryEngine(db);
var deletedItems = historyEngine.GetHistory(fromDateUTC, toDateUTC)
.Where(history => history.Action == HistoryAction.Deleted);
请注意,默认情况下,仅存储30天的信息。你可以在config中增加它:
<Engines.HistoryEngine.Storage>
<obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
<param connectionStringName="$(id)"/>
<EntryLifeTime>30.00:00:00</EntryLifeTime>
</obj>
</Engines.HistoryEngine.Storage>