RE: Change blog author

Jamie Sammons, modified 3 Years ago. New Member Post: 1 Join Date: 6/2/22 Recent Posts

I need to change the author on several published blog posts. Is there a way to do that without entirely re-entering/re-publishing the blog post?

thumbnail
Tanweer Ahmed Ansari, modified 3 Years ago. Expert Posts: 322 Join Date: 3/11/10 Recent Posts

Hi Kristin,

Not sure if you thought about the approach to solve it programmatically - one way would be to use Actionable Dynamic Query.

In case, you go with this approach - use the setAddCriteriaMethod to retrieve the blog list that needs an author update and then use setPerformActionMethod to update the Author details.

Here is how I used it to solve a similar issue related to the Layout entity.

private void updateLayouts() throws Exception {

		ActionableDynamicQuery adq = _layoutLocalService.getActionableDynamicQuery();

		adq.setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<Layout>() {

			@Override
			public void performAction(Layout layout) {
				try {
					// put the update logic here
				} catch (PortalException e) {
					log.error(e);
				}
			}
		});

		try {
			adq.performActions();
		} catch (Exception e) {
			log.error(e);
		}
	}

	@Reference(unbind = "-")
	LayoutLocalService _layoutLocalService;

Here is a link that describes more about  Actionable Dynamic Query

thumbnail
Olaf Kock, modified 3 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

For programmatic approaches, I'd look at the anonymization code, that replaces the original author with an anonymous user before deleting the actual author's user account.