2014-07-17 28 views
1

我有一個項目的要求,客戶要求我在給定的時間戳後返回已刪除的項目。Sitecore項目從給定的時間戳刪除

/fetch-updates?last-update=[timestamp] 

我對此做了一些研究,但找不到任何東西。據我所知,如果某件物品被刪除,則無法追蹤,但我可能是錯的。

有沒有辦法做到這一點?

如果不是,請問您能否提出一種做此操作的方法?

回答

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代替。

您可以打開/關閉Recycle binSitecore的配置文件:

<!-- 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" /> 
+0

而這些保存在回收站多久? –

+1

從我所知道的沒有時間限制。您可以使用Sitecore Desktop中的「回收站」應用程序查看歸檔項目。 –

+0

關於這個問題的另一個問題,我認爲我完成了。有沒有通過模板選擇已刪除項目的方法? –

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天的信息。你可以增加這個配置:

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