以编程方式将许多版本添加到Liferay Web内容

问题描述 投票:0回答:1

我在Liferay 6.2中有一个Web内容,我想为它添加许多版本,以便进行测试。

如何在不点击数千次的情况下做到这一点?

liferay liferay-6
1个回答
1
投票

转到脚本控制台(在“服务器管理”中),将其设置为“Groovy”,粘贴下面的脚本,将userIdgroupIdarticleId值替换为使用Liferay Web界面找到的值,将numberOfVersions值替换为您想要的任何数字,然后执行:

import com.liferay.portal.service.ServiceContext
import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil
import com.liferay.portlet.documentlibrary.model.DLFolderConstants

int numberOfVersions=1000
long companyId=20155
long groupId=21328
String articleId="21333"
long userId=20199
long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID
String content='<?xml version="1.0"?><root available-locales="en_US" default-locale="en_US"><static-content language-id="en_US"><![CDATA[Bonjour]]></static-content></root>'

ServiceContext serviceContext = new com.liferay.portal.service.ServiceContext()
serviceContext.setAddCommunityPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(groupId);
serviceContext.setCompanyId(companyId);
serviceContext.setUserId(userId);

for (int i=10; i<numberOfVersions; i++) {
  double version = i/10.0
  JournalArticleLocalServiceUtil.updateArticle(userId, groupId, folderId, articleId, version, content, serviceContext)
}

欢迎任何改进或其他想法!

© www.soinside.com 2019 - 2024. All rights reserved.