RE: Change blog author

Jamie Sammons, modificat fa 3 anys. New Member Apunt: 1 Data d'incorporació: 02/06/22 Publicacions recents

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, modificat fa 3 anys. Expert Apunts: 322 Data d'incorporació: 11/03/10 Publicacions recents

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, modificat fa 3 anys. Liferay Legend Apunts: 6441 Data d'incorporació: 23/09/08 Publicacions recents

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.