mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
MT - fixes for version2Store upgrade, skip SiteService patch
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11017 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1484,6 +1484,12 @@
|
|||||||
<property name="versionMigrator">
|
<property name="versionMigrator">
|
||||||
<ref bean="versionMigrator" />
|
<ref bean="versionMigrator" />
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tenantService">
|
||||||
|
<ref bean="tenantService" />
|
||||||
|
</property>
|
||||||
|
<property name="importerBootstrap">
|
||||||
|
<ref bean="version2Bootstrap" />
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="patch.inviteEmailTemplate" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
|
<bean id="patch.inviteEmailTemplate" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
|
||||||
|
@@ -507,6 +507,9 @@
|
|||||||
<entry key="versionMigrator">
|
<entry key="versionMigrator">
|
||||||
<ref bean="versionMigrator" />
|
<ref bean="versionMigrator" />
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry key="tenantAdminService">
|
||||||
|
<ref bean="tenantAdminService" />
|
||||||
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -27,7 +27,11 @@ package org.alfresco.repo.admin.patch.impl;
|
|||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.i18n.I18NUtil;
|
import org.alfresco.i18n.I18NUtil;
|
||||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||||
|
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.tenant.TenantService;
|
||||||
import org.alfresco.repo.version.VersionMigrator;
|
import org.alfresco.repo.version.VersionMigrator;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -41,6 +45,9 @@ public class MigrateVersionStorePatch extends AbstractPatch
|
|||||||
private static final String MSG_SUCCESS = "patch.migrateVersionStore.result";
|
private static final String MSG_SUCCESS = "patch.migrateVersionStore.result";
|
||||||
|
|
||||||
private VersionMigrator versionMigrator;
|
private VersionMigrator versionMigrator;
|
||||||
|
private TenantService tenantService;
|
||||||
|
private ImporterBootstrap version2ImporterBootstrap;
|
||||||
|
|
||||||
private int batchSize = 1;
|
private int batchSize = 1;
|
||||||
private boolean deleteImmediately = false;
|
private boolean deleteImmediately = false;
|
||||||
|
|
||||||
@@ -49,6 +56,16 @@ public class MigrateVersionStorePatch extends AbstractPatch
|
|||||||
this.versionMigrator = versionMigrator;
|
this.versionMigrator = versionMigrator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTenantService(TenantService tenantService)
|
||||||
|
{
|
||||||
|
this.tenantService = tenantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImporterBootstrap(ImporterBootstrap version2ImporterBootstrap)
|
||||||
|
{
|
||||||
|
this.version2ImporterBootstrap = version2ImporterBootstrap;
|
||||||
|
}
|
||||||
|
|
||||||
public void setBatchSize(int batchSize)
|
public void setBatchSize(int batchSize)
|
||||||
{
|
{
|
||||||
this.batchSize = batchSize;
|
this.batchSize = batchSize;
|
||||||
@@ -73,7 +90,17 @@ public class MigrateVersionStorePatch extends AbstractPatch
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String applyInternal() throws Exception
|
protected String applyInternal() throws Exception
|
||||||
{
|
{
|
||||||
|
if (tenantService.isEnabled() && tenantService.isTenantUser())
|
||||||
|
{
|
||||||
|
// bootstrap new version store
|
||||||
|
StoreRef bootstrapStoreRef = version2ImporterBootstrap.getStoreRef();
|
||||||
|
bootstrapStoreRef = tenantService.getName(AuthenticationUtil.getCurrentEffectiveUserName(), bootstrapStoreRef);
|
||||||
|
version2ImporterBootstrap.setStoreUrl(bootstrapStoreRef.toString());
|
||||||
|
|
||||||
|
version2ImporterBootstrap.bootstrap();
|
||||||
|
}
|
||||||
|
|
||||||
int vhCount = versionMigrator.migrateVersions(batchSize, deleteImmediately);
|
int vhCount = versionMigrator.migrateVersions(batchSize, deleteImmediately);
|
||||||
|
|
||||||
// build the result message
|
// build the result message
|
||||||
|
@@ -29,6 +29,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.alfresco.i18n.I18NUtil;
|
import org.alfresco.i18n.I18NUtil;
|
||||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.site.SiteInfo;
|
import org.alfresco.repo.site.SiteInfo;
|
||||||
import org.alfresco.repo.site.SiteModel;
|
import org.alfresco.repo.site.SiteModel;
|
||||||
import org.alfresco.repo.site.SiteService;
|
import org.alfresco.repo.site.SiteService;
|
||||||
@@ -37,6 +38,7 @@ import org.alfresco.service.cmr.security.AccessPermission;
|
|||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
|
import org.alfresco.util.EqualsHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch's the site permission model to use groups to contain users.
|
* Patch's the site permission model to use groups to contain users.
|
||||||
@@ -89,51 +91,59 @@ public class SitePermissionRefactorPatch extends AbstractPatch
|
|||||||
@Override
|
@Override
|
||||||
protected String applyInternal() throws Exception
|
protected String applyInternal() throws Exception
|
||||||
{
|
{
|
||||||
// Set all the sites in the repository
|
// NOTE: SiteService is not currently MT-enabled (eg. getSiteRoot) so skip if applied to tenant
|
||||||
List<SiteInfo> sites = this.siteService.listSites(null, null);
|
if (EqualsHelper.nullSafeEquals(
|
||||||
for (SiteInfo siteInfo : sites)
|
AuthenticationUtil.SYSTEM_USER_NAME,
|
||||||
|
AuthenticationUtil.getCurrentEffectiveUserName())
|
||||||
|
||
|
||||||
|
!AuthenticationUtil.isMtEnabled())
|
||||||
{
|
{
|
||||||
// Create the site's groups
|
// Set all the sites in the repository
|
||||||
String siteGroup = authorityService.createAuthority(
|
List<SiteInfo> sites = this.siteService.listSites(null, null);
|
||||||
AuthorityType.GROUP,
|
for (SiteInfo siteInfo : sites)
|
||||||
null,
|
{
|
||||||
((SiteServiceImpl)this.siteService).getSiteGroup(siteInfo.getShortName(),
|
// Create the site's groups
|
||||||
false));
|
String siteGroup = authorityService.createAuthority(
|
||||||
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
|
AuthorityType.GROUP,
|
||||||
for (String permission : permissions)
|
null,
|
||||||
{
|
((SiteServiceImpl)this.siteService).getSiteGroup(siteInfo.getShortName(),
|
||||||
// Create a group for the permission
|
false));
|
||||||
String permissionGroup = authorityService.createAuthority(
|
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||||
AuthorityType.GROUP,
|
for (String permission : permissions)
|
||||||
siteGroup,
|
{
|
||||||
((SiteServiceImpl)this.siteService).getSiteRoleGroup(
|
// Create a group for the permission
|
||||||
siteInfo.getShortName(),
|
String permissionGroup = authorityService.createAuthority(
|
||||||
permission,
|
AuthorityType.GROUP,
|
||||||
false));
|
siteGroup,
|
||||||
|
((SiteServiceImpl)this.siteService).getSiteRoleGroup(
|
||||||
// Assign the group the relevant permission on the site
|
siteInfo.getShortName(),
|
||||||
permissionService.setPermission(siteInfo.getNodeRef(), permissionGroup, permission, true);
|
permission,
|
||||||
}
|
false));
|
||||||
|
|
||||||
// Take the current members and assign them to the appropriate groups
|
// Assign the group the relevant permission on the site
|
||||||
Set<AccessPermission> currentPermissions = this.permissionService.getAllSetPermissions(siteInfo.getNodeRef());
|
permissionService.setPermission(siteInfo.getNodeRef(), permissionGroup, permission, true);
|
||||||
for (AccessPermission permission : currentPermissions)
|
}
|
||||||
{
|
|
||||||
// Only support user's being transfered (if public the everyone group will stay on the node)
|
// Take the current members and assign them to the appropriate groups
|
||||||
if (permission.getAuthorityType() == AuthorityType.USER)
|
Set<AccessPermission> currentPermissions = this.permissionService.getAllSetPermissions(siteInfo.getNodeRef());
|
||||||
{
|
for (AccessPermission permission : currentPermissions)
|
||||||
// Add this authority to the appropriate group
|
{
|
||||||
String group = ((SiteServiceImpl)this.siteService).getSiteRoleGroup(
|
// Only support user's being transfered (if public the everyone group will stay on the node)
|
||||||
siteInfo.getShortName(),
|
if (permission.getAuthorityType() == AuthorityType.USER)
|
||||||
permission.getPermission(),
|
{
|
||||||
true);
|
// Add this authority to the appropriate group
|
||||||
this.authorityService.addAuthority(group, permission.getAuthority());
|
String group = ((SiteServiceImpl)this.siteService).getSiteRoleGroup(
|
||||||
|
siteInfo.getShortName(),
|
||||||
// Remove the permission from the node
|
permission.getPermission(),
|
||||||
this.permissionService.deletePermission(siteInfo.getNodeRef(), permission.getAuthority(), permission.getPermission());
|
true);
|
||||||
}
|
this.authorityService.addAuthority(group, permission.getAuthority());
|
||||||
}
|
|
||||||
}
|
// Remove the permission from the node
|
||||||
|
this.permissionService.deletePermission(siteInfo.getNodeRef(), permission.getAuthority(), permission.getPermission());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Report status
|
// Report status
|
||||||
return I18NUtil.getMessage(STATUS_MSG);
|
return I18NUtil.getMessage(STATUS_MSG);
|
||||||
|
@@ -500,7 +500,7 @@ public class MultiTServiceImpl implements TenantService
|
|||||||
*/
|
*/
|
||||||
public boolean isTenantUser()
|
public boolean isTenantUser()
|
||||||
{
|
{
|
||||||
return isTenantUser(AuthenticationUtil.getCurrentUserName());
|
return isTenantUser(AuthenticationUtil.getCurrentEffectiveUserName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -567,7 +567,7 @@ public class MultiTServiceImpl implements TenantService
|
|||||||
*/
|
*/
|
||||||
public String getCurrentUserDomain()
|
public String getCurrentUserDomain()
|
||||||
{
|
{
|
||||||
String user = AuthenticationUtil.getCurrentUserName();
|
String user = AuthenticationUtil.getCurrentEffectiveUserName();
|
||||||
return getUserDomain(user);
|
return getUserDomain(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.version;
|
package org.alfresco.repo.version;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
|
import org.alfresco.repo.tenant.Tenant;
|
||||||
|
import org.alfresco.repo.tenant.TenantAdminService;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.quartz.Job;
|
import org.quartz.Job;
|
||||||
@@ -39,7 +45,9 @@ public class MigrationCleanupJob implements Job
|
|||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(MigrationCleanupJob.class);
|
private static Log logger = LogFactory.getLog(MigrationCleanupJob.class);
|
||||||
|
|
||||||
private static final String KEY_COMPONENT = "versionMigrator";
|
private static final String KEY_VERSION_MIGRATOR = "versionMigrator";
|
||||||
|
private static final String KEY_TENANT_ADMIN_SERVICE = "tenantAdminService";
|
||||||
|
|
||||||
private static final String KEY_BATCHSIZE = "batchSize";
|
private static final String KEY_BATCHSIZE = "batchSize";
|
||||||
|
|
||||||
private int batchSize = 1;
|
private int batchSize = 1;
|
||||||
@@ -47,10 +55,13 @@ public class MigrationCleanupJob implements Job
|
|||||||
public void execute(JobExecutionContext context) throws JobExecutionException
|
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||||
{
|
{
|
||||||
JobDataMap jobData = context.getJobDetail().getJobDataMap();
|
JobDataMap jobData = context.getJobDetail().getJobDataMap();
|
||||||
VersionMigrator migrationCleanup = (VersionMigrator)jobData.get(KEY_COMPONENT);
|
|
||||||
|
final VersionMigrator migrationCleanup = (VersionMigrator)jobData.get(KEY_VERSION_MIGRATOR);
|
||||||
|
final TenantAdminService tenantAdminService = (TenantAdminService)jobData.get(KEY_TENANT_ADMIN_SERVICE);
|
||||||
|
|
||||||
if (migrationCleanup == null)
|
if (migrationCleanup == null)
|
||||||
{
|
{
|
||||||
throw new JobExecutionException("Missing job data: " + KEY_COMPONENT);
|
throw new JobExecutionException("Missing job data: " + KEY_VERSION_MIGRATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
String batchSizeStr = (String)jobData.get(KEY_BATCHSIZE);
|
String batchSizeStr = (String)jobData.get(KEY_BATCHSIZE);
|
||||||
@@ -75,5 +86,22 @@ public class MigrationCleanupJob implements Job
|
|||||||
|
|
||||||
// perform the cleanup of the old version store
|
// perform the cleanup of the old version store
|
||||||
migrationCleanup.executeCleanup(batchSize);
|
migrationCleanup.executeCleanup(batchSize);
|
||||||
|
|
||||||
|
if ((tenantAdminService != null) && tenantAdminService.isEnabled())
|
||||||
|
{
|
||||||
|
List<Tenant> tenants = tenantAdminService.getAllTenants();
|
||||||
|
for (Tenant tenant : tenants)
|
||||||
|
{
|
||||||
|
String tenantDomain = tenant.getTenantDomain();
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||||
|
{
|
||||||
|
public Object doWork() throws Exception
|
||||||
|
{
|
||||||
|
migrationCleanup.executeCleanup(batchSize);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, tenantAdminService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user