我正在一个新的Umbraco v6.1.6网站上使用我编码的导入脚本创建大约500个页面。我正在使用内容服务api来创建新页面。它们是被创造出来的,看起来保存得很好。但是,如果我从其中一个新页面请求checbox列表的值,我会得到一个空字符串。
我已经验证了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
文件中,因此谢天谢地,这些数据是相同的。
为了使代码更加DRY(您总是将文档保存在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是否有错误)。