【问题标题】:Cannot recycle a Sitecore CMS Item from a Windows Service无法从 Windows 服务回收 Sitecore CMS 项目
【发布时间】:2012-09-24 10:35:55
【问题描述】:

我正在使用 Windows 服务,它对 Sitecore 项目(非活动或旧产品)进行清理工作,但当我尝试删除它们时却无法删除。

if (qItem != null)
{
 qItem.Recycle();
}

相关的 StackTrace 是:

Message: Object reference not set to an instance of an object.
StackTrace:   at Sitecore.Tasks.ItemEventHandler.OnItemDeleted(Object sender, EventArgs args)
   at Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters, EventResult result)
   at Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters)
   at Sitecore.Events.Event.RaiseEvent(String eventName, Object[] parameters)
   at Sitecore.Events.Event.RaiseItemDeleted(Object sender, ItemDeletedEventArgs args)
   at Sitecore.Events.Event.DataEngine_ItemDeleted(Object sender, ExecutedEventArgs`1 e)
   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   at Sitecore.Data.Engines.EngineCommand`2.RaiseExecuted()
   at Sitecore.Data.Engines.DataEngine.RaiseDeletedItem(Item item, ID parentId, Boolean result)
   at Sitecore.Data.Archiving.Archive.NotifyItemDeleted(Item item, ID parentId)
   at Sitecore.Data.Archiving.SqlArchive.DoArchiveItems(IEnumerable`1 items, Guid archivalId)
   at Sitecore.Data.Archiving.SqlArchive.DoArchiveItems(IEnumerable`1 items, Guid archivalId)
   at Sitecore.Data.Archiving.SqlArchive.ArchiveItem(Item item)
   at Sitecore.Data.Items.Item.Recycle()

我再次提到,仅当我从 Windows 服务回收项目时才会收到此错误。在 Web 应用程序中同样的回收工作正常。

在 Web 应用程序中,我登录到 sitecore,用户是管理员,所以他有一些权限。

在 Windows 服务中,用户 (Sitecore.Context.User) 是 "default\Anonymous"

为了绕过安全检查,我在 SecurityDisabler 中使用了 Recycle 调用,但没有结果。

我是否需要从我的 Windows 服务登录到 Sitecore?如果是,我该怎么做?

或者还有其他方法可以从非 Web 应用程序中回收/删除 Sitecore 项目吗?

下面是运行并抛出拒绝访问异常的代码(它不在 SecurityDisabler 上下文中运行):

这是在 SecurityDisabler 上下文中回收项目的代码。现在没有拒绝访问异常,但是“对象引用未设置为实例”异常。

【问题讨论】:

  • 你可以试试网络服务。您可以在 /sitecore/shell/WebService 下找到它

标签: windows-services sitecore recycle


【解决方案1】:

我在使用 Sitecore API 的独立服务中遇到了非常相似的问题。

我使用 BucketManager 来同步一个项目存储桶,它最终调用了与 Recycle 调用相同的 item.Delete() 方法,因此我的堆栈跟踪将我带到了相同的位置。

TaskDatabase 是在我使用的 web.config 中定义的,但我决定 Globals 上的 Load() 方法永远不会被调用,所以我从未使用以下任何内容初始化任务数据库字段配置。

在我调用删除的对象的构造函数中,我包含了以下行:

Sitecore.Globals.Load();

这解决了我的问题。

【讨论】:

    【解决方案2】:

    当我们安装 Sitecore 实例时,我们会获得一个 Web 服务,该服务与 Sitecore 应用程序在同一域下公开

    http://sitedomain.com/sitecore/shell/webservice/service.asmx

    此服务包含使用 Sitecore API 所需的所有方法。

    它对我有用

    【讨论】:

      【解决方案3】:

      在反射器中查看引发异常的方法 (Sitecore.Tasks.ItemEventHandler.OnItemDeleted),您的空引用可能是 TaskDatabase。

      protected void OnItemDeleted(object sender, EventArgs args)
      {
          Item item = Event.ExtractParameter(args, 0) as Item;
          Error.AssertNotNull(item, "No item in parameters");
          using (new SecurityDisabler())
          {
              Globals.TaskDatabase.RemoveItemTasks(item);
          }
      }
      

      我假设对于您的 Windows 服务,您的 App.config 具有精简的 Sitecore 配置。您应该确保 /sitecore/configuration/TaskDatabase 元素在您的 Sitecore 配置中。

      【讨论】:

      • 配置文件中有一个TaskDatabase:
      • 我也使用反射器查找了执行的代码,但无法弄清楚什么变量是空的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多