Update of 
/var/cvs/contributions/CMSContainer/cmsc/maintenance/src/java/com/finalist/cmsc/maintenance/beans
In directory 
james.mmbase.org:/tmp/cvs-serv16541/cmsc/maintenance/src/java/com/finalist/cmsc/maintenance/beans

Modified Files:
        CreateRelationsForSecondaryContent.java 
Log Message:
CMSC-1192 - add SQL script to migrate all images/attachments/URLs to new 
assetstable - improved functionality


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/maintenance/src/java/com/finalist/cmsc/maintenance/beans
See also: http://www.mmbase.org/jira/browse/CMSC-1192


Index: CreateRelationsForSecondaryContent.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/maintenance/src/java/com/finalist/cmsc/maintenance/beans/CreateRelationsForSecondaryContent.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- CreateRelationsForSecondaryContent.java     9 Jan 2009 02:59:58 -0000       
1.13
+++ CreateRelationsForSecondaryContent.java     6 Feb 2009 15:03:06 -0000       
1.14
@@ -32,8 +32,6 @@
    private static final String CONTENTCHANNEL = "contentchannel";
 
    private Cloud cloud;
-   private Integer parentNumber;
-   private String type ;
    public PageContext ctx ;
    /** MMbase logging system */
    private static final Logger log = 
Logging.getLoggerInstance(CreateRelationsForSecondaryContent.class.getName());
@@ -43,11 +41,9 @@
       ctx =  pageContext;
    }
 
-   public String execute(Integer parentNumber,String type) throws Exception {
+   public String execute(Integer parentNumber,String type, String 
selfselectLogic) throws Exception {
       //Creating relations between assets and content channel
       //Only process assets that don't have creationrels!
-      this.parentNumber = parentNumber;
-      this.type = type;
 
       NodeManager assetManager = cloud.getNodeManager("assetelement");
       NodeManager ownerManager = cloud.getNodeManager("user");
@@ -74,9 +70,31 @@
          if (!RepositoryUtil.hasCreationChannel(asset)) {
             counter++;
             Relation relation = null;
-            //if type is not null . create relations acording to the realations
+            // If type is not null, it means someone has picked selfselect. We 
will now try to determine
+            // a suitable channel for the asset.
             if(StringUtils.isNotBlank(type)) {
                
+               if(selfselectLogic != null && 
selfselectLogic.equals("rootWhenUndetermined")) {
+                  // narrow selfselect. Picks a channel from a related content 
element, if and only if the asset has 1 related content element
+                  // If an asset has more then one related content element, 
the asset will be put in the root channel.
+                  
+                  int numRelatedContent = 
asset.countRelatedNodes(CONTENTELEMENT);
+                  if(numRelatedContent > 1) {
+                     relation = RelationUtil.createRelation(asset, root, 
CREATIONREL);
+                  } else {
+                     Node channel = getRelatedChannel(asset);
+                     if(channel == null) {
+                        relation = RelationUtil.createRelation(asset, root, 
CREATIONREL);
+                     }
+                     else {
+                        relation = RelationUtil.createRelation(asset, channel, 
CREATIONREL);
+                     }
+                  }
+                  
+               } else {
+                  // selfselectLogic is firstElem
+                  // Standard way of selfselect. picks first non recyclebin 
channel.
+                  
                Node channel = getRelatedChannel(asset);
                if(channel == null) {
                   relation = RelationUtil.createRelation(asset, root, 
CREATIONREL);
@@ -85,9 +103,11 @@
                   relation = RelationUtil.createRelation(asset, channel, 
CREATIONREL);
                }
             }
+            }
             else {
                relation = RelationUtil.createRelation(asset, root, 
CREATIONREL);
             }
+            
             if(Publish.isPublishable(relation)) {
                Publish.publish(relation); // This method checks if it need to 
publish
             }                        // otherwise, it doesn't harm anyone
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to