【问题标题】:Umbraco ContentService not updating checboxlist in document cacheUmbraco ContentService 未更新文档缓存中的复选框列表
【发布时间】:2014-02-10 15:47:04
【问题描述】:

我正在使用我编写的导入脚本在新的 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 但是它没有回复。

【问题讨论】:

  • 属性字典中的值(对于您的复选框列表)如何格式化?如果您导入一个值,该值不会显示在 XML 缓存中,但如果您从后台保存,则听起来您的复选框属性在导入期间未正确保存。

标签: database caching content-management-system umbraco


【解决方案1】:

来自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 是否有错误)。

【讨论】:

  • 'contentService' 不包含 PublishWithResult 的定义。有什么想法吗?
  • 我将您的答案中的“var publishresult = ...”行替换为“contentService.Publish(document);”突然它起作用了。这是一个谜,因为 Publish 和 SaveAndPublish 都使用相同的方法 'SaveAndPublishDo' 但是我不能说我对 Umbraco 源代码做了很多工作。
  • 抱歉,PublishWithResult 是 v7 中的新功能,尚未在 v6 中。
  • 更新了答案,我会弄清楚 PublishWithResult 出了什么问题,看看我们能不能解决这个问题。
  • 谢谢。希望尽快迁移到 v7。可能至少要再发布一个版本。
猜你喜欢
  • 1970-01-01
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 2020-08-24
  • 2018-10-10
  • 1970-01-01
相关资源
最近更新 更多