Les scripts des tables SQL contenant des logins ont été harmonisées et permettent une recherche par login ou population en respectant la casse.
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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")
}
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")
}
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 d'identifiant de droit
L'identifiant du droit pour gérer les 'fichiers de paramètre' a changé, il faut passer le script suivant :
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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);
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);
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);
Désactivation de l'héritage des droits
Suite à la l'ajout de la possibilité de désactiver l'héritage des affectations sur un contexte donné, une nouvelle table SQL est nécessaire.
Passez ce script sur l'application site également.
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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);
}
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);
}
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);
}
Migration des données JCR
Avant d'appliquer les scripts de migration JCR, supprimez le fichier repository/nodetypes/custom_nodetypes.xml puis redémarrer le serveur.
N'exécutez pas les scripts si votre application démarre en mode sans échec.
Mots clés réservés
Certains mots clés sont désormais réservés et ne peuvent plus être utilisés comme nom de champs dans vos types de contenus (voir Migration technique 4.2 vers 4.3)
Le script ci-après fournit un exemple pour migrer vos données lorsqu'un conflit concerne l'attribut réservé "site". Vous pouvez vous en inspirer pour régler d'autres conflits.
Ce script est à passé uniquement si un conflit a été détecté lors de la migration technique.
Les 2 premières variables sont à personnaliser :
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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");
}
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");
}
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");
}
Compteur de signalements
Le compteur du nombre de signalements d'un commentaire a été renommé.
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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");
}
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");
}
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");
}
Mise en place des composants de migrations automatiques
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.
Pour que les migrations futures soient plus simples à appliquer, des composants destinés à passer certaines migrations automatiquement sont maintenant disponibles. Cependant, une première migration manuelle destinée à initialiser l'état de l'application est nécessaire.
Il est nécessaire de passer ces deux scripts, l'un ajoutant la gestion des versions dans le repository JCR, l'autre ajoutant la gestion des versions dans les bases de données :
En 4.3
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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.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.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");
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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");
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");
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");
Le deuxième script doit également être passé sur les données de l'application site d'Ametys.
Après l'application de ces scripts, Ametys nécessitera un redémarrage pour passer les éventuelles migrations automatiques disponibles.
En 4.4
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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.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.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");
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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");
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");
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");
Le deuxième script doit également être passé sur les données de l'application site d'Ametys.
Après l'application de ces scripts, Ametys nécessitera un redémarrage pour passer les éventuelles migrations automatiques disponibles.
En 4.7
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
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");
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");
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");
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
// TODO SQL
// TODO SQL
// TODO SQL
Le script doit également être passé sur les données de l'application site d'Ametys.
Après l'application de ces scripts, Ametys nécessitera un redémarrage pour passer les éventuelles migrations automatiques disponibles.