gpt4 book ai didi

database - Umbraco ContentService 不更新文档缓存中的复选框列表

转载 作者:搜寻专家 更新时间:2023-10-30 23:09:46 25 4
gpt4 key购买 nike

我正在使用我编写的导入脚本在一个新的 Umbraco v6.1.6 网站中创建大约 500 个页面。我正在使用 ContentService api 来创建新页面。它们被创建并且似乎保存得很好。但是,如果我从其中一个新页面请求复选框列表的值,我会得到一个空字符串。

我已验证 umbraco.config 文件中的属性为空,但是如果我从 Umbraco 后台手动保存页面。缓存将更新为正确的值,我突然得到返回的正确值。

有没有办法强制更新缓存或解决此问题的其他形式?

这是我正在使用的 CreateContent 方法:

public static IContent CreateContent(string name, string documentTypeAlias, int parentId, Dictionary properties, bool publish = false, int author = 0)
{
IContent document = null;

ContentService contentService = new ContentService();
document = contentService.CreateContent(
name, // the name of the document
parentId, // the parent id should be the id of the group node
documentTypeAlias, // the alias of the Document Type
author);

foreach (string property in properties.Keys)
{
document.SetValue(property, properties[property]);
}

// If publish is true, then save and publish the document
if (publish)
{
contentService.SaveAndPublish(document);
}
// Else, just save it
else
{
contentService.Save(document);
}

return document;
}

编辑:

查看数据库后,我可以看到 cmsContentXml 具有该属性,但其中的数据与 umbraco.config 相同。我查看了 cmsPropertyData 并且数据存在。所以我想问题是如何将数据从 cmsPropertyData 获取到 cmsContentXml?

我的问题与此类似:https://stackoverflow.com/questions/17722347/umbraco-6-1-1-when-i-publish-content-via-the-content-service-tags-type-property但是它没有回复。

最佳答案

cmsContentXml 中的数据被直接转储到 umbraco.config 文件中,幸好它们是相同的。

为了让你的代码更干一点(你总是在 if 和 else 中保存文档,试试这个并将 SaveAndPublish 方法更新为 Publish (在 v7 中,您可以使用 PublishWithResult 获取发布操作的详细结果):

contentService.Save(document);

// If publish is true, then save and publish the document
if (publish)
{
contentService.Publish(document);
}

在 v7 中,您可以查看 publishResult。如果有什么问题,那么这会告诉你它是什么。不过,它很可能会以这种方式正常工作(这可能意味着 SaveAndPublish 已损坏,但让我们弄清楚 publishResult 是否有错误)。

关于database - Umbraco ContentService 不更新文档缓存中的复选框列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21681631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com