Index: kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java (revision 36976) +++ kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java (revision 37040) @@ -7417,10 +7417,58 @@ /** * {@inheritDoc} */ - public void updateEntityReferences(String toContext, Map transversalMap){ - //TODO: is there any content that needs reference updates? - } + public void updateEntityReferences(String toContext, Map transversalMap) { + if (transversalMap != null && transversalMap.size() > 0) { + try { + Set> entrySet = (Set>) transversalMap.entrySet(); + // Get the root collection + ContentCollection oCollection = getCollection(getSiteCollection(toContext)); + + if (oCollection != null) { + updateEntityReferences(entrySet, oCollection); + + } + } catch (Exception e) { + M_log.error("BaseContentService Resources updateEntityReferences Error " + e, e); + } + } + } + + private void updateEntityReferences(Set> entrySet, ContentCollection oCollection) { + // Get the collection members from the old collection + List oResources = oCollection.getMemberResources(); + + for (int i = 0; i < oResources.size(); i++) { + // Get the original resource + Entity oResource = (Entity) oResources.get(i); + + if (oResource instanceof ContentResource) { + ContentResource resource = (ContentResource) oResource; + if (resource.getContentType().equals("text/html")) { + String content = null; + try { + content = new String(resource.getContent()); + + Iterator> entryItr = entrySet.iterator(); + while (entryItr.hasNext()) { + Entry entry = entryItr.next(); + String fromContextRef = entry.getKey(); + if (content.contains(fromContextRef)) { + content = content.replace(fromContextRef, entry.getValue()); + } + } + oResource = updateResource(oResource.getId(), resource.getContentType(), content.getBytes()); + } catch (Exception e) { + M_log.error("BaseContentService Resources updateEntityReferences Error " + e, e); + } + } + } else if (oResource instanceof ContentCollection) { + updateEntityReferences(entrySet, (ContentCollection) oResource); + } + } + } + public void transferCopyEntities(String fromContext, String toContext, List resourceIds){ transferCopyEntitiesRefMigrator(fromContext, toContext, resourceIds); } @@ -7581,15 +7629,19 @@ } catch (IdUsedException e) { + M_log.warn("problem copying collection into site: " + toContext + " from site: " + fromContext, e); } catch (IdInvalidException e) { + M_log.warn("problem copying collection into site: " + toContext + " from site: " + fromContext, e); } catch (PermissionException e) { + M_log.warn("problem copying collection into site: " + toContext + " from site: " + fromContext, e); } catch (InconsistentException e) { + M_log.warn("problem copying collection into site: " + toContext + " from site: " + fromContext, e); } transversalMap.put(oResource.getId(), nId); @@ -7623,18 +7675,24 @@ } catch (PermissionException e) { + M_log.warn("problem copying resource into site: " + toContext + " from site: " + fromContext, e); } catch (IdUsedException e) { + M_log.warn("problem copying resource into site: " + toContext + " from site: " + fromContext, e); + } catch (IdInvalidException e) { + M_log.warn("problem copying resource into site: " + toContext + " from site: " + fromContext, e); } catch (InconsistentException e) { + M_log.warn("problem copying resource into site: " + toContext + " from site: " + fromContext, e); } catch (ServerOverloadException e) { + M_log.warn("problem copying resource into site: " + toContext + " from site: " + fromContext, e); } } // if } // if @@ -7642,12 +7700,15 @@ } catch (IdUnusedException e) { + M_log.warn("problem copying resources into site: " + toContext + " from site: " + fromContext, e); } catch (TypeException e) { + M_log.warn("problem copying resources into site: " + toContext + " from site: " + fromContext, e); } catch (PermissionException e) { + M_log.warn("problem copying resources into site: " + toContext + " from site: " + fromContext, e); } } return transversalMap; @@ -12806,9 +12867,9 @@ { try { - //ContentCollectionEdit edit = editCollection(oId); + ContentCollectionEdit edit = editCollection(oId); - this.removeCollection(oId); + this.removeCollection(edit.getId()); } catch (Exception ee) { @@ -12831,13 +12892,15 @@ } - + threadLocalManager.set("members@" + oCollection.getId(), null); + threadLocalManager.set("getResources@" + oCollection.getId(), null); + threadLocalManager.set("getCollections@" + oCollection.getId(), null); } } } catch (Exception e) { - M_log.debug("BaseContentService Resources transferCopyEntities Error" + e); + M_log.error("BaseContentService Resources transferCopyEntities Error" + e); } transversalMap.putAll(transferCopyEntitiesRefMigrator(fromContext, toContext, ids));