Cq54StartupCodeUpgrade.java 4.82 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Item
 *  javax.jcr.Node
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.sling.jcr.api.SlingRepository
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.compat.codeupgrade.impl.cq54;

import com.day.cq.compat.codeupgrade.CodeUpgradeTask;
import com.day.cq.compat.codeupgrade.impl.StatusNode;
import com.day.cq.compat.codeupgrade.impl.UpgradeNodetypes;
import com.day.cq.compat.codeupgrade.impl.cq54.Msm54RolloutConfigUpgrade;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import java.util.Dictionary;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class Cq54StartupCodeUpgrade
implements CodeUpgradeTask {
    private final Logger log;
    private StatusNode statusNode;
    private String configPath;
    private ProgressInfoProvider infoProvider;
    private String progressInfo;
    @Reference
    private SlingRepository repository;
    @Property(value={"/libs/cq/compat/components/codeupgrade/5.4"})
    public static final String PROP_CONFIG_PATH = "upgrade.configuration.path";
    @Property(value={"/var/upgrade/status"})
    public static final String PROP_STATUS_NODE_PATH = "status.node.path";
    @Property(value={"Cq54StartupCodeUpgrade"})
    public static final String PROP_STATUS_PROPERTY_NAME = "status.property.name";

    Cq54StartupCodeUpgrade() {
        this.log = LoggerFactory.getLogger(this.getClass());
        this.progressInfo = "No progress info";
    }

    public String toString() {
        return this.getClass().getSimpleName();
    }

    public void activate(ComponentContext ctx) throws Exception {
        Dictionary properties = ctx.getProperties();
        this.statusNode = new StatusNode((String)properties.get("status.node.path"), (String)properties.get("status.property.name"));
        this.configPath = (String)properties.get("upgrade.configuration.path");
    }

    @Override
    public void cancelUpgrade() {
    }

    @Override
    public synchronized String getProgressInfo() {
        if (this.infoProvider == null) {
            return this.progressInfo;
        }
        return this.infoProvider.getProgressInfo();
    }

    private void run54SpecificUpgrades(Session s) throws RepositoryException {
        String repl = "/etc/replication";
        String rtProp = "sling:resourceType";
        String rtValue = "cq/replication/components/home";
        if (s.itemExists("/etc/replication")) {
            String value;
            Node n = (Node)s.getItem("/etc/replication");
            String string = value = n.hasProperty("sling:resourceType") ? n.getProperty("sling:resourceType").getString() : "";
            if (!"cq/replication/components/home".equals(value)) {
                n.setProperty("sling:resourceType", "cq/replication/components/home");
                s.save();
                this.log.info("Property {} set to {}", (Object)(n.getPath() + "/" + "sling:resourceType"), (Object)"cq/replication/components/home");
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public void run() {
        Session s = null;
        try {
            s = this.repository.loginService("compat-codeupgrade", null);
            this.progressInfo = "Upgrading node types";
            new UpgradeNodetypes().doUpgrade(s, this.configPath + "/nodetypes.cnd");
            Msm54RolloutConfigUpgrade rcu = new Msm54RolloutConfigUpgrade();
            Cq54StartupCodeUpgrade cq54StartupCodeUpgrade = this;
            synchronized (cq54StartupCodeUpgrade) {
                this.infoProvider = rcu;
            }
            rcu.doUpgrade(s);
            cq54StartupCodeUpgrade = this;
            synchronized (cq54StartupCodeUpgrade) {
                this.infoProvider = null;
            }
            this.progressInfo = "Running 5.4-specific upgrades";
            this.run54SpecificUpgrades(s);
            this.statusNode.recordUpgrade(this.repository);
        }
        catch (Exception e) {
            this.log.warn("Exception in " + this.getClass().getSimpleName() + ".run()", (Throwable)e);
        }
        finally {
            if (s != null) {
                s.logout();
            }
        }
    }

    @Override
    public boolean upgradeNeeded() {
        return this.statusNode.upgradeNeeded(this.repository);
    }
}