Uploaded image for project: 'CMS'
  1. CMS
  2. CMS-6099

Do not use JCR same name sibling anymore

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 3.7
    • None
    • None
    • None

      Bugs such as CMS-6055 is due to our synchonisation system between DEFAULT and LIVE jcr workspaces that is based upon JCR listener mechanism : events are not sent in the right order and this makes same name sibling nodes to bug.

      We should not use it anymode for auto-synchronized node : ametys:plugins and [site]/ametys-internal:plugins.

      It concerns :

      • Alias : ametys:alias
      • Glossary : ametys:definition
      • Newsletter : ametys:category
      • LinkDirectory : ametys:theme
      • Survey : ametys-internal:rules

      We have to create migrations script.

          [CMS-6099] Do not use JCR same name sibling anymore

          Alias was naming alias, alias-2, alias-3, ... as we have no property to use with FilterNameHelper (an alias have just a url like "//*.html").
          For others nodes, the name was construct from a label or a title using FilterNameHelper.

          Here is the script of migration for old alias:

          function getUniqueName (rootNode, defaultName)
          {
             var uniqueName = defaultName;
             var index = 2;
             while (rootNode.hasNode(uniqueName))
             {
                uniqueName = defaultName + "-" + index;
                index++;
             }   
             return uniqueName;
          }
           
          // Migration des alias
          var qm = session.getWorkspace().getQueryManager();
          var query = qm.createQuery("//element(*, ametys:site)/ametys-internal:plugins/web/pageAlias/element(ametys:alias, ametys:alias)", javax.jcr.query.Query.XPATH);
          var nodes = query.execute().getNodes();
           
          var count = 0;
          while (nodes.hasNext())
          {
            var aliasNode = nodes.next();
            var newName = getUniqueName (aliasNode.getParent(), "alias");
             
            session.move(aliasNode.getPath(), aliasNode.getParent().getPath() + '/' + newName);
            count++;
          }
           
          if (count > 0)
          {
            session.save();
          }
          println(count + " alias have been renamed");
          

          Laurence Aumeunier added a comment - Alias was naming alias, alias-2, alias-3, ... as we have no property to use with FilterNameHelper (an alias have just a url like "/ / *.html"). For others nodes, the name was construct from a label or a title using FilterNameHelper. Here is the script of migration for old alias: function getUniqueName (rootNode, defaultName) { var uniqueName = defaultName; var index = 2; while (rootNode.hasNode(uniqueName)) { uniqueName = defaultName + "-" + index; index++; } return uniqueName; } // Migration des alias var qm = session.getWorkspace().getQueryManager(); var query = qm.createQuery( " //element(*, ametys:site)/ametys-internal:plugins/web/pageAlias/element(ametys:alias, ametys:alias)" , javax.jcr.query.Query.XPATH); var nodes = query.execute().getNodes(); var count = 0; while (nodes.hasNext()) { var aliasNode = nodes.next(); var newName = getUniqueName (aliasNode.getParent(), "alias" ); session.move(aliasNode.getPath(), aliasNode.getParent().getPath() + '/' + newName); count++; } if (count > 0) { session.save(); } println(count + " alias have been renamed" );

          Rather than naming them alias1, alias2, alias3, (or definition1, definition2...), we should name them from a distinctive property (filtered by FilterNameHelper), like "word" for a glossary definition.

          Nicolas Gavalda (Inactive) added a comment - Rather than naming them alias1, alias2, alias3, (or definition1, definition2...), we should name them from a distinctive property (filtered by FilterNameHelper), like "word" for a glossary definition.

            laurence Laurence Aumeunier
            raphael Raphaël Franchet
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: