mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ACE-2030: Clean up patches on unsupported upgrade paths to 5.0
88058: ACE-2030: Start process of retiring patches leading up to 4.0a 88061: ACE-2030: Remove unused SQL scripts for newly-retired patches 88062: ACE-2030: Change class names for all generic patches. 88064: ACE-2030: Remove unused patch implementation classes and fixes to get upgrade working again. 88067: ACE-2030: Clean up unused code and SQL for PatchDAO git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@88070 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Patch to update the activities email templates. Current templates become
|
||||
* versions of the new templates.
|
||||
*
|
||||
* @author Florian Mueller
|
||||
*/
|
||||
public class ActivitiesTemplatesUpdatePatch extends GenericEMailTemplateUpdatePatch
|
||||
{
|
||||
private Repository repository;
|
||||
|
||||
private static final String[] LOCALES = new String[] {"de", "es", "fr", "it", "ja"};
|
||||
private static final String PATH = "alfresco/templates/activities-email-templates/";
|
||||
private static final String BASE_FILE = "activities-email.ftl";
|
||||
private static final String XPATH ="/app:company_home/app:dictionary/app:email_templates/cm:activities/cm:activities-email.ftl";
|
||||
|
||||
public void setRepository(Repository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPath()
|
||||
{
|
||||
return PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBaseFileName()
|
||||
{
|
||||
return BASE_FILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getLocales()
|
||||
{
|
||||
return LOCALES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NodeRef getBaseTemplate()
|
||||
{
|
||||
List<NodeRef> refs = searchService.selectNodes(
|
||||
repository.getRootHome(),
|
||||
XPATH,
|
||||
null,
|
||||
namespaceService,
|
||||
false);
|
||||
if (refs.size() != 1)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(I18NUtil.getMessage("patch.activitiesTemplatesUpdate.error"));
|
||||
}
|
||||
return refs.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
|
||||
*/
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
updateTemplates();
|
||||
return I18NUtil.getMessage("patch.activitiesTemplatesUpdate.result");
|
||||
}
|
||||
}
|
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
public class ClearOldImapMessgesPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_REMOVED = "patch.imap.clear.old.messages.description.cleared";
|
||||
|
||||
private static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname";
|
||||
private static final String PROPERTY_DICTIONARY_CHILDNAME = "spaces.dictionary.childname";
|
||||
private static final String PROPERTY_SCRIPTS_CHILDNAME = "spaces.scripts.childname";
|
||||
private static final String PROPERTY_IMAP_CONFIG_CHILDNAME = "spaces.imapConfig.childname";
|
||||
private static final String PROPERTY_IMAP_TEMPLATES_CHILDNAME = "spaces.imap_templates.childname";
|
||||
|
||||
private ImporterBootstrap importerBootstrap;
|
||||
protected Properties configuration;
|
||||
private NodeRef imapTemplatesFolderNodeRef;
|
||||
|
||||
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||
{
|
||||
this.importerBootstrap = importerBootstrap;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
// get the node store that we must work against
|
||||
StoreRef storeRef = importerBootstrap.getStoreRef();
|
||||
if (storeRef == null)
|
||||
{
|
||||
throw new PatchException("Bootstrap store has not been set");
|
||||
}
|
||||
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
this.configuration = importerBootstrap.getConfiguration();
|
||||
// get the association names that form the path
|
||||
String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME);
|
||||
if (companyHomeChildName == null || companyHomeChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_COMPANY_HOME_CHILDNAME + "' is not present");
|
||||
}
|
||||
String dictionaryChildName = configuration.getProperty(PROPERTY_DICTIONARY_CHILDNAME);
|
||||
if (dictionaryChildName == null || dictionaryChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_DICTIONARY_CHILDNAME + "' is not present");
|
||||
}
|
||||
String scriptsChildName = configuration.getProperty(PROPERTY_SCRIPTS_CHILDNAME);
|
||||
if (scriptsChildName == null || scriptsChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_SCRIPTS_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
String imapConfigChildName = configuration.getProperty(PROPERTY_IMAP_CONFIG_CHILDNAME);
|
||||
if (imapConfigChildName == null || imapConfigChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_IMAP_CONFIG_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
String imapTemplatesChildName = configuration.getProperty(PROPERTY_IMAP_TEMPLATES_CHILDNAME);
|
||||
if (imapConfigChildName == null || imapConfigChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_IMAP_CONFIG_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
// build the search string to get the company home node
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("/").append(companyHomeChildName);
|
||||
sb.append("/").append(dictionaryChildName);
|
||||
sb.append("/").append(imapConfigChildName);
|
||||
sb.append("/").append(imapTemplatesChildName);
|
||||
|
||||
String xpath = sb.toString();
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
|
||||
if (nodeRefs.size() > 1)
|
||||
{
|
||||
throw new PatchException("XPath returned too many results: \n" + " root: " + storeRootNodeRef + "\n" + " xpath: " + xpath + "\n" + " results: " + nodeRefs);
|
||||
}
|
||||
else if (nodeRefs.size() == 0)
|
||||
{
|
||||
this.imapTemplatesFolderNodeRef = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.imapTemplatesFolderNodeRef = nodeRefs.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
setUp();
|
||||
if (imapTemplatesFolderNodeRef != null)
|
||||
{
|
||||
NodeRef oldTextPlain = nodeService.getChildByName(imapTemplatesFolderNodeRef, ContentModel.ASSOC_CONTAINS, "emailbody-textplain.ftl");
|
||||
NodeRef oldTextHTML = nodeService.getChildByName(imapTemplatesFolderNodeRef, ContentModel.ASSOC_CONTAINS, "emailbody-texthtml.ftl");
|
||||
|
||||
if (oldTextPlain != null)
|
||||
{
|
||||
nodeService.deleteNode(oldTextPlain);
|
||||
}
|
||||
if (oldTextHTML != null)
|
||||
{
|
||||
nodeService.deleteNode(oldTextHTML);
|
||||
}
|
||||
}
|
||||
|
||||
return I18NUtil.getMessage(MSG_REMOVED);
|
||||
}
|
||||
|
||||
}
|
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
public class ClearOldImapTemplatesPatch2 extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_REMOVED = "patch.imap.clear.old.messages.description.cleared";
|
||||
|
||||
private static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname";
|
||||
private static final String PROPERTY_DICTIONARY_CHILDNAME = "spaces.dictionary.childname";
|
||||
private static final String PROPERTY_SCRIPTS_CHILDNAME = "spaces.scripts.childname";
|
||||
private static final String PROPERTY_IMAP_CONFIG_CHILDNAME = "spaces.imapConfig.childname";
|
||||
private static final String PROPERTY_IMAP_TEMPLATES_CHILDNAME = "spaces.imap_templates.childname";
|
||||
|
||||
private ImporterBootstrap importerBootstrap;
|
||||
protected Properties configuration;
|
||||
private NodeRef imapTemplatesFolderNodeRef;
|
||||
|
||||
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||
{
|
||||
this.importerBootstrap = importerBootstrap;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
// get the node store that we must work against
|
||||
StoreRef storeRef = importerBootstrap.getStoreRef();
|
||||
if (storeRef == null)
|
||||
{
|
||||
throw new PatchException("Bootstrap store has not been set");
|
||||
}
|
||||
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
this.configuration = importerBootstrap.getConfiguration();
|
||||
// get the association names that form the path
|
||||
String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME);
|
||||
if (companyHomeChildName == null || companyHomeChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_COMPANY_HOME_CHILDNAME + "' is not present");
|
||||
}
|
||||
String dictionaryChildName = configuration.getProperty(PROPERTY_DICTIONARY_CHILDNAME);
|
||||
if (dictionaryChildName == null || dictionaryChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_DICTIONARY_CHILDNAME + "' is not present");
|
||||
}
|
||||
String scriptsChildName = configuration.getProperty(PROPERTY_SCRIPTS_CHILDNAME);
|
||||
if (scriptsChildName == null || scriptsChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_SCRIPTS_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
String imapConfigChildName = configuration.getProperty(PROPERTY_IMAP_CONFIG_CHILDNAME);
|
||||
if (imapConfigChildName == null || imapConfigChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_IMAP_CONFIG_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
String imapTemplatesChildName = configuration.getProperty(PROPERTY_IMAP_TEMPLATES_CHILDNAME);
|
||||
if (imapConfigChildName == null || imapConfigChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_IMAP_CONFIG_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
// build the search string to get the company home node
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("/").append(companyHomeChildName);
|
||||
sb.append("/").append(dictionaryChildName);
|
||||
sb.append("/").append(imapConfigChildName);
|
||||
sb.append("/").append(imapTemplatesChildName);
|
||||
|
||||
String xpath = sb.toString();
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
|
||||
if (nodeRefs.size() > 1)
|
||||
{
|
||||
throw new PatchException("XPath returned too many results: \n" + " root: " + storeRootNodeRef + "\n" + " xpath: " + xpath + "\n" + " results: " + nodeRefs);
|
||||
}
|
||||
else if (nodeRefs.size() == 0)
|
||||
{
|
||||
this.imapTemplatesFolderNodeRef = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.imapTemplatesFolderNodeRef = nodeRefs.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
setUp();
|
||||
if (imapTemplatesFolderNodeRef != null)
|
||||
{
|
||||
List<String> templatesToDelete = new ArrayList<String>();
|
||||
|
||||
templatesToDelete.add("emailbody-textplain.ftl");
|
||||
templatesToDelete.add("emailbody-textplain_de.ftl");
|
||||
templatesToDelete.add("emailbody-textplain_it.ftl");
|
||||
templatesToDelete.add("emailbody-textplain_fr.ftl");
|
||||
templatesToDelete.add("emailbody-textplain_ja.ftl");
|
||||
templatesToDelete.add("emailbody-textplain_es.ftl");
|
||||
|
||||
templatesToDelete.add("emailbody-texthtml.ftl");
|
||||
templatesToDelete.add("emailbody-texthtml_de.ftl");
|
||||
templatesToDelete.add("emailbody-texthtml_it.ftl");
|
||||
templatesToDelete.add("emailbody-texthtml_fr.ftl");
|
||||
templatesToDelete.add("emailbody-texthtml_ja.ftl");
|
||||
templatesToDelete.add("emailbody-texthtml_es.ftl");
|
||||
|
||||
for(String template : templatesToDelete)
|
||||
{
|
||||
NodeRef nodeRef = nodeService.getChildByName(imapTemplatesFolderNodeRef, ContentModel.ASSOC_CONTAINS, template);
|
||||
if(nodeRef != null)
|
||||
{
|
||||
nodeService.deleteNode(nodeRef);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return I18NUtil.getMessage(MSG_REMOVED);
|
||||
}
|
||||
|
||||
}
|
@@ -1,532 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.admin.patch.PatchExecuter;
|
||||
import org.alfresco.repo.batch.BatchProcessWorkProvider;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorkerAdaptor;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.node.NodeDAO.NodeRefQueryCallback;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Patch to break the link between {@link ContentModel#ASPECT_WORKING_COPY working copies}
|
||||
* and {@link ContentModel#ASPECT_COPIEDFROM copies}.
|
||||
* <p/>
|
||||
* Formerly, when a document was copied, it was given a <b>cm:source</b> property on the
|
||||
* <b>cm:copiedfrom</b> aspect - a <b>d:noderef</b> property. During checkout, the
|
||||
* working copy was given the <b>cm:workingcopy</b> aspect and the <b>cm:copiedfrom</b>
|
||||
* aspect was assumed to be present. However, the ordinality of the <b>cm:copiedfrom</b>'s
|
||||
* <b>cm:source</b> property didn't match up with the checkin-checkout 1:1 relationship.
|
||||
* <p/>
|
||||
* This patch works in two parts:
|
||||
* <p/>
|
||||
* <u><b>cm:copiedfrom</b></u><br/>
|
||||
* <ul>
|
||||
* <li><b>cm:source</b> is transformed into a peer association, <b>cm:original</b></li>
|
||||
* <li>The aspect is removed where the source no longer exists</li>
|
||||
* </ul>
|
||||
* <p/>
|
||||
* <u><b>cm:workingcopy</b></u><br/>
|
||||
* <ul>
|
||||
* <li><b>cm:source</b> is transformed into a peer association, <b>cm:workingcopylink</b></li>
|
||||
* <li>The original is given aspect <b>cm:checkedout</b></li>
|
||||
* <li>The copy keeps <b>cm:workingcopy</b></li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CopiedFromAspectPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.copiedFromAspect.result";
|
||||
|
||||
private PatchDAO patchDAO;
|
||||
private NodeDAO nodeDAO;
|
||||
private DictionaryService dictionaryService;
|
||||
private BehaviourFilter behaviourFilter;
|
||||
private RuleService ruleService;
|
||||
|
||||
private int batchThreads = 2;
|
||||
private int batchSize = 1000;
|
||||
private int batchMaxQueryRange = 10000;
|
||||
|
||||
private static Log logger = LogFactory.getLog(CopiedFromAspectPatch.class);
|
||||
private static Log progress_logger = LogFactory.getLog(PatchExecuter.class);
|
||||
|
||||
public CopiedFromAspectPatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param patchDAO additional queries
|
||||
*/
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeDAO provides query support
|
||||
*/
|
||||
public void setNodeDAO(NodeDAO nodeDAO)
|
||||
{
|
||||
this.nodeDAO = nodeDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService type and aspect resolution
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param behaviourFilter used to switch off <b>cm:auditable</b> behaviour
|
||||
*/
|
||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||
{
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ruleService used to disable rules
|
||||
*/
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param batchThreads the number of threads that will write child association changes
|
||||
*/
|
||||
public void setBatchThreads(int batchThreads)
|
||||
{
|
||||
this.batchThreads = batchThreads;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param batchSize the number of child associations that will be modified per transaction
|
||||
*/
|
||||
public void setBatchSize(int batchSize)
|
||||
{
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param batchMaxQueryRange the largest ID range that the work provider can query for.
|
||||
* Lower this if the DB resultset retrieval causes memory issues
|
||||
* prior to the {@link #setBatchQuerySize(int) query limit} being
|
||||
* applied.
|
||||
*/
|
||||
public void setBatchMaxQueryRange(int batchMaxQueryRange)
|
||||
{
|
||||
this.batchMaxQueryRange = batchMaxQueryRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
super.checkProperties();
|
||||
checkPropertyNotNull(patchDAO, "patchDAO");
|
||||
checkPropertyNotNull(nodeDAO, "nodeDAO");
|
||||
checkPropertyNotNull(dictionaryService, "dictionaryService");
|
||||
checkPropertyNotNull(applicationEventPublisher, "applicationEventPublisher");
|
||||
}
|
||||
|
||||
private CopiedFromAspectPatch write(FileChannel file, Object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
file.write(ByteBuffer.wrap(obj.toString().getBytes("UTF-8")));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Failed to write object to file: " + obj.toString());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private CopiedFromAspectPatch writeLine(FileChannel file, Object obj)
|
||||
{
|
||||
write(file, obj);
|
||||
write(file, "\n");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
// put the log file into a long life temp directory
|
||||
File tempDir = TempFileProvider.getLongLifeTempDir("patches");
|
||||
File logFile = new File(tempDir, "CopiedFromAspectPatch.log");
|
||||
|
||||
// open the file for appending
|
||||
RandomAccessFile outputFile = new RandomAccessFile(logFile, "rw");
|
||||
FileChannel file = outputFile.getChannel();
|
||||
try
|
||||
{
|
||||
// move to the end of the file
|
||||
file.position(file.size());
|
||||
// add a newline and it's ready
|
||||
writeLine(file, "").writeLine(file, "");
|
||||
writeLine(file, "CopiedFromAspectPatch.log executing on " + new Date());
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Starting CopiedFromAspectPatch. [Q=Query; P=Process]");
|
||||
}
|
||||
|
||||
int updated = process(file);
|
||||
// done
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS, updated, logFile);
|
||||
return msg;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { outputFile.close(); } catch (IOException e) {}
|
||||
try { file.close(); } catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual work, writing results to the given file channel
|
||||
|
||||
* @return Returns a status message after completion
|
||||
*/
|
||||
private int process(final FileChannel file)
|
||||
{
|
||||
// Authentication
|
||||
final String user = AuthenticationUtil.getRunAsUser();
|
||||
|
||||
Set<QName> qnames = new HashSet<QName>();
|
||||
qnames.add(ContentModel.ASPECT_COPIEDFROM);
|
||||
qnames.add(ContentModel.ASPECT_WORKING_COPY);
|
||||
|
||||
// Instance to provide raw data to process
|
||||
BatchProcessWorkProvider<Pair<Long, NodeRef>> workProvider = new WorkProvider(qnames);
|
||||
|
||||
// Instance to handle each item of work
|
||||
BatchProcessWorker<Pair<Long, NodeRef>> worker = new BatchProcessWorkerAdaptor<Pair<Long, NodeRef>>()
|
||||
{
|
||||
@Override
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
// Run as the correct user
|
||||
AuthenticationUtil.setRunAsUser(user);
|
||||
}
|
||||
@Override
|
||||
public void process(Pair<Long, NodeRef> entry) throws Throwable
|
||||
{
|
||||
// Disable auditable aspect
|
||||
behaviourFilter.disableBehaviour();
|
||||
// Disable rules
|
||||
ruleService.disableRules();
|
||||
try
|
||||
{
|
||||
CopiedFromAspectPatch.this.process(file, entry);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ruleService.enableRules();
|
||||
behaviourFilter.enableBehaviour();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
};
|
||||
|
||||
BatchProcessor<Pair<Long, NodeRef>> batchProcessor = new BatchProcessor<Pair<Long, NodeRef>>(
|
||||
"CopiedFromAspectPatch",
|
||||
transactionService.getRetryingTransactionHelper(),
|
||||
workProvider,
|
||||
this.batchThreads, this.batchSize,
|
||||
null,
|
||||
progress_logger,
|
||||
1000);
|
||||
int updated = batchProcessor.process(worker, true);
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work provider that performs incremental queries to find nodes with the
|
||||
* required aspects.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 4.0
|
||||
*/
|
||||
private class WorkProvider implements BatchProcessWorkProvider<Pair<Long, NodeRef>>
|
||||
{
|
||||
private long maxId = Long.MAX_VALUE;
|
||||
private long workCount = Long.MAX_VALUE;
|
||||
private long currentId = 0L;
|
||||
private final Set<QName> aspectQNames;
|
||||
|
||||
private WorkProvider(Set<QName> aspectQNames)
|
||||
{
|
||||
this.aspectQNames = aspectQNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getTotalEstimatedWorkSize()
|
||||
{
|
||||
if (maxId == Long.MAX_VALUE)
|
||||
{
|
||||
maxId = patchDAO.getMaxAdmNodeID();
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tQ: Max node id: " + maxId);
|
||||
}
|
||||
}
|
||||
if (workCount == Long.MAX_VALUE)
|
||||
{
|
||||
workCount = patchDAO.getCountNodesWithAspects(aspectQNames);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tQ: Work count: " + workCount);
|
||||
}
|
||||
}
|
||||
return (int) workCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Collection<Pair<Long, NodeRef>> getNextWork()
|
||||
{
|
||||
// Record the results
|
||||
final Set<Pair<Long, NodeRef>> results = new HashSet<Pair<Long, NodeRef>>(batchMaxQueryRange*2);
|
||||
// Record the node IDs for bulk loading
|
||||
final List<Long> nodeIds = new ArrayList<Long>(batchMaxQueryRange);
|
||||
|
||||
NodeRefQueryCallback callback = new NodeRefQueryCallback()
|
||||
{
|
||||
@Override
|
||||
public boolean handle(Pair<Long, NodeRef> nodePair)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tQ: Recording node work: " + nodePair);
|
||||
}
|
||||
results.add(nodePair);
|
||||
nodeIds.add(nodePair.getFirst());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
// Keep querying until we have enough results to give back
|
||||
int minResults = batchMaxQueryRange / 2;
|
||||
while (currentId <= maxId && results.size() < minResults)
|
||||
{
|
||||
nodeDAO.getNodesWithAspects(
|
||||
aspectQNames,
|
||||
currentId,
|
||||
currentId + batchMaxQueryRange,
|
||||
callback);
|
||||
// Increment the minimum ID
|
||||
currentId += batchMaxQueryRange;
|
||||
}
|
||||
// Preload the nodes for quicker access
|
||||
nodeDAO.cacheNodesById(nodeIds);
|
||||
// Done
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
private static final QName PROP_SOURCE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "source");
|
||||
private static final StoreRef VERSION_STORE = new StoreRef("workspace://version2Store"); // see http://wiki.alfresco.com/wiki/Version_Store
|
||||
/**
|
||||
* Does the per-node manipulation as stated in the class's docs
|
||||
*
|
||||
* @param file the file to write output to
|
||||
* @param nodePair the node to operate on
|
||||
*/
|
||||
private void process(FileChannel file, Pair<Long, NodeRef> nodePair)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Processing node: " + nodePair);
|
||||
}
|
||||
NodeRef nodeRef = nodePair.getSecond();
|
||||
// First check if the source property is present and valid
|
||||
NodeRef sourceNodeRef = DefaultTypeConverter.INSTANCE.convert(
|
||||
NodeRef.class,
|
||||
nodeService.getProperty(nodeRef, PROP_SOURCE));
|
||||
|
||||
// Does the source exist?
|
||||
if (sourceNodeRef == null || !nodeService.exists(sourceNodeRef))
|
||||
{
|
||||
boolean isNewModel = true;
|
||||
if (
|
||||
nodeService.hasAspect(nodeRef, ContentModel.ASPECT_COPIEDFROM) &&
|
||||
nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).size() == 0)
|
||||
{
|
||||
// There is no association pointing back to the original and the source node is invalid
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Removing cm:copiedfrom: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Removing cm:copiedfrom from node: " + nodePair);
|
||||
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_COPIEDFROM);
|
||||
isNewModel = false;
|
||||
}
|
||||
if (
|
||||
nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) &&
|
||||
nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK).size() == 0)
|
||||
{
|
||||
// There is no association from the checked out node and the source node is invalid
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Removing cm:workingcopy: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Removing cm:workingcopy from node: " + nodePair);
|
||||
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
|
||||
isNewModel = false;
|
||||
}
|
||||
// If nothing was done, then it's a node with the new data model and we can leave it
|
||||
if (isNewModel)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Ignoring data with new model: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Ignoring data with new model: " + nodePair);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The cm:source property points to a valid node.
|
||||
// This needs to be fixed up to use the new model.
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_COPIEDFROM))
|
||||
{
|
||||
if (nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).size() > 0)
|
||||
{
|
||||
// The association is already present, so just remove the property (we'll do that later)
|
||||
}
|
||||
else
|
||||
{
|
||||
QName sourceTypeQName = nodeService.getType(sourceNodeRef);
|
||||
// cm:copiedfrom target must be a cm:object
|
||||
if (dictionaryService.isSubClass(sourceTypeQName, ContentModel.TYPE_CMOBJECT))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Adding association cm:original: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Adding association cm:original: " + nodePair);
|
||||
nodeService.createAssociation(nodeRef, sourceNodeRef, ContentModel.ASSOC_ORIGINAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Removing incompatible aspect cm:copiedfrom " + nodePair);
|
||||
}
|
||||
writeLine(file, "Removing incompatible aspect cm:copiedfrom " + nodePair);
|
||||
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_COPIEDFROM);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
if (nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK).size() > 0)
|
||||
{
|
||||
// The association is already present, so just remove the property (we'll do that later)
|
||||
}
|
||||
else if (nodeService.hasAspect(sourceNodeRef, ContentModel.ASPECT_CHECKED_OUT))
|
||||
{
|
||||
// ALF-9569: copiedFromAspect patch does not take documents with
|
||||
// more than one working copy into account
|
||||
// So there are multiple working copies
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Found node with multiple working copies: " + sourceNodeRef);
|
||||
logger.debug("\tP: Removing cm:workingcopy: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Found node with multiple working copies: " + nodePair);
|
||||
writeLine(file, "Removing cm:workingcopy from node: " + nodePair);
|
||||
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
|
||||
}
|
||||
else if (!VERSION_STORE.equals(nodeRef.getStoreRef()))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Adding aspect cm:checkedout: " + sourceNodeRef);
|
||||
logger.debug("\tP: Adding association cm:workingcopylink: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Adding aspect cm:checkedout: " + sourceNodeRef);
|
||||
writeLine(file, "Adding association cm:workingcopylink to " + nodePair);
|
||||
// Add aspect to source
|
||||
nodeService.addAspect(sourceNodeRef, ContentModel.ASPECT_CHECKED_OUT, null);
|
||||
// Create the association
|
||||
nodeService.createAssociation(sourceNodeRef, nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ALF-11479:
|
||||
// - No cm:workingcopylink to the target node.
|
||||
// - Source node hasn't got the cm:checkedout aspect.
|
||||
// - But don't fix up the association, since the target node is in the version store
|
||||
// and *versions* of a working copy shouldn't have the cm:workingcopy aspect: there should
|
||||
// be one, and only one working copy.
|
||||
// - Therefore, remove this phantom cm:workingcopy aspect.
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("\tP: Found version of working copy marked as actual working copy: " + nodeRef);
|
||||
logger.debug("\tP: Removing cm:workingcopy: " + nodePair);
|
||||
}
|
||||
writeLine(file, "Found version of working copy marked as actual working copy: " + nodePair);
|
||||
writeLine(file, "Removing cm:workingcopy: " + nodePair);
|
||||
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove the property if it exists
|
||||
nodeService.removeProperty(nodeRef, PROP_SOURCE);
|
||||
}
|
||||
}
|
@@ -1,394 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.domain.permissions.AccessControlListDAO;
|
||||
import org.alfresco.repo.domain.permissions.AclDAO;
|
||||
import org.alfresco.repo.security.permissions.ACLType;
|
||||
import org.alfresco.repo.security.permissions.AccessControlListProperties;
|
||||
import org.alfresco.repo.security.permissions.impl.AclChange;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Fix ACLs that inherit and have issues with inheritance to correctly inherit from their primary parent, that may have
|
||||
* failed on upgrade or that have any other issue according to the DB
|
||||
*/
|
||||
public class FixAclInheritancePatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.fixAclInheritance.result";
|
||||
|
||||
private static Log logger = LogFactory.getLog(FixAclInheritancePatch.class);
|
||||
|
||||
private AclDAO aclDAO;
|
||||
|
||||
private PatchDAO patchDAO;
|
||||
|
||||
private AccessControlListDAO accessControlListDao;
|
||||
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
|
||||
private long count = 0;
|
||||
|
||||
/**
|
||||
* @param aclDaoComponent
|
||||
* the aclDaoComponent to set
|
||||
*/
|
||||
public void setAclDAO(AclDAO aclDAO)
|
||||
{
|
||||
this.aclDAO = aclDAO;
|
||||
}
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
public void setAccessControlListDao(AccessControlListDAO accessControlListDao)
|
||||
{
|
||||
this.accessControlListDao = accessControlListDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param retryingTransactionHelper
|
||||
* the retryingTransactionHelper to set
|
||||
*/
|
||||
public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
|
||||
{
|
||||
this.retryingTransactionHelper = retryingTransactionHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
// Fix unwired inheritance first as the other fixes depend on it and the fix can create D-D issues
|
||||
|
||||
List<Map<String, Object>> rows = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<List<Map<String, Object>>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> execute() throws Throwable
|
||||
{
|
||||
return patchDAO.getAclsThatInheritWithInheritanceUnset();
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
for (Map<String, Object> row : rows)
|
||||
{
|
||||
Long childAclId = (Long) row.get("childAclId");
|
||||
Long childAclType = (Long) row.get("childAclType");
|
||||
Long primaryParentAclId = (Long) row.get("primaryParentAclId");
|
||||
Long primaryParentAclType = (Long) row.get("primaryParentAclType");
|
||||
Long childNodeId = (Long) row.get("childNodeId");
|
||||
|
||||
ACLType childType = ACLType.getACLTypeFromId(childAclType.intValue());
|
||||
ACLType parentType = ACLType.getACLTypeFromId(primaryParentAclType.intValue());
|
||||
|
||||
RetryingTransactionCallback<Void> cb = null;
|
||||
|
||||
switch (childType)
|
||||
{
|
||||
case DEFINING:
|
||||
cb = new FixInherited(primaryParentAclId, childAclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
break;
|
||||
case FIXED:
|
||||
break;
|
||||
case GLOBAL:
|
||||
break;
|
||||
case LAYERED:
|
||||
break;
|
||||
case OLD:
|
||||
break;
|
||||
case SHARED:
|
||||
cb = new FixSharedUnsetInheritanceCallback(childNodeId, primaryParentAclId, childAclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If we fixed up any D - S relationships with and create a new inherited ACL we may break some D - D
|
||||
// relationships
|
||||
// Fix these up after as they appear as broken inheritance
|
||||
|
||||
rows = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<List<Map<String, Object>>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> execute() throws Throwable
|
||||
{
|
||||
return patchDAO.getSharedAclsThatDoNotInheritCorrectlyFromTheirDefiningAcl();
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
for (Map<String, Object> row : rows)
|
||||
{
|
||||
Long inheritedAclId = (Long) row.get("inheritedAclId");
|
||||
Long inheritedAclType = (Long) row.get("inheritedAclType");
|
||||
Long aclId = (Long) row.get("aclId");
|
||||
Long aclType = (Long) row.get("aclType");
|
||||
|
||||
ACLType inheritedType = ACLType.getACLTypeFromId(inheritedAclType.intValue());
|
||||
ACLType type = ACLType.getACLTypeFromId(aclType.intValue());
|
||||
|
||||
FixSharedAclCallback cb = new FixSharedAclCallback(inheritedAclId, aclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
}
|
||||
|
||||
rows = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<List<Map<String, Object>>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> execute() throws Throwable
|
||||
{
|
||||
return patchDAO.getSharedAclsThatDoNotInheritCorrectlyFromThePrimaryParent();
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
for (Map<String, Object> row : rows)
|
||||
{
|
||||
Long childAclId = (Long) row.get("childAclId");
|
||||
Long childAclType = (Long) row.get("childAclType");
|
||||
Long primaryParentAclId = (Long) row.get("primaryParentAclId");
|
||||
Long primaryParentAclType = (Long) row.get("primaryParentAclType");
|
||||
Long childNodeId = (Long) row.get("childNodeId");
|
||||
|
||||
ACLType childType = ACLType.getACLTypeFromId(childAclType.intValue());
|
||||
ACLType parentType = ACLType.getACLTypeFromId(primaryParentAclType.intValue());
|
||||
|
||||
FixSharedAclCallback cb = new FixSharedAclCallback(primaryParentAclId, childAclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
}
|
||||
|
||||
rows = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<List<Map<String, Object>>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> execute() throws Throwable
|
||||
{
|
||||
return patchDAO.getDefiningAclsThatDoNotInheritCorrectlyFromThePrimaryParent();
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
for (Map<String, Object> row : rows)
|
||||
{
|
||||
Long childAclId = (Long) row.get("childAclId");
|
||||
Long childAclType = (Long) row.get("childAclType");
|
||||
Long primaryParentAclId = (Long) row.get("primaryParentAclId");
|
||||
Long primaryParentAclType = (Long) row.get("primaryParentAclType");
|
||||
Long childNodeId = (Long) row.get("childNodeId");
|
||||
|
||||
ACLType childType = ACLType.getACLTypeFromId(childAclType.intValue());
|
||||
ACLType parentType = ACLType.getACLTypeFromId(primaryParentAclType.intValue());
|
||||
|
||||
FixInherited cb = new FixInherited(primaryParentAclId, childAclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
rows = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<List<Map<String, Object>>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> execute() throws Throwable
|
||||
{
|
||||
return patchDAO.getAclsThatInheritFromNonPrimaryParent();
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
for (Map<String, Object> row : rows)
|
||||
{
|
||||
Long childAclId = (Long) row.get("childAclId");
|
||||
Long childAclType = (Long) row.get("childAclType");
|
||||
Long primaryParentAclId = (Long) row.get("primaryParentAclId");
|
||||
Long primaryParentAclType = (Long) row.get("primaryParentAclType");
|
||||
Long childNodeId = (Long) row.get("childNodeId");
|
||||
|
||||
ACLType childType = ACLType.getACLTypeFromId(childAclType.intValue());
|
||||
ACLType parentType = ACLType.getACLTypeFromId(primaryParentAclType.intValue());
|
||||
|
||||
RetryingTransactionCallback<Void> cb = null;
|
||||
switch (childType)
|
||||
{
|
||||
case DEFINING:
|
||||
cb = new FixInherited(primaryParentAclId, childAclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
break;
|
||||
case FIXED:
|
||||
break;
|
||||
case GLOBAL:
|
||||
break;
|
||||
case LAYERED:
|
||||
break;
|
||||
case OLD:
|
||||
break;
|
||||
case SHARED:
|
||||
cb = new SetFixedAclsCallback(childNodeId, primaryParentAclId, childAclId);
|
||||
retryingTransactionHelper.doInTransaction(cb, false, true);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(FixAclInheritancePatch.MSG_SUCCESS, count);
|
||||
// done
|
||||
return msg;
|
||||
|
||||
}
|
||||
|
||||
private class FixSharedUnsetInheritanceCallback implements RetryingTransactionCallback<Void>
|
||||
{
|
||||
|
||||
Long childNodeId;
|
||||
|
||||
Long primaryParentAclId;
|
||||
|
||||
Long childAclId;
|
||||
|
||||
FixSharedUnsetInheritanceCallback(Long childNodeId, Long primaryParentAclId, Long childAclId)
|
||||
{
|
||||
this.childNodeId = childNodeId;
|
||||
this.primaryParentAclId = primaryParentAclId;
|
||||
this.childAclId = childAclId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback#execute()
|
||||
*/
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
Long inheritedAclId = aclDAO.getInheritedAccessControlList(primaryParentAclId);
|
||||
if (inheritedAclId.equals(childAclId))
|
||||
{
|
||||
// child acl does match inherited from primary parent
|
||||
// needs to set inherits_from correctly and fix up
|
||||
aclDAO.fixSharedAcl(primaryParentAclId, childAclId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// child acl does not match inherited from primary parent
|
||||
// need to replace the shared acl
|
||||
List<AclChange> changes = new ArrayList<AclChange>();
|
||||
accessControlListDao.setFixedAcls(childNodeId, primaryParentAclId, null, childAclId, changes, true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SetFixedAclsCallback implements RetryingTransactionCallback<Void>
|
||||
{
|
||||
Long childNodeId;
|
||||
|
||||
Long primaryParentAclId;
|
||||
|
||||
Long childAclId;
|
||||
|
||||
SetFixedAclsCallback(Long childNodeId, Long primaryParentAclId, Long childAclId)
|
||||
{
|
||||
this.childNodeId = childNodeId;
|
||||
this.primaryParentAclId = primaryParentAclId;
|
||||
this.childAclId = childAclId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback#execute()
|
||||
*/
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
List<AclChange> changes = new ArrayList<AclChange>();
|
||||
accessControlListDao.setFixedAcls(childNodeId, primaryParentAclId, null, childAclId, changes, true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class FixSharedAclCallback implements RetryingTransactionCallback<Void>
|
||||
{
|
||||
|
||||
Long inheritedAclId;
|
||||
|
||||
Long aclId;
|
||||
|
||||
FixSharedAclCallback(Long inheritedAclId, Long aclId)
|
||||
{
|
||||
this.inheritedAclId = inheritedAclId;
|
||||
this.aclId = aclId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback#execute()
|
||||
*/
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
aclDAO.fixSharedAcl(inheritedAclId, aclId);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class FixInherited implements RetryingTransactionCallback<Void>
|
||||
{
|
||||
|
||||
Long primaryParentAclId;
|
||||
|
||||
Long childAclId;
|
||||
|
||||
FixInherited(Long primaryParentAclId, Long childAclId)
|
||||
{
|
||||
this.primaryParentAclId = primaryParentAclId;
|
||||
this.childAclId = childAclId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback#execute()
|
||||
*/
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
aclDAO.enableInheritance(childAclId, primaryParentAclId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,180 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Gives user store entries unique qnames to allow fast database lookup of local authentication information.
|
||||
*
|
||||
* @author David Ward
|
||||
* @since 3.3.5
|
||||
*/
|
||||
public class FixUserQNamesPatch extends AbstractPatch implements ApplicationEventPublisherAware
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(FixUserQNamesPatch.class);
|
||||
private static final String MSG_SUCCESS = "patch.fixUserQNames.result";
|
||||
|
||||
private QNameDAO qnameDAO;
|
||||
private RuleService ruleService;
|
||||
private ImporterBootstrap userBootstrap;
|
||||
|
||||
public FixUserQNamesPatch()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param qnameDAO
|
||||
* resolved QNames
|
||||
*/
|
||||
public void setQnameDAO(QNameDAO qnameDAO)
|
||||
{
|
||||
this.qnameDAO = qnameDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ruleService
|
||||
* the rule service
|
||||
*/
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
public void setUserBootstrap(ImporterBootstrap userBootstrap)
|
||||
{
|
||||
this.userBootstrap = userBootstrap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
super.checkProperties();
|
||||
checkPropertyNotNull(qnameDAO, "qnameDAO");
|
||||
checkPropertyNotNull(userBootstrap, "userBootstrap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
// Get the ChildAssociationRefs
|
||||
List<ChildAssociationRef> toProcess = nodeService.getChildAssocs(
|
||||
getUserFolderLocation(),
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_USER,
|
||||
false);
|
||||
BatchProcessor<ChildAssociationRef> batchProcessor = new BatchProcessor<ChildAssociationRef>(
|
||||
"FixUserQNamesPatch",
|
||||
transactionHelper,
|
||||
toProcess,
|
||||
2,
|
||||
20,
|
||||
this.applicationEventPublisher, logger, 1000);
|
||||
|
||||
final String runAsUser = AuthenticationUtil.getRunAsUser();
|
||||
|
||||
int updated = batchProcessor.process(new BatchProcessWorker<ChildAssociationRef>()
|
||||
{
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
// Disable rules
|
||||
ruleService.disableRules();
|
||||
AuthenticationUtil.setRunAsUser(runAsUser);
|
||||
}
|
||||
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
// Enable rules
|
||||
ruleService.enableRules();
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
public String getIdentifier(ChildAssociationRef entry)
|
||||
{
|
||||
return entry.getChildRef().toString();
|
||||
}
|
||||
|
||||
public void process(ChildAssociationRef entry) throws Throwable
|
||||
{
|
||||
QName userQName = QName.createQName(
|
||||
ContentModel.USER_MODEL_URI,
|
||||
(String) nodeService.getProperty(entry.getChildRef(), ContentModel.PROP_USER_USERNAME));
|
||||
|
||||
// Only a user called "user" will stay in place
|
||||
if (!userQName.equals(ContentModel.TYPE_USER))
|
||||
{
|
||||
nodeService.moveNode(entry.getChildRef(), entry.getParentRef(), entry.getTypeQName(), userQName);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
return I18NUtil.getMessage(MSG_SUCCESS, updated);
|
||||
}
|
||||
|
||||
private NodeRef getUserFolderLocation()
|
||||
{
|
||||
NodeRef rootNode = this.nodeService.getRootNode(this.userBootstrap.getStoreRef());
|
||||
QName qnameAssocSystem = QName.createQName("sys", "system", namespaceService);
|
||||
QName qnameAssocUsers = QName.createQName("sys", "people", namespaceService);
|
||||
List<ChildAssociationRef> results = nodeService.getChildAssocs(rootNode, RegexQNamePattern.MATCH_ALL,
|
||||
qnameAssocSystem);
|
||||
NodeRef sysNodeRef = null;
|
||||
if (results.size() == 0)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Required authority system folder path not found: "
|
||||
+ qnameAssocSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
sysNodeRef = results.get(0).getChildRef();
|
||||
}
|
||||
results = nodeService.getChildAssocs(sysNodeRef, RegexQNamePattern.MATCH_ALL, qnameAssocUsers);
|
||||
if (results.size() == 0)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Required user folder path not found: " + qnameAssocUsers);
|
||||
}
|
||||
else
|
||||
{
|
||||
return results.get(0).getChildRef();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Migrate attributes (drop tables 'alf_*attribute*')
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 4.0
|
||||
*/
|
||||
public class MigrateAttrDropOldTablesPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.migrateAttrDropOldTables.result";
|
||||
|
||||
private PatchDAO patchDAO;
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
patchDAO.migrateOldAttrDropTables();
|
||||
|
||||
// build the result message
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS);
|
||||
// done
|
||||
return msg;
|
||||
}
|
||||
}
|
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* MT ALF-6029 - fix bootstrapped creator/modifier and change "admin" to "System@xxx" (or "System" in case of default domain) for given nodes (ie. "Models" and "Workflow Definitions")
|
||||
*/
|
||||
public class MultiTFixAdminExistingTenantsPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_RESULT = "patch.mtFixAdminExistingTenants.result";
|
||||
|
||||
private TenantService tenantService;
|
||||
private BehaviourFilter policyBehaviourFilter;
|
||||
private NodeDAO nodeDAO;
|
||||
|
||||
private List<String> pathsToNodes;
|
||||
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
}
|
||||
|
||||
public void setNodeDAO(NodeDAO nodeDAO)
|
||||
{
|
||||
this.nodeDAO = nodeDAO;
|
||||
}
|
||||
|
||||
public void setPolicyBehaviourFilter(BehaviourFilter policyBehaviourFilter)
|
||||
{
|
||||
this.policyBehaviourFilter = policyBehaviourFilter;
|
||||
}
|
||||
|
||||
public void setPathsToNodes(List<String> pathsToNodes)
|
||||
{
|
||||
this.pathsToNodes = pathsToNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#checkProperties()
|
||||
*/
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
super.checkProperties();
|
||||
|
||||
checkPropertyNotNull(this.tenantService, "tenantService");
|
||||
checkPropertyNotNull(this.nodeDAO, "nodeDAO");
|
||||
checkPropertyNotNull(this.pathsToNodes, "pathsToNodes");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
|
||||
*/
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
String currentUserDomain = tenantService.getCurrentUserDomain();
|
||||
|
||||
for (String xpathToNode : pathsToNodes)
|
||||
{
|
||||
fixAuditable(currentUserDomain, xpathToNode);
|
||||
}
|
||||
|
||||
return I18NUtil.getMessage(MSG_RESULT);
|
||||
}
|
||||
|
||||
private void fixAuditable(String currentUserDomain, String xpathToNode)
|
||||
{
|
||||
NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef,
|
||||
xpathToNode,
|
||||
null,
|
||||
namespaceService,
|
||||
false,
|
||||
SearchService.LANGUAGE_XPATH);
|
||||
|
||||
if (nodeRefs.size() > 0)
|
||||
{
|
||||
NodeRef nodeRef = nodeRefs.get(0);
|
||||
|
||||
Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(tenantService.getName(nodeRef)); // add tenant domain (since going via nodeDAO)
|
||||
if (nodePair != null)
|
||||
{
|
||||
String tenantSystem = tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), currentUserDomain);
|
||||
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||
props.put(ContentModel.PROP_MODIFIER, tenantSystem);
|
||||
props.put(ContentModel.PROP_CREATOR, tenantSystem);
|
||||
|
||||
try
|
||||
{
|
||||
policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
|
||||
nodeDAO.addNodeProperties(nodePair.getFirst(), props); // update only
|
||||
}
|
||||
finally
|
||||
{
|
||||
policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Patch to remove the GROUP_EVERYONE Contributor permissions on the
|
||||
* Sites Space (/
|
||||
* <p/>
|
||||
* Formerly, all users could create anything in this folder. As only
|
||||
* Sites should live there, and the SiteService handles permissions itself,
|
||||
* the Contributor permission can be removed.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SitesSpacePermissionsPatch extends AbstractPatch
|
||||
{
|
||||
// Message IDs
|
||||
private static final String MSG_SUCCESS = "patch.sitesSpacePermissions.result";
|
||||
private static final String MSG_SUCCESS_NONE = "patch.sitesSpacePermissions.result.none";
|
||||
|
||||
// Folders' names for path building
|
||||
private static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname";
|
||||
private static final String PROPERTY_SITES_CHILDNAME = "spaces.sites.childname";
|
||||
|
||||
// Things we've found
|
||||
private NodeRef sitesNodeRef;
|
||||
|
||||
// Dependencies
|
||||
private ImporterBootstrap importerBootstrap;
|
||||
private PermissionService permissionService;
|
||||
|
||||
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||
{
|
||||
this.importerBootstrap = importerBootstrap;
|
||||
}
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
super.checkProperties();
|
||||
checkPropertyNotNull(importerBootstrap, "importerBootstrap");
|
||||
checkPropertyNotNull(permissionService, "permissionService");
|
||||
}
|
||||
|
||||
public SitesSpacePermissionsPatch()
|
||||
{
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
// Get the node store that we must work against
|
||||
StoreRef storeRef = importerBootstrap.getStoreRef();
|
||||
if (storeRef == null)
|
||||
{
|
||||
throw new PatchException("Bootstrap store has not been set");
|
||||
}
|
||||
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
// Build up the Assocation Names that form the path
|
||||
Properties configuration = importerBootstrap.getConfiguration();
|
||||
|
||||
String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME);
|
||||
if (companyHomeChildName == null || companyHomeChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_COMPANY_HOME_CHILDNAME + "' is not present");
|
||||
}
|
||||
String sitesChildName = configuration.getProperty(PROPERTY_SITES_CHILDNAME);
|
||||
if (sitesChildName == null || sitesChildName.length() == 0)
|
||||
{
|
||||
throw new PatchException("Bootstrap property '" + PROPERTY_SITES_CHILDNAME + "' is not present");
|
||||
}
|
||||
|
||||
// build the search string to get the sites node
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("/").append(companyHomeChildName);
|
||||
sb.append("/").append(sitesChildName);
|
||||
String xpath = sb.toString();
|
||||
// get the sites node
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
|
||||
if (nodeRefs.size() == 0)
|
||||
{
|
||||
throw new PatchException("XPath didn't return any results: \n" + " root: " + storeRootNodeRef + "\n" + " xpath: " + xpath);
|
||||
}
|
||||
else if (nodeRefs.size() > 1)
|
||||
{
|
||||
throw new PatchException("XPath returned too many results: \n" + " root: " + storeRootNodeRef + "\n" + " xpath: " + xpath + "\n" + " results: " + nodeRefs);
|
||||
}
|
||||
this.sitesNodeRef = nodeRefs.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
setUp();
|
||||
|
||||
// Get the sites space
|
||||
NodeRef sitesSpace = sitesNodeRef;
|
||||
if(sitesSpace == null || !nodeService.exists(sitesSpace))
|
||||
{
|
||||
throw new IllegalStateException("Sites Space not found in Company Home!");
|
||||
}
|
||||
|
||||
String msg = I18NUtil.getMessage(MSG_SUCCESS);
|
||||
try
|
||||
{
|
||||
// Remove the permission
|
||||
permissionService.deletePermission(
|
||||
sitesSpace,
|
||||
PermissionService.ALL_AUTHORITIES,
|
||||
PermissionService.CONTRIBUTOR
|
||||
);
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
{
|
||||
if (e.getMessage().contains("SHARED"))
|
||||
{
|
||||
// ALF-11489: 'patch.sitesSpacePermissions' failed on upgrade 2.2.8 -> 3.4.6
|
||||
// We are catching "Can not delete from this acl in a node context SHARED"
|
||||
msg = I18NUtil.getMessage(MSG_SUCCESS_NONE);
|
||||
}
|
||||
// Something else
|
||||
}
|
||||
|
||||
// All done
|
||||
return msg;
|
||||
}
|
||||
}
|
@@ -19,7 +19,6 @@
|
||||
package org.alfresco.repo.domain.patch;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -57,36 +56,6 @@ public interface PatchDAO
|
||||
*/
|
||||
public List<Pair<NodeRef, String>> getNodesOfTypeWithNamePattern(QName typeQName, String namePattern);
|
||||
|
||||
/**
|
||||
* Drop old attribute alf_*attribute* tables
|
||||
*/
|
||||
public void migrateOldAttrDropTables();
|
||||
|
||||
/**
|
||||
* Get shared acls with inheritance issues
|
||||
*/
|
||||
public List<Map<String, Object>> getSharedAclsThatDoNotInheritCorrectlyFromThePrimaryParent();
|
||||
|
||||
/**
|
||||
* Get defining acls with inheritance issues
|
||||
*/
|
||||
public List<Map<String, Object>> getDefiningAclsThatDoNotInheritCorrectlyFromThePrimaryParent();
|
||||
|
||||
/**
|
||||
* Get acls that do not inherit from the primary parent.
|
||||
*/
|
||||
public List<Map<String, Object>> getAclsThatInheritFromNonPrimaryParent();
|
||||
|
||||
/**
|
||||
* Get acls that inherit with inheritance unset
|
||||
*/
|
||||
public List<Map<String, Object>> getAclsThatInheritWithInheritanceUnset();
|
||||
|
||||
/**
|
||||
* Get shared acls that do not inherit correctly from the defining acl
|
||||
*/
|
||||
public List<Map<String, Object>> getSharedAclsThatDoNotInheritCorrectlyFromTheirDefiningAcl();
|
||||
|
||||
/**
|
||||
* @param qnames the qnames to search for
|
||||
* @return Returns a count of the number of nodes that have either of the aspects
|
||||
|
@@ -60,18 +60,6 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl
|
||||
|
||||
private static final String UPDATE_CONTENT_MIMETYPE_ID = "alfresco.patch.update_contentMimetypeId";
|
||||
|
||||
private static final String DROP_OLD_ATTR_LIST = "alfresco.patch.drop_oldAttrAlfListAttributeEntries";
|
||||
private static final String DROP_OLD_ATTR_MAP = "alfresco.patch.drop_oldAttrAlfMapAttributeEntries";
|
||||
private static final String DROP_OLD_ATTR_GLOBAL = "alfresco.patch.drop_oldAttrAlfGlobalAttributes";
|
||||
private static final String DROP_OLD_ATTR = "alfresco.patch.drop_oldAttrAlfAttributes";
|
||||
private static final String DROP_OLD_ATTR_SEQ = "alfresco.patch.drop_oldAttrAlfAttributes_seq";
|
||||
|
||||
private static final String SELECT_ACLS_THAT_INHERIT_FROM_NON_PRIMARY_PARENT = "alfresco.patch.select_aclsThatInheritFromNonPrimaryParent";
|
||||
private static final String SELECT_ACLS_THAT_INHERIT_WITH_INHERITANCE_UNSET = "alfresco.patch.select_aclsThatInheritWithInheritanceUnset";
|
||||
private static final String SELECT_DEFINING_ACLS_THAT_DO_NOT_INHERIT_CORRECTLY_FROM_THE_PRIMARY_PARENT = "alfresco.patch.select_definingAclsThatDoNotInheritCorrectlyFromThePrimaryParent";
|
||||
private static final String SELECT_SHARED_ACLS_THAT_DO_NOT_INHERIT_CORRECTLY_FROM_THE_PRIMARY_PARENT = "alfresco.patch.select_sharedAclsThatDoNotInheritCorrectlyFromThePrimaryParent";
|
||||
private static final String SELECT_SHARED_ACLS_THAT_DO_NOT_INHERIT_CORRECTLY_FROM_THEIR_DEFINING_ACL = "alfresco.patch.select_sharedAclsThatDoNotInheritCorrectlyFromTheirDefiningAcl";
|
||||
|
||||
private static final String SELECT_COUNT_NODES_WITH_ASPECTS = "alfresco.patch.select_CountNodesWithAspectIds";
|
||||
|
||||
private static final String SELECT_NODES_BY_TYPE_QNAME = "alfresco.patch.select_NodesByTypeQName";
|
||||
@@ -199,60 +187,6 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrateOldAttrDropTables()
|
||||
{
|
||||
template.update(DROP_OLD_ATTR_LIST);
|
||||
template.update(DROP_OLD_ATTR_MAP);
|
||||
template.update(DROP_OLD_ATTR_GLOBAL);
|
||||
template.update(DROP_OLD_ATTR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAclsThatInheritFromNonPrimaryParent()
|
||||
{
|
||||
List<Map<String, Object>> rows = template.selectList(
|
||||
SELECT_ACLS_THAT_INHERIT_FROM_NON_PRIMARY_PARENT,
|
||||
Boolean.TRUE);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAclsThatInheritWithInheritanceUnset()
|
||||
{
|
||||
List<Map<String, Object>> rows = template.selectList(
|
||||
SELECT_ACLS_THAT_INHERIT_WITH_INHERITANCE_UNSET,
|
||||
Boolean.TRUE);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getDefiningAclsThatDoNotInheritCorrectlyFromThePrimaryParent()
|
||||
{
|
||||
List<Map<String, Object>> rows = template.selectList(
|
||||
SELECT_DEFINING_ACLS_THAT_DO_NOT_INHERIT_CORRECTLY_FROM_THE_PRIMARY_PARENT,
|
||||
Boolean.TRUE);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getSharedAclsThatDoNotInheritCorrectlyFromThePrimaryParent()
|
||||
{
|
||||
List<Map<String, Object>> rows = template.selectList(
|
||||
SELECT_SHARED_ACLS_THAT_DO_NOT_INHERIT_CORRECTLY_FROM_THE_PRIMARY_PARENT,
|
||||
Boolean.TRUE);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getSharedAclsThatDoNotInheritCorrectlyFromTheirDefiningAcl()
|
||||
{
|
||||
List<Map<String, Object>> rows = template.selectList(
|
||||
SELECT_SHARED_ACLS_THAT_DO_NOT_INHERIT_CORRECTLY_FROM_THEIR_DEFINING_ACL,
|
||||
Boolean.TRUE);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountNodesWithAspects(Set<QName> qnames)
|
||||
{
|
||||
@@ -388,12 +322,6 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl
|
||||
*/
|
||||
public static class PostgreSQL extends PatchDAOImpl
|
||||
{
|
||||
@Override
|
||||
public void migrateOldAttrDropTables()
|
||||
{
|
||||
super.migrateOldAttrDropTables();
|
||||
template.update(DROP_OLD_ATTR_SEQ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,11 +332,5 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl
|
||||
*/
|
||||
public static class Oracle extends PatchDAOImpl
|
||||
{
|
||||
@Override
|
||||
public void migrateOldAttrDropTables()
|
||||
{
|
||||
super.migrateOldAttrDropTables();
|
||||
template.update(DROP_OLD_ATTR_SEQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user