Legacy Knowledge Base
公開されました Jul. 2, 2025

DXP 7.1の旧バージョンからの移行で、複数のWebコンテンツに表示ページテンプレートを割り当てる。

Written By

Georgel Pop

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

問題

  • 7.1以前のバージョンでは、ウェブコンテンツで使用する表示ページテンプレートがありませんでした。
  • 7.1+ に移行した後、 Design > Page Templates > Display Page Templatesから、既存の Web コンテンツ構造に関連するデフォルトの Display Page Template を作成することができます。
  • その構造を持つ既存のウェブコンテンツを編集すると、デフォルトの「表示ページテンプレート」を指すことがわかりますが、この関係はウェブコンテンツを保存しないと有効になりません。
  • この手作業を避けて、移行したWebコンテンツのDisplay Page Templateを大量に変更する方法はないでしょうか。

Environment

  • DXP 7.1以上

解決策

  • 各ウェブコンテンツを手動で変更するのを避けるために、このAPIメソッドを使ってGroovyスクリプトを書くことができます(source):
    addAssetDisplayPageEntry(long userId, long groupId, long classNameId, long classPK, long layoutPageTemplateEntryId, int type, com.liferay.portal.kernel.service.ServiceContext serviceContext)
  • 重要: 以下のGroovyコードの一部は、スタートガイドとして意図されており、公式にサポートされているものではありません。 それぞれのユースケースに合わせて、慎重に検討し、適合させる必要があります。 変更内容は元に戻らないので、コードを実行する前にデータベースのバックアップを取る必要があります。
  • まず、 userId と classNameIdを取得することになります。
    // We are using the current user running the script but it could be another admin user.
    // Documentation: https://help.liferay.com/hc/en-us/articles/360017877412-Running-Scripts-From-the-Script-Console#tip-1-use-the-predefined-variables
    def userId = Long.valueOf(userInfo.get('liferay.user.id'));
    
    def classNameId = PortalUtil.getClassNameId(JournalArticle.class.getName());
  • 次のステップは、Webコンテンツの修正に必要な JournalArticleResources を取得することです。
    List<JournalArticleResource> journalArticleResources =
    JournalArticleResourceLocalServiceUtil.getJournalArticleResources(-1, -1);
    注: 記事の数が多い場合は、パフォーマンスを維持するために、countメソッドなどを使って本サービスへの呼び出しをページネーションしてください:
    JournalArticleLocalServiceUtil.getStructureArticlesCount(long groupId, String ddmStructureKey)
  • 最後に、各 journalArticleResourceに対して、:
    • 関連する groupId および resourcePrimKeyを取得する。
         def groupId = journalArticleResource.getGroupId();
         def resourcePrimKey = journalArticleResource.getResourcePrimKey();
    • layoutPageTemplateId と typeを選択する。これは、すべての journalArticleResources に対して同じであっても、それぞれに対して異なっていてもよい:
         // We are assigning a default display page template relationships, hence TYPE_DEFAULT, so we also use 0L for layoutPageTemplateEntryId
         // If other types are used, such as TYPE_SPECIFIC, query the table layoutpagetemplateentry for the value of layoutPageTemplateEntryId associated to a particular display page template.
         def type = AssetDisplayPageConstants.TYPE_DEFAULT;
         def layoutPageTemplateEntryId = 0L;
    • 表示ページテンプレートである既存のassetDisplayPageEntryを取得し、新規に割り当てます:
         AssetDisplayPageEntry assetDisplayPageEntry = AssetDisplayPageEntryLocalServiceUtil.fetchAssetDisplayPageEntry(groupId, classNameId, resourcePrimKey);
      
         if (assetDisplayPageEntry == null) {
            AssetDisplayPageEntryLocalServiceUtil.addAssetDisplayPageEntry(userId, groupId, classNameId, resourcePrimKey, layoutPageTemplateEntryId, type, new ServiceContext());
         }
  • 注意事項 このコードを慎重に確認し、特定のユースケースに適合させ、実行前にデータベースのバックアップを作成してください。

追加情報

  • Liferay DXP 7.4では、特に変更する必要はありません。 機能要求 LPS-122275 ( Breaking Change documentation参照) の実装後、デフォルトの表示ページテンプレートを使用するために、テーブル assetdisplaypageentry のエントリーが不要になりました。
  • Global サイトの Basic Web Content 構造に影響し、フレンドリーな URL の使用に影響する問題が、 LPS-155301で報告されています。 修正するためのパッチをサポートに依頼し、移行データベース処理を再度実行してください。
  • 表示の問題は、 LPS-156283によって解決されます。 修正するために、サポートにパッチを依頼してください。
Did this article resolve your issue ?

Legacy Knowledge Base