我遇到了业务需求,我想从master&web,并从solr索引中删除相应的项。业务不想发布父项,因为兄弟或父项可能会发生更改,因此我无法触发任何策略,如onPublishEndAsync,onPublishEndAsyncSingleInstanceon PublishEndAsync预览这里我正在尝试下面的东西,但它不起作用
var ParentItem = item.Parent;
using (new EditContext(item))
{
if (Sitecore.Configuration.Settings.RecycleBinActive)
item.Recycle();
else
item.Delete();
}
if (item == null)
return;
ISearchIndex index = ContentSearchManager.GetIndex((SitecoreIndexableItem)ParentItem );
if (index == null)
return;
index.Refresh(new SitecoreIndexableItem(ParentItem )); or
index.RefreshAsync(new SitecoreIndexableItem(item), IndexingOptions.ForcedIndexing, new System.Threading.CancellationToken());
我没有在sitecore日志或solr日志文件中得到任何错误,但索引没有删除项目
您可以将项目标记为不可发布,发布它(这将从web
数据库和web
索引中删除该项目(,然后删除它。
以下是来自所有发布目标数据库的未发布项目的示例代码:
using (new SecurityDisabler())
{
var targets = PublishManager.GetPublishingTargets(item.Database)
.Select(i => Database.GetDatabase(i[FieldIDs.PublishingTargetDatabase]))
.ToArray();
var languages = LanguageManager.GetLanguages(item.Database).ToArray();
item.Editing.BeginEdit();
item.Publishing.NeverPublish = true;
item.Editing.EndEdit();
var handle = PublishManager.PublishItem(item, targets, languages, false, false);
PublishManager.WaitFor(handle);
}
之后只执行item.Recycle
或Delete
。
不久前,我写了一篇博客文章,描述了如何添加一个功能区按钮;删除并取消发布"项目。你可以在这里找到:
自动取消发布已删除的Sitecore项目