Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Migrating from the old placeholder paragraphs in blossom 0.5

As some of you know Blossom 0.5 used a placeholder paragraph instead of the paragraphrenderer mechanism it uses today. This means that those of you who created a lot of content in magnolia 0.5 have to do a lot of special extensions of things like the ParagraphRegistry and ParagraphDescriptionBuilder to get everything to play nice in blossom 1.0 and higher.

Migrating away from this means changing the template of all these paragraphs to the new correct templatename instead of the blossom-paragraph.

It is highly recommended that you start by using the recommended module startup method in the newer blossomversion since running installtasks means your applicationcontext doesn't start and you will need an extra restart after all this.

In the process of upgrading to Blossom 1.2.1 I created an installtask that did it automatically for me on install.

Basically all you have to do with this is add something like this to you modules versionhandler.

register(DeltaBuilder.update("1.44", "").addTask(new MigrateBlossomPlaceholderParagraphs()));

This means that in upgrading to version 1.44 of your module all content is scanned and fixed.

If you have customized the name of the placeholderparagraph and/or the name of the handlerPath-content you can specify this by using the second constructor.

My installtask looks like this
package se.issi.stellata.module;

import info.magnolia.cms.beans.config.ContentRepository;
import info.magnolia.cms.core.Content;
import info.magnolia.cms.util.ContentUtil;
import info.magnolia.module.InstallContext;
import info.magnolia.module.delta.AllChildrenNodesOperation;
import info.magnolia.module.delta.TaskExecutionException;
import org.apache.commons.lang.StringUtils;

import javax.jcr.RepositoryException;

/**
 * @author Åke Argéus
 */
public class MigrateBlossomPlaceholderParagraphs extends AllChildrenNodesOperation {

	private final String placeholderParagraph;
	private final String handlerPath;

	public MigrateBlossomPlaceholderParagraphs() {
		super("Migrate blossom-0.5 paragraphs", "Migrate blossom-0.5 paragraphs", ContentRepository.WEBSITE, "/", ContentUtil.EXCLUDE_META_DATA_CONTENT_FILTER);
		this.placeholderParagraph = "blossom";
		this.handlerPath = "handlerPath";
	}

	public MigrateBlossomPlaceholderParagraphs(String placeholderParagraph, String handlerPath) {
		super("Migrate blossom-0.5 paragraphs", "Migrate blossom-0.5 paragraphs", ContentRepository.WEBSITE, "/", ContentUtil.EXCLUDE_META_DATA_CONTENT_FILTER);
		this.placeholderParagraph = placeholderParagraph;
		this.handlerPath = handlerPath;
	}

	protected void doExecute(final InstallContext ctx) throws RepositoryException, TaskExecutionException {
		log.info("Starting migration of blossom-0.5 paragraphs");
		final Content parentNode = getParentNode(ctx);

		try {
			ContentUtil.visit(parentNode, new ContentUtil.Visitor() {
				public void visit(Content subNode) throws Exception {
					operateOnChildNode(subNode, ctx);
				}
			}, ContentUtil.EXCLUDE_META_DATA_CONTENT_FILTER);
		} catch (Exception e) {
			throw new TaskExecutionException("Could not visit subnode", e);
		}
		log.info("Finished migration of blossom-0.5 paragraphs");
	}

	@Override
	protected void operateOnChildNode(Content subNode, InstallContext ctx) throws RepositoryException, TaskExecutionException {
		if (subNode.getMetaData().getTemplate().equals(placeholderParagraph)) {
			log.info("Migrating away from placeholder paragraph on paragraph at:" + subNode.getHandle());
			String template = StringUtils.replaceChars(StringUtils.strip(subNode.getNodeData(handlerPath).getString(), "/"), "/#", "_");
			subNode.getMetaData().setTemplate(template);
			subNode.deleteNodeData(handlerPath);
			subNode.save();
		}
	}

}

It is suggested that you try this a few times on a local development repository before really just running it in production, even though we have tested this quite a few times.

If you have customized the name of the placeholderparagraph and/or the name of the handlerPath-content you can specify this by using the second constructor.

  • No labels