-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 12999 delete content types #13214
Changes from all commits
782b7a6
a7c5b3e
0ecb6c7
a5e7a50
9e69157
f2e1fe9
c2d78f2
afd7dc9
5da6387
325effc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package com.dotmarketing.portlets.containers.action; | ||
|
||
import com.dotmarketing.beans.MultiTree; | ||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.exception.DotSecurityException; | ||
import com.dotmarketing.factories.MultiTreeFactory; | ||
import java.net.URLDecoder; | ||
import java.net.URLEncoder; | ||
import java.util.Iterator; | ||
|
@@ -559,43 +563,78 @@ public void _saveWebAsset(ActionRequest req, ActionResponse res, | |
identifier.setHostId(host.getIdentifier()); | ||
APILocator.getIdentifierAPI().save(identifier); | ||
|
||
|
||
//Save/Update/Delete the ContainerStructures associated | ||
saveContainerStructures(req, currentContainer, container); | ||
|
||
|
||
SessionMessages.add(httpReq, "message", "message.containers.save"); | ||
ActivityLogger.logInfo(this.getClass(), "Save WebAsset action", "User " + user.getPrimaryKey() + " saved " + container.getTitle(), HostUtil.hostNameUtil(req, _getUser(req))); | ||
// saves to working folder under velocity | ||
ContainerServices.invalidate(container, true); | ||
|
||
// copies the information back into the form bean | ||
BeanUtils.copyProperties(form, req | ||
.getAttribute(WebKeys.CONTAINER_FORM_EDIT)); | ||
|
||
APILocator.getVersionableAPI().setWorking(container); | ||
|
||
|
||
|
||
|
||
HibernateUtil.flush(); | ||
} | ||
|
||
/** | ||
* Containers are associated with multiple Structures. This method takes care of the ContainerStructure save/update/delete logic | ||
* @param req Request | ||
* @param currentContainer Container as currently exists | ||
* @param container Container with the new changes to be persisted | ||
*/ | ||
private void saveContainerStructures (ActionRequest req, Container currentContainer, Container container) | ||
throws DotDataException, DotSecurityException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic on this code can be optimized keeping a map for oldContainerStructures, then filter to exclude newContainerStructures (https://www.mkyong.com/java8/java-8-filter-a-map-examples/). With the resulting map you can delete in batch. I think it's a faster and less verbose implementation |
||
List<ContainerStructure> oldContainerStructures = APILocator.getContainerAPI().getContainerStructures(currentContainer); | ||
List<ContainerStructure> csList = new LinkedList<>(); | ||
|
||
// saving the multiple structures | ||
if(container.getMaxContentlets()>0) { | ||
String structuresIdsStr = req.getParameter("structuresIds"); | ||
|
||
String[] structuresIds = structuresIdsStr.split("#"); | ||
List<ContainerStructure> csList = new LinkedList<ContainerStructure>(); | ||
|
||
for (String structureId : structuresIds) { | ||
String code = req.getParameter("code_"+structureId); | ||
ContainerStructure cs = new ContainerStructure(); | ||
cs.setContainerId(container.getIdentifier()); | ||
cs.setContainerInode(container.getInode()); | ||
cs.setContainerInode(container.getInode()); | ||
cs.setStructureId(structureId); | ||
cs.setCode(code); | ||
csList.add(cs); | ||
} | ||
|
||
//Save new structures | ||
APILocator.getContainerAPI().saveContainerStructures(csList); | ||
|
||
} | ||
|
||
//Delete MultiTree for old / unused ContainerStructures | ||
for (ContainerStructure oldCS : oldContainerStructures) { | ||
boolean unused = true; | ||
for (ContainerStructure newCS : csList) { | ||
if (newCS.getStructureId().equals(oldCS.getStructureId())) { | ||
unused = false; | ||
break; | ||
} | ||
} | ||
|
||
SessionMessages.add(httpReq, "message", "message.containers.save"); | ||
ActivityLogger.logInfo(this.getClass(), "Save WebAsset action", "User " + user.getPrimaryKey() + " saved " + container.getTitle(), HostUtil.hostNameUtil(req, _getUser(req))); | ||
// saves to working folder under velocity | ||
ContainerServices.invalidate(container, true); | ||
|
||
// copies the information back into the form bean | ||
BeanUtils.copyProperties(form, req | ||
.getAttribute(WebKeys.CONTAINER_FORM_EDIT)); | ||
|
||
APILocator.getVersionableAPI().setWorking(container); | ||
|
||
|
||
|
||
|
||
HibernateUtil.flush(); | ||
if (unused) { | ||
List<MultiTree> multiTreeList = MultiTreeFactory | ||
.getContainerStructureMultiTree(oldCS.getContainerId(), oldCS.getStructureId()); | ||
for (MultiTree mt : multiTreeList) { | ||
MultiTreeFactory.deleteMultiTree(mt); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void _copyWebAsset(ActionRequest req, ActionResponse res, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A MultitreeTransformer can be implemented instead. Take a look at https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotmarketing/portlets/templates/transform/FolderTransformer.java