Data migration 4.2 to 4.3


This guide covers data migration from Ametys 4.2.x to 4.3.0.
See also the technical migration guide and the graphical migration guide.   

  1. Table migration SQL
    1. Users/Population
    2. Modification of legal identifier
    3. Inheritance of rights disabled
  2. Data migration JCR
    1. Reserved key words
    2. Warning counter
    3. Setting up automatic migration components

Table migration SQL

Users/Population

Scripts for SQL tables containing logins have been harmonized, enabling case-sensitive searches by login or population.

var Config = Java.type("org.ametys.runtime.config.Config");   
var SQLDataSourceManager = serviceManager.lookup("org.ametys.core.datasource.SQLDataSourceManager");   
var UserPopulationDAO = serviceManager.lookup("org.ametys.core.user.population.UserPopulationDAO");   
var GroupDirectoryDAO = serviceManager.lookup("org.ametys.core.group.GroupDirectoryDAO");   

updateRightsTables();   
updateAuhenticationTokenTables();   
updateUserPreferencesTables();   
updateUserSignupTables();   
updateSurveyTables();   
updateUserPopulations();   
updateGroupDirectories();   

function updateGroupDirectories()   
{   
    print("Update group directories");   

    var groupDirectories = GroupDirectoryDAO.getGroupDirectories();   
    for (var i = 0; i < groupDirectories.size(); i++)   
    {   
        var groupDirectory = groupDirectories.get(i);   
        _updateGroupDirectory(groupDirectory);   
    }   
}   

function _updateGroupDirectory(groupDirectory)   
{   
    print("* Group directory " + groupDirectory.getId() + " *");   
    if (groupDirectory.getGroupDirectoryModelId() == "org.ametys.plugins.core.group.directory.Jdbc")   
    {   
        var datasourceId = groupDirectory.getParameterValues().get("runtime.groups.jdbc.datasource");   
        var tableName = groupDirectory.getParameterValues().get("runtime.groups.jdbc.composition.table");   
        var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
        var requests = [];   

        switch (dbType)   
        {   
            case "derby":   
                requests.push("ALTER TABLE " + tableName + " ADD COLUMN Login2 varchar(64) NOT NULL DEFAULT 'nonnull'");   
                requests.push("UPDATE " + tableName + " SET Login2=Login");   
                requests.push("ALTER TABLE " + tableName + " DROP COLUMN Login");   
                requests.push("RENAME COLUMN " + tableName + ".Login2 TO Login");   
                requests.push("ALTER TABLE " + tableName + " ADD PRIMARY KEY (Group_Id, Login, UserPopulation_Id)");   
                break;   
            case "mysql":   
                requests.push("ALTER TABLE " + tableName + " MODIFY Login VARCHAR(64) BINARY");   
                requests.push("ALTER TABLE " + tableName + " MODIFY UserPopulation_Id VARCHAR(200) BINARY");   
                break;   
            case "oracle":   
                requests.push("ALTER TABLE " + tableName + " MODIFY Login VARCHAR(64)");   
                break;   
            case "postgresql":   
                requests.push("ALTER TABLE " + tableName + " ALTER COLUMN Login TYPE VARCHAR(64)");   
                break;   
            case "hsqldb":   
                requests.push("ALTER TABLE " + tableName + " ALTER COLUMN Login VARCHAR(64)");   
                break;   
            default:   
                throw new Error("Unknown database type " + dbType)   
        }   

        _execute("_updateGroupDirectory", dbType, requests, datasourceId);   
    }   
}   

function updateUserPopulations()   
{   
    print("Update user populations");   

    var userPopulations = UserPopulationDAO.getUserPopulations(true);   
    for (var i = 0; i < userPopulations.size(); i++)   
    {   
        var userPopulation = userPopulations.get(i);   
        _updateUserPopulation(userPopulation);   
    }   
}   

function _updateUserPopulation(userPopulation)   
{   
    print("* User Population " + userPopulation.getId() + " *");   

    var userDirectories = userPopulation.getUserDirectories();   
    for (var i = 0; i < userDirectories.size(); i++)   
    {   
        var userDirectory = userDirectories.get(i);   
        _updateUserDirectory(userPopulation, i, userDirectory);   
    }   

    var credentialProviders = userPopulation.getCredentialProviders();   
    for (var i = 0; i < credentialProviders.size(); i++)   
    {   
        var credentialProvider = credentialProviders.get(i);   
        _updateCredentialProvider(userPopulation, i, credentialProvider);   
    }   
}   

function _updateUserDirectory(userPopulation, index, userDirectory)   
{   
    print("** User Directory[" + index + "] " + userDirectory.getId() + " " +     userDirectory.getUserDirectoryModelId() + " *");   
    if (userDirectory.getUserDirectoryModelId() == "org.ametys.plugins.core.user.directory.Jdbc")   
    {   
        var datasourceId = userDirectory.getParameterValues().get("runtime.users.jdbc.datasource");   
        var tableName = userDirectory.getParameterValues().get("runtime.users.jdbc.table");   
        var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
        var requests = [];   

        switch (dbType)   
        {   
            case "mysql":   
                requests.push("ALTER TABLE " + tableName + " MODIFY login varchar(64) BINARY");   
                break;   
            case "derby":   
            case "oracle":   
            case "postgresql":   
            case "hsqldb":   
                // Nothing to do   
                break;   
            default:   
                throw new Error("Unknown database type " + dbType)   
        }   

        _execute("_updateUserDirectory", dbType, requests, datasourceId);   
    }   
}   

function _updateCredentialProvider(userPopulation, index, credentialProvider)   
{   
    print("** Credential Provider[" + index + "] " + credentialProvider.getId() + " " +     credentialProvider.getCredentialProviderModelId() + " *");   
    if (credentialProvider.getCredentialProviderModelId() == "org.ametys.core.authentication.FormBased"   
&& credentialProvider.getParameterValues().get("runtime.authentication.form.captcha") == true)   
    {   
        var datasourceId = credentialProvider.getParameterValues().get("runtime.authentication.form.security.storage");   
        var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
        var requests = [];   

        switch (dbType)   
        {   
            case "derby":   
                requests.push("ALTER TABLE Users_FormConnectionFailed ADD COLUMN login2 varchar(64) NOT NULL DEFAULT 'nonnull'");   
                requests.push("UPDATE Users_FormConnectionFailed SET login2=login");   
                requests.push("ALTER TABLE Users_FormConnectionFailed DROP COLUMN login");   
                requests.push("RENAME COLUMN Users_FormConnectionFailed.login2 TO login");   
                requests.push("ALTER TABLE Users_FormConnectionFailed ADD PRIMARY KEY(login)");   
                break;   
            case "mysql":   
                requests.push("ALTER TABLE Users_FormConnectionFailed MODIFY login VARCHAR(64) BINARY");   
                requests.push("ALTER TABLE Users_FormConnectionFailed MODIFY population_id VARCHAR(200) BINARY");   
                break;   
            case "oracle":   
                requests.push("ALTER TABLE Users_FormConnectionFailed MODIFY (login VARCHAR(64))");   
                break;   
            case "postgresql":   
                requests.push("ALTER TABLE Users_FormConnectionFailed ALTER COLUMN login TYPE VARCHAR(64)");   
                break;   
            case "hsqldb":   
                requests.push("ALTER TABLE Users_FormConnectionFailed ALTER COLUMN login VARCHAR(64)");   
                break;   
            default:   
                throw new Error("Unknown database type " + dbType)   
        }   

        _execute("_updateCredentialProvider", dbType, requests, datasourceId);   
    }   
}   

function updateUserSignupTables()   
{   
    var datasourceId = Config.getInstance().getValue("web.usersignup.datasource");   
    if (datasourceId == null)   
    {   
        print("...No web signup plugin...");   
        return;   
    }   
    var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
    var requests = [];   

    switch (dbType)   
    {   
        case "derby":   
            requests.push("ALTER TABLE Users_Temp ADD COLUMN userDirectory2 varchar(200) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Users_Temp SET userDirectory2=userDirectory");   
            requests.push("ALTER TABLE Users_Temp DROP COLUMN userDirectory");   
            requests.push("RENAME COLUMN Users_Temp.userDirectory2 TO userDirectory");   
            requests.push("ALTER TABLE Users_Temp ADD COLUMN population2 varchar(200) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Users_Temp SET population2=population");   
            requests.push("ALTER TABLE Users_Temp DROP COLUMN population");   
            requests.push("RENAME COLUMN Users_Temp.population2 TO population");   
            requests.push("ALTER TABLE Users_PasswordChange ADD COLUMN population2 varchar(200) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Users_PasswordChange SET population2=population");   
            requests.push("ALTER TABLE Users_PasswordChange DROP COLUMN population");   
            requests.push("RENAME COLUMN Users_PasswordChange.population2 TO population");   
            requests.push("ALTER TABLE Users_PasswordChange ADD COLUMN login2 varchar(64) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Users_PasswordChange SET login2=login");   
            requests.push("ALTER TABLE Users_PasswordChange DROP COLUMN login");   
            requests.push("RENAME COLUMN Users_PasswordChange.login2 TO login");   
            requests.push("ALTER TABLE Users_PasswordChange ADD PRIMARY KEY(site, login, population)");   
            break;   
        case "mysql":   
            requests.push("ALTER TABLE Users_Temp MODIFY userDirectory VARCHAR(200) BINARY");   
            requests.push("ALTER TABLE Users_Temp MODIFY population VARCHAR(200) BINARY");   
            requests.push("ALTER TABLE Users_PasswordChange MODIFY login VARCHAR(64) BINARY");   
            requests.push("ALTER TABLE Users_PasswordChange MODIFY population VARCHAR(200) BINARY");   
            requests.push("ALTER TABLE Users_PasswordChange DROP PRIMARY KEY, ADD PRIMARY KEY(site, login, population)");   
            break;   
        case "oracle":   
            requests.push("ALTER TABLE Users_Temp MODIFY (userDirectory VARCHAR(200))");   
            requests.push("ALTER TABLE Users_Temp MODIFY (population VARCHAR(200))");   
            requests.push("ALTER TABLE Users_PasswordChange MODIFY (login VARCHAR(64))");   
            requests.push("ALTER TABLE Users_PasswordChange MODIFY (population VARCHAR(200))");   

            requests.push("ALTER TABLE Users_PasswordChange DROP CONSTRAINT pk_users_passwordchange");   
            requests.push("ALTER TABLE Users_PasswordChange ADD CONSTRAINT pk_users_passwordchange PRIMARY KEY (site, login, population)");   
            break;   
        case "postgresql":   
            requests.push("ALTER TABLE Users_Temp ALTER COLUMN userDirectory TYPE VARCHAR(200)");   
            requests.push("ALTER TABLE Users_Temp ALTER COLUMN population TYPE VARCHAR(200)");   
            requests.push("ALTER TABLE Users_PasswordChange ALTER COLUMN login TYPE VARCHAR(64)");   
            requests.push("ALTER TABLE Users_PasswordChange ALTER COLUMN population TYPE VARCHAR(200)");   
            requests.push("ALTER TABLE Users_PasswordChange DROP CONSTRAINT Users_PasswordChange_pkey, ADD PRIMARY KEY(site, login, population)");   
            break;   
        case "hsqldb":   
            requests.push("ALTER TABLE Users_Temp ALTER COLUMN userDirectory VARCHAR(200)");   
            requests.push("ALTER TABLE Users_Temp ALTER COLUMN population VARCHAR(200)");   
            requests.push("ALTER TABLE Users_PasswordChange ALTER COLUMN login VARCHAR(64)");   
            requests.push("ALTER TABLE Users_PasswordChange ALTER COLUMN population VARCHAR(200)");   
            var rs = sqlQuery("SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE LCASE(TABLE_NAME) = LCASE('Users_PasswordChange') and CONSTRAINT_NAME like 'SYS_PK_%'", datasourceId);   
rs.next();   
            var constraint = rs.getString(1);   
            requests.push("ALTER TABLE Users_PasswordChange DROP CONSTRAINT " + constraint);   
            requests.push("ALTER TABLE Users_PasswordChange ADD PRIMARY KEY(site, login, population)");   
            break;   
        default:   
            throw new Error("Unknown database type " + dbType)   
    }   

    _execute("updateUserSignupTables", dbType, requests, datasourceId);   
}   

function updateSurveyTables()   
{   
    var datasourceId = Config.getInstance().getValue("plugins.survey.datasource");   
    if (datasourceId == null)   
    {   
        print("...No survey plugin...");   
        return;   
    }   
    var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
    var requests = [];   

    switch (dbType)   
    {   
        case "derby":   
            requests.push("ALTER TABLE Survey_Session ADD COLUMN population2 varchar(200) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Survey_Session SET population2=population");   
            requests.push("ALTER TABLE Survey_Session DROP COLUMN population");   
            requests.push("RENAME COLUMN Survey_Session.population2 TO population");   
            break;   
        case "mysql":   
            requests.push("ALTER TABLE Survey_Session MODIFY login VARCHAR(64) BINARY");   
            requests.push("ALTER TABLE Survey_Session MODIFY population VARCHAR(200) BINARY");   
            break;   
        case "oracle":   
            requests.push("ALTER TABLE Survey_Session MODIFY population VARCHAR(200)");   
            break;   
        case "postgresql":   
            requests.push("ALTER TABLE Survey_Session ALTER COLUMN population TYPE VARCHAR(200)");   
            break;   
        /* HSQLDB is not supported in survey */   
        default:   
            throw new Error("Unknown database type " + dbType)   
    }   

    _execute("updateSurveyTables", dbType, requests, datasourceId);   
}   

function updateUserPreferencesTables()   
{   
    var datasourceId = Config.getInstance().getValue("runtime.usersprefs.datasource");   
    var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
    var requests = [];   

    switch (dbType)   
    {   
        case "derby":   
            requests.push("ALTER TABLE UserPreferences ADD COLUMN login2 varchar(64) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE UserPreferences SET login2=login");   
            requests.push("ALTER TABLE UserPreferences DROP COLUMN login");   
            requests.push("RENAME COLUMN UserPreferences.login2 TO login");   
            requests.push("ALTER TABLE UserPreferences ADD PRIMARY KEY(login, population, context)");   
            break;   
        case "mysql":   
            requests.push("ALTER TABLE UserPreferences MODIFY login varchar(64) BINARY");   
            requests.push("ALTER TABLE UserPreferences MODIFY population varchar(200) BINARY");   
            break;   
        case "oracle":   
            requests.push("ALTER TABLE UserPreferences MODIFY (login varchar(64))");   
            break;   
        case "postgresql":   
            requests.push("ALTER TABLE UserPreferences ALTER COLUMN login TYPE varchar(64)");   
            break;   
        case "hsqldb":   
            requests.push("ALTER TABLE UserPreferences ALTER COLUMN login varchar(64)");   
            break;   
        default:   
            throw new Error("Unknown database type " + dbType)   
    }   

    _execute("updateUserPreferencesTables", dbType, requests, datasourceId);   
}   

function updateAuhenticationTokenTables()   
{   
    var datasourceId = Config.getInstance().getValue("runtime.assignments.authenticationtokens");   
    var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
    var requests = [];   

    switch (dbType)   
    {   
        case "mysql":   
            requests.push("ALTER TABLE Authentication_Token MODIFY login varchar(64) BINARY");   
            requests.push("ALTER TABLE Authentication_Token MODIFY population_id varchar(200) BINARY");   
            break;   
        case "derby":   
        case "oracle":   
        case "postgresql":   
        case "hsqldb":   
            // Nothing   
            break;   
        default:   
            throw new Error("Unknown database type " + dbType)   
    }   

    _execute("updateAuhenticationTokenTables", dbType, requests, datasourceId);   
}   

function updateRightsTables()   
{   
    var datasourceId = Config.getInstance().getValue("runtime.rights.datasource");   
    var dbType = SQLDataSourceManager.getDataSourceDefinition(datasourceId).getParameters().get("dbtype");   
    var requests = [];   

    switch (dbType)   
    {   
        case "derby":   
            requests.push("ALTER TABLE Rights_AllowedUsers ADD COLUMN Login2 varchar(64) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Rights_AllowedUsers SET Login2=Login");   
            requests.push("ALTER TABLE Rights_AllowedUsers DROP COLUMN Login");   
            requests.push("RENAME COLUMN Rights_AllowedUsers.Login2 TO Login");   
            requests.push("ALTER TABLE Rights_AllowedUsers ADD PRIMARY KEY(Profile_Id, Login, UserPopulation_Id, Context)");   
            requests.push("ALTER TABLE Rights_DeniedUsers ADD COLUMN Login2 varchar(64) NOT NULL DEFAULT 'nonnull'");   
            requests.push("UPDATE Rights_DeniedUsers SET Login2=Login");   
            requests.push("ALTER TABLE Rights_DeniedUsers DROP COLUMN Login");   
            requests.push("RENAME COLUMN Rights_DeniedUsers.Login2 TO Login");   
            requests.push("ALTER TABLE Rights_DeniedUsers ADD PRIMARY KEY(Profile_Id, Login, UserPopulation_Id, Context)");   
            break;   
        case "mysql":   
            requests.push("ALTER TABLE Rights_AllowedUsers MODIFY Login varchar(64) BINARY");   
            requests.push("ALTER TABLE Rights_AllowedUsers MODIFY UserPopulation_Id varchar(200) BINARY");   
            requests.push("ALTER TABLE Rights_DeniedUsers MODIFY Login varchar(64) BINARY");   
            requests.push("ALTER TABLE Rights_DeniedUsers MODIFY UserPopulation_Id varchar(200) BINARY");   
            break;   
        case "oracle":   
            requests.push("ALTER TABLE Rights_AllowedUsers MODIFY Login varchar(64)");   
            requests.push("ALTER TABLE Rights_DeniedUsers MODIFY Login varchar(64)");   
            break;   
        case "postgresql":   
            requests.push("ALTER TABLE Rights_AllowedUsers ALTER COLUMN Login TYPE varchar(64)");   
            requests.push("ALTER TABLE Rights_DeniedUsers ALTER COLUMN Login TYPE varchar(64)");   
            break;   
        case "hsqldb":   
            requests.push("ALTER TABLE Rights_AllowedUsers ALTER COLUMN Login varchar(64)");   
            requests.push("ALTER TABLE Rights_DeniedUsers ALTER COLUMN Login varchar(64)");   
            break;   
        default:   
            throw new Error("Unknown database type " + dbType)   
    }   

    _execute("updateRightsTables", dbType, requests, datasourceId);   
}   

function _execute(label, dbType, requests, datasourceId)   
{   
    print("*********************************************************")   
    print("* " + label + " on " + datasourceId + " (" + dbType + ") *");   
    print("*********************************************************")   

    for (var i=0; i < requests.length; i++)   
    {   
        print(" " + requests[i]);   
    sqlUpdate(requests[i],datasourceId)   
    }   

    print(" OK")   
}   

Modification of legal identifier

The identifier of the right to manage 'parameter files' has changed, so the following script must be passed:

var datasourceId = org.ametys.runtime.config.Config.getInstance().getValue("runtime.rights.datasource");                 
var oldRight = 'CMS_Rights_EditParameterFile';                 
var newRight = 'CORE_Rights_EditParameterFile';                 
var query = "UPDATE Rights_ProfileRights SET Right_Id = '" + newRight + "' WHERE Right_Id = '" + oldRight + "'";                 
sqlUpdate(query, datasourceId);                 

Inheritance of rights disabled

Following the addition of the ability to disable assignment inheritance on a given context, a new SQL table is required.

Pass this script on the site application as well.

var Config = Java.type("org.ametys.runtime.config.Config");                  
var SQLDataSourceManager = serviceManager.lookup("org.ametys.core.datasource.SQLDataSourceManager");                  
var dataSourceId = Config.getInstance().getValue("runtime.rights.datasource");                     

var dbType = SQLDataSourceManager.getDataSourceDefinition(dataSourceId).getParameters().get("dbtype");                  

switch(dbType)                  
{                  
    case "derby":                     
        sqlUpdate("CREATE TABLE Rights_Inheritance(Context VARCHAR(200) NOT NULL, Disallow SMALLINT, PRIMARY KEY(Context, Disallow))", dataSourceId);                       
        break;                  
    case "mysql":                  
        sqlUpdate("CREATE TABLE Rights_Inheritance(Context VARCHAR(200) NOT NULL, Disallow BOOLEAN, PRIMARY KEY(Context, Disallow))ENGINE=innodb CHARACTER SET utf8", dataSourceId);                       
        break;                  
    case "oracle":                  
        sqlUpdate("CREATE TABLE Rights_Inheritance(Context VARCHAR(200) NOT NULL, Disallow NUMBER(1) DEFAULT 0 NOT NULL, PRIMARY KEY(Context, Disallow))", dataSourceId);                       
        break;                  
    case "postgresql":                  
        sqlUpdate("CREATE TABLE Rights_Inheritance(Context VARCHAR(200) NOT NULL, Disallow BOOLEAN, PRIMARY KEY(Context, Disallow))", dataSourceId);                       
        break;                  
    case "hsqldb":                  
        sqlUpdate("CREATE TABLE Rights_Inheritance(Context VARCHAR(200) NOT NULL, Disallow BOOLEAN, PRIMARY KEY(Context, Disallow))", dataSourceId);                       
        break;                  
    default:                  
        throw new Error("Unknown database type " + dbType);                  
}                  

Data migration JCR

Before applying the migration scripts JCR, delete the file repository/nodetypes/custom_nodetypes.xml then restart the server.

Do not run the scripts if your application starts in safe mode.

Reserved key words

Certain keywords are now reserved and can no longer be used as field names in your content types (see Technical migration 4.2 to 4.3).

The following script provides an example of how to migrate your data in the event of a conflict involving the reserved attribute "site".
You can use this as inspiration to resolve other conflicts.

This script should only be skipped if a conflict was detected during the technical migration.

The first 2 variables can be customized:

var contentType = "org.ametys.plugin.organisation.Content.agent"; // TO PERSONALIZED : id of concerned content type         
var newName = "location"; // TO PERSONALIZED the new name for attribute         
var count = 0;         

function _moveSiteAttribute(content)         
{         
    // Move property 
    if (content.getNode().hasProperty("ametys:site") && !content.getNode().hasProperty("ametys:" + newName))
    {
        var value = content.getNode().getProperty("ametys:site").getValue();         
        content.getNode().setProperty("ametys:" + newName, value);         
    }

    // Try to get real site name         
    var siteName =_getSiteName(content)         
    if (siteName != null)         
    {         
        content.getNode().setProperty("ametys:site", siteName);         
    }         
    else         
    {         
        // No site, remove property         
        content.getNode().getProperty("ametys:site").remove();         
    }         

    count++;         
}         

function _getSiteName(content)         
{         
    var parent = content.getNode().getParent();         
    while (parent != null && parent.getPrimaryNodeType().getName() != 'ametys:root')         
    {         
        if (parent.getPrimaryNodeType().getName() == 'ametys:site')         
        {         
            return parent.getName();         
        }         
        parent = parent.getParent();         
    }         
    return null;         
}         

jcrXPathQuery("//element(*, ametys:content)[@ametys-internal:contentType='" + contentType + "' and @ametys:site and not(@ametys:" + newName + ")]")         
    .forEach(function (content)         
    {         
        migrateContent(         
            content,         
            [_moveSiteAttribute],         
            false /* old versions incompatible */,         
            null /* no tag */,         
            false /* not verbose */         
        );         
    }         
);         

print(count + " contents have been migrated");         
if (count > 0)         
{         
    print("=> BUILD THE LIVE WORKSPACE");         
}  

Warning counter

The counter for the number of times a comment has been flagged has been renamed.

var qm = session.getWorkspace().getQueryManager();               
var query = qm.createQuery("//element(ametys:comments, ametys:compositeMetadata)", javax.jcr.query.Query.XPATH);               
var commentsNodes = query.execute().getNodes();               
var count = 0;               
while (commentsNodes.hasNext())               
{               
  var commentsNode = commentsNodes.nextNode();               
  var commentNodes = commentsNode.getNodes("ametys:comment-*");               
  while (commentNodes.hasNext())               
  {               
    var commentNode = commentNodes.nextNode();               
    if (commentNode.hasProperty("ametys:nb-reporters"))               
    {               
      var property = commentNode.getProperty("ametys:nb-reporters");               
      ConsoleHelper.setProperty(commentNode, "ametys:reportsCount", property.getLong());              
      property.remove();               
      count++;               
    }               
  }               
}               
if (count > 0)               
{               
  session.save();               
  print(count + " comments migrated");               
}               

Setting up automatic migration components

Attention, pour une migration d'une version <= 4.4 vers une version >= 4.7, il faut le faire en deux étapes : d'abord migrer vers 4.5 puis vers la version cible.

To make future migrations easier to apply, components are now available to automatically perform certain migrations. However, an initial manual migration is required to initialize the application state.

It is necessary to pass these two scripts, one adding version management to the JCR repository, the other adding version management to the databases:

In 4.3

var logger = Ametys.getLogger("migration.manual4jcr");            

logger.info("Begin of the manual initialization for automatic JCR Data component's migration");            

logger.info("Components preparation");            
const JcrDataVersion = Java.type("org.ametys.plugins.repository.migration.jcr.data.JcrDataVersion");            
const _migrationEP = Ametys.serviceManager.lookup("org.ametys.core.migration.MigrationExtensionPoint");            
const _versionsRootHelper = Ametys.serviceManager.lookup("org.ametys.plugins.repository.migration.jcr.data.VersionsRootHelper");            
const _versionHandlerEP = Ametys.serviceManager.lookup("org.ametys.core.migration.handler.VersionHandlerExtensionPoint");            
const _jcrVersionHandler = _versionHandlerEP.getExtension("jcr-data");            

logger.info("Iterate on migration components");            
_migrationEP.getExtensionsIds().forEach(            
    extensionId =>            
    {            
        logger.info("Component " + extensionId);            
        var extension = _migrationEP.getExtension(extensionId);            
        var versionConfigurations = extension.getConfiguration().getChild("versions").getChildren("version");            
        for (var versionConfiguration of versionConfigurations)            
        {            
            if (versionConfiguration.getAttribute("type") == "jcr-data")            
            {            
                logger.info("Version jcr-data found");            
                try            
                {            
                    _jcrVersionHandler.getCurrentVersions(extensionId, versionConfiguration);            
                    // Migration is not failing            
                }            
                catch (e)            
                {            
                    logger.info("Needed migration");            
                    // Migration is failing            
                    var version = new JcrDataVersion("jcr-data", extensionId);            
                    version.setVersionNumber("0");            
                    version.setComment("Manual initialization.");            
                    _jcrVersionHandler.addVersion(version);            
                }            
            }            
        }            
    }            
);            

logger.info("Update of known plugins");            
_versionsRootHelper.updateKnownPlugins();            

logger.info("End of the manual initialization for automatic JCR Data component's migration");            
var logger = Ametys.getLogger("migration.manual4sql");            

logger.info("Begin of the manual initialization for automatic SQL component's migration");            

logger.info("Components preparation");            
const _migrationEP = Ametys.serviceManager.lookup("org.ametys.core.migration.MigrationExtensionPoint");            
const _versionHandlerEP = Ametys.serviceManager.lookup("org.ametys.core.migration.handler.VersionHandlerExtensionPoint");            
const _sqlVersionHandler = _versionHandlerEP.getExtension("sql");            

logger.info("Iterate on migration components");            
_migrationEP.getExtensionsIds().forEach(            
    extensionId =>            
    {            
        logger.info("Component " + extensionId);            
        var extension = _migrationEP.getExtension(extensionId);            
        var versionConfigurations = extension.getConfiguration().getChild("versions").getChildren("version");            
        for (var versionConfiguration of versionConfigurations)            
        {            
            if (versionConfiguration.getAttribute("type") == "sql")            
            {            
                logger.info("Version sql found");            
                try            
                {            
                    var versionsObj = _sqlVersionHandler.getCurrentVersions(extensionId, versionConfiguration);            
                    for (var version of versionsObj)            
                    {            
                        if (version.getVersionNumber() == null)            
                        {            
                            logger.info("Needed migration");            
                            // Migration is failing            
                            version.setVersionNumber("0");            
                            version.setComment("Manual initialization.");            
                            _sqlVersionHandler.addVersion(version);            
                        }            
                    }            
                }            
                catch (e)            
                {            
                    logger.error("Error during manual migration", e);            
                }            
            }            
        }            
    }            
);           

logger.info("End of the manual initialization for automatic SQL component's migration");          

The second script must also be run on data from theAmetyswebsite application.

After applying these scripts, Ametys will require a restart to pass any available automatic migrations.

In 4.4

var logger = Ametys.getLogger("migration.manual4jcr");            

logger.info("Begin of the manual initialization for automatic JCR Data component's migration");            

logger.info("Components preparation");            
const JcrDataVersion = Java.type("org.ametys.plugins.repository.migration.jcr.data.JcrDataVersion");            
const _migrationEP = Ametys.serviceManager.lookup("org.ametys.core.migration.MigrationExtensionPoint");            
const _versionsRootHelper = Ametys.serviceManager.lookup("org.ametys.plugins.repository.migration.jcr.data.VersionsRootHelper");            
const _versionHandlerEP = Ametys.serviceManager.lookup("org.ametys.core.migration.handler.VersionHandlerExtensionPoint");            
const _jcrVersionHandler = _versionHandlerEP.getExtension("jcr-data");            

logger.info("Iterate on migration components");            
_migrationEP.getExtensionsIds().forEach(            
    extensionId =>            
    {            
        logger.info("Component " + extensionId);            
        var extension = _migrationEP.getExtension(extensionId);            
        var versionConfigurations = extension.getConfiguration().getChild("versions").getChildren("version");            
        for (var versionConfiguration of versionConfigurations)            
        {            
            if (versionConfiguration.getAttribute("type") == "jcr-data")            
            {            
                logger.info("Version jcr-data found");            
                try            
                {            
                    var configuration = _jcrVersionHandler.getConfiguration(extensionId, versionConfiguration);
                    var versionsObj = _jcrVersionHandler.getCurrentVersions(extensionId, configuration);
                    // Migration is not failing            
                }            
                catch (e)            
                {            
                    logger.info("Needed migration");            
                    // Migration is failing            
                    var version = new JcrDataVersion("jcr-data", extensionId);            
                    version.setVersionNumber("0");            
                    version.setComment("Manual initialization.");            
                    _jcrVersionHandler.addVersion(version);            
                }            
            }            
        }            
    }            
);            

logger.info("Update of known plugins");            
_versionsRootHelper.updateKnownPlugins();            

logger.info("End of the manual initialization for automatic JCR Data component's migration");            
var logger = Ametys.getLogger("migration.manual4sql");            

logger.info("Begin of the manual initialization for automatic SQL component's migration");            

logger.info("Components preparation");            
const _migrationEP = Ametys.serviceManager.lookup("org.ametys.core.migration.MigrationExtensionPoint");            
const _versionHandlerEP = Ametys.serviceManager.lookup("org.ametys.core.migration.handler.VersionHandlerExtensionPoint");            
const _sqlVersionHandler = _versionHandlerEP.getExtension("sql");            

logger.info("Iterate on migration components");            
_migrationEP.getExtensionsIds().forEach(            
    extensionId =>            
    {            
        logger.info("Component " + extensionId);            
        var extension = _migrationEP.getExtension(extensionId);            
        var versionConfigurations = extension.getConfiguration().getChild("versions").getChildren("version");            
        for (var versionConfiguration of versionConfigurations)            
        {            
            if (versionConfiguration.getAttribute("type") == "sql")            
            {            
                logger.info("Version sql found");            
                try            
                {            
                    var configuration = _sqlVersionHandler.getConfiguration(extensionId, versionConfiguration);
                    var versionsObj = _sqlVersionHandler.getCurrentVersions(extensionId, configuration);
                    for (var version of versionsObj)            
                    {            
                        if (version.getVersionNumber() == null)            
                        {            
                            logger.info("Needed migration");            
                            // Migration is failing            
                            version.setVersionNumber("0");            
                            version.setComment("Manual initialization.");            
                            _sqlVersionHandler.addVersion(version);            
                        }            
                    }            
                }            
                catch (e)            
                {            
                    logger.error("Error during manual migration", e);            
                }            
            }            
        }            
    }            
);           

logger.info("End of the manual initialization for automatic SQL component's migration");  

The second script must also be run on data from theAmetyswebsite application.

After applying these scripts, Ametys will require a restart to pass any available automatic migrations.

In 4.7

var logger = Ametys.getLogger("migration.manual4jcr"); 

logger.info("Begin of the manual initialization for automatic JCR Data component's migration"); 

logger.info("Components preparation"); 
const _migrationEP = Ametys.serviceManager.lookup("org.ametys.core.migration.MigrationExtensionPoint"); 
const _versionsRootHelper = Ametys.serviceManager.lookup("org.ametys.plugins.repository.migration.jcr.VersionsRootHelper"); 

logger.info("Iterate on migration components"); 
_migrationEP.getExtensionsIds().forEach( extensionId => { 
   logger.info("Component '" + extensionId + "'"); 
   const component = _migrationEP.getExtension(extensionId); 
   if (component.versionHandlerType() === "jcr") 
   { 
       logger.info("Version jcr found"); 
       try 
       { 
           const versionsObj = component.versionHandler().getVersions(component); 
           // Migration is not failing 
       } 
       catch (e) 
       { 
           logger.info("Needed migration"); 
           // Migration is failing 
           Migration.addVersion(extensionId, null, null, "0", "Manual initialization"); 
       } 
   } 
}); 

logger.info("Update of known plugins"); 
_versionsRootHelper.updateKnownPlugins(); 

logger.info("End of the manual initialization for automatic JCR Data component's migration");
// TODO SQL



The script must also be run on the data of theAmetys application site.

After applying these scripts, Ametys will require a restart to pass any available automatic migrations.

Back to top