为什么 Sitecore 从 C# API 发布草稿项目,我该如何阻止它这样做? [英] Why does Sitecore publish draft items from the C# API, and how do I stop it doing so?

查看:91
本文介绍了为什么 Sitecore 从 C# API 发布草稿项目,我该如何阻止它这样做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sitecore 发布 API 运行我的 Sitecore 主数据库的预定发布.我在一天中按计划的时间间隔调用 Web 服务,该服务运行以下代码(为了便于阅读而略有压缩):

I'm running a scheduled publish of my Sitecore master DB using the Sitecore publishing API. I call a web service at scheduled intervals during the day which runs the following code (slightly condensed for readability):

// grab the root content node from sitecore
Item contentNode = dbSource.Items[ID.Parse("{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}")];

PublishOptions options = new PublishOptions(sourceDatabase, targetDatabase, PublishMode.Smart, lang, DateTime.Now);

options.RootItem = contentNode;

options.Deep = true;

Publisher p = new Publisher(options);

p.PublishAsync();

当我们运行上述代码时,它会发布内容节点中的所有内容,包括所有后代,而不管工作流状态如何.就好像它完全忽略了工作流程.这不是我们所追求的,并且会在我们的实时网站上造成很多问题.

When we run the above code it publishes everything in the content node, including all descendants, regardless of workflow state. It's like it is ignoring the workflow completely. This is not what we are after, and is causing lots of problems on our live website.

如果我们在 Sitecore Desktop 中运行相同的操作,它会发布内容节点中的所有内容,包括所有后代,这些内容都是可发布(即在最终工作流程阶段).它不会在树中发布任何仍处于草稿模式的项目.这是必需的行为.

If we run the same action from within Sitecore Desktop it publishes everything in the content node, including all descendants, that are publishable (I.e. in the final workflow stage). It does not publish any items in the tree that are still in draft mode. This is the required bahaviour.

我已尝试通过使用以下 using 语句包围上述代码来以非管理员用户身份实现代码:

I have tried implementing the code as a non-admin user by surrounding the above code with the following using statement:

string userName = @"sitecore\******";

Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(userName, true);

user.RuntimeSettings.IsAdministrator = false;

using (new Sitecore.Security.Accounts.UserSwitcher(user))
{
    ...
}

不幸的是,这没有效果.

Unfortunately this has had no effect.

是否有明显我遗漏的地方,或者我做对了而 Sitecore 做错了?请问有人可以帮忙吗?

Is there something obvious I've missed, or am I doing it right and Sitecore is doing it wrong? Can anyone help please?

我还注意到一件奇怪的事情,即在实时数据库中查看发布的草稿项目时,Sitecore 桌面中的字段或元数据完全没有显示.他们还显示了当前项目没有英语:英语"版本的警告.

The strange thing I noticed, also, is that the draft items that were published, when viewed on the live database, were showing absolutely nothing in the Sitecore Desktop in terms of fields or meta data. They were also showing a warning that "The current item does not have a version in "English : English".

推荐答案

TL;DR 根内容节点有另一种语言的版本,删除该版本,或仅阻止以英语发布以草稿模式发布项目

TL;DR Root content node had version in another language, removing that version, or only publishing in English language prevented publishing of items in draft mode

好的,所以在尝试了@techphoria414 的建议代码后,很明显上下文不是问题.发布者毕竟坚持工作流程,但问题已经证明是根内容节点具有另一种语言的版本(日语 - 不要问我这是如何到达那里的),但后代节点没有日语版本根本.事实上,我们的主数据库仅配置为将英语作为一种语言,因此管理员以外的用户甚至不可能添加另一种语言的版本.

OK, so after trying @techphoria414's suggested code, it became clear that the context wasn't the issue. The publisher WAS adhering to workflow after all, but the problem has turned out to be the root content node having a version in another language (Japanese - don't ask me how this got there), but the descendant nodes having no versions in Japanese at all. In fact, our master database is only configured to have English as a language so it shouldn't even be possible for a user other than admin to add a version in another language.

我进行了一些测试,发现发布商会忽略以另一种语言存在的项目的工作流程.考虑以下场景:

I have conducted some tests and found that the publisher ignores workflow for items that exist in another language. Consider the following scenario:

1) 您添加一个文件夹和下面具有工作流的任何项目(测试工作流项目").不要提交项目,将其保留在版本 1,处于草稿模式(即不应发布).包含文件夹只有一种语言(英语)的版本:

1) You add a folder and any item underneath ("test workflow item") which has workflow. Don't commit the item, leaving it at version 1, in draft mode (i.e. shouldn't be publishable). The containing folder only has one version in one language (English):

2) 您将带有深度发布的文件夹发布到您的网络数据库(使用我问题中的代码).这导致以下结果(添加了文件夹,但未添加草稿测试工作流项目").这是预期的行为 - 是的!

2) You publish the folder with a deep publish to your web db (using the code in my question). This results in the following (folder added, but draft "test workflow item" not added). This is expected behaviour - yay!

3) 以不同语言将新版本添加到包含文件夹.

3) Add a new version to the containing folder in a different language.

4) 现在选择日语作为语言,检查子项的工作流状态.请注意,在装订线中不再说它处于草稿模式,但根本没有日文版本(如右图所示).

4) Check the workflow state of the child item now that Japanese is selected as the language. Notice, in the gutter it no longer says it is in draft mode, but there is no version at all in Japanese (as seen to the right).

5) 将所有语言的包含文件夹发布到网络数据库,与之前完全相同.请注意,测试工作流项"已发布,但根本没有版本.这就是我们发布时发生的情况,除了从根内容节点开始,这意味着无数不应该发布的项目被发布

5) Publish the containing folder in all languages to the web db, exactly the same as before. Notice now that the "test workflow item" has been published, but with no versions at all. This is what happened with our publish, except from the very root content node which meant countless items got published that should not have been published

现在,为什么我们的根内容节点有一个日文版本完全是个谜,但至少我们已经弄清楚了为什么我们的草稿项目会被发布,这样我们就可以在将来防止它.我怀疑这与升级 Sitecore 有关系,因为日语有 2 个版本,大致对应于过去 2 年的升级日期.

Now, why our root content node has a version in Japanese is a complete mystery, but at least we have figured out why our draft items got published so we can prevent it in the future. I suspect it has something to do with upgrading Sitecore as there are 2 versions in Japanese which roughly correspond to upgrade dates over the last 2 years.

这篇关于为什么 Sitecore 从 C# API 发布草稿项目,我该如何阻止它这样做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆