To unable cm:autoVersionOnUpdateProps

cancel
Showing results for 
Search instead for 
Did you mean: 
piyush48
Established Member

To unable cm:autoVersionOnUpdateProps

Jump to solution

Hii All,

I want to unable versioning on properties and want cm:autoVersionOnUpdateProps to be true.

I have added this two changes in both docker alfresco-global.properties and platform alfresco-global.properties. 

version.store.enableAutoVersioning=true
version.store.enableAutoVersionOnUpdateProps=true

please notify me changes to be made with path. I am attaching screenshot which is showing autoVersionOnUpdateProps to be false.

Screenshot (29).png

1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: To unable cm:autoVersionOnUpdateProps

Jump to solution

You can write a repository tier webscript (java or javascript) to cleanup nodes where "cm:autoVersionOnUpdateProps" property is set to false. 

Javascript based webscript can be directly deployed to "Data Dictionary > Web Scripts Extensions " directory without restarting the server. Follow the document here to learn more: https://docs.alfresco.com/6.2/tasks/ws-config.html

Learn more on creating webcripts here: 

https://docs.alfresco.com/6.2/concepts/ws-overview.html

https://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html#what-...

Steps you would do in the webscript:

1- Prepare a search query to return the nodes having  "cm:autoVersionOnUpdateProps" property as false. You could choose to do site by site/folder by folder or get all sites and iterate your search query using site short name.

2- Once nodes are returned, double check that whether "cm:autoVersionOnUpdateProps" property is false, if true- set the property value to true

3- save the node

-------------------

If you decide to use javascript based repo webscript, here is a sample webscript which you can try and make changes/tweak as per your need.

cleanupProperty.get.desc.xml

<webscript>
	<shortname>Cleanup existing value of a property</shortname>
	<description>Cleanup existing value of a property</description>
	<url>/cleanupProperty?propertyName={propertyName}&amp;existingPropertyVal={existingPropertyVal}&amp;newPropertyVal={newPropertyVal}&amp;folderPath={folderPath}&amp;siteShortName={siteShortName}&amp;contentTypes={contentTypes}&amp;skipCount={skipCount}&amp;maxCount={maxCount}</url>
	<format default="html">any</format>
  	<authentication>admin</authentication>
</webscript>
cleanupProperty.get.html.ftl

<html> <head> <title>Cleanup existing value of a property</title> </head> <body> <h4>Nodes which failed during update</h4> <#if failedNodes?is_hash_ex> <#assign keys = failedNodes ?keys> <#list keys as key>${key} - ${failedNodes [key]}; <br></#list> </#if> <h4>Successfully updated nodes</h4> <#if successNodes?is_hash_ex> <#assign keys = successNodes ?keys> <#list keys as key>${key} - ${successNodes [key]}; <br></#list> </#if> </body> </html>
cleanupProperty.get.js

main();

function main(){
	var propertyName =  args["propertyName"];
    var existingPropertyVal = args["existingPropertyVal"];
    var newPropertyVal = args["newPropertyVal"];
    var contentTypes = args["contentTypes"];
	var siteShortName = args["siteShortName"];
    var folderPath = args["folderPath"];
	var skipCount = (args["skipCount"]==null || args["skipCount"]==undefined)?0:args["skipCount"];
	var maxCount = (args["maxCount"]==null || args["maxCount"]==undefined)?100000:args["maxCount"];
  	
	var successNodes = [];
	var failedNodes = [];
  
    var query = buildSearchQuery(siteShortName, contentTypes, folderPath, propertyName, existingPropertyVal)
	var page = {
			skipCount : parseInt(skipCount),
			maxItems : parseInt(maxCount)
	};

	var searchQuery = {
			query : query,
			language : "fts-alfresco",
			page : page
	};
	
 	logger.log("Executing Search: "+query)
 	var nodes = search.query(searchQuery);
 	logger.log("Total Nodes found: "+nodes.length)
      
    for each(node in nodes) {
		try {
              logger.log("Updating the "+propertyName+" of node: "+node.name);
              node[propertyName] = newPropertyVal;
              node.save();
              successNodes[node.nodeRef] = node.name+" - Success";
		} catch(ex) {
			logger.log("Exception occurred: "+ex.message);
			failedNodes[node.nodeRef] = node.name+" - "+ex.message;
		}
	}
	model.successNodes = successNodes;
	model.failedNodes = failedNodes;
}

function buildSearchQuery(siteShortName, contentTypes, folderPath, propertyName, existingPropertyVal) {
    var query = 'PATH:"/app:company_home/st:sites/cm:' +siteShortName;
  
    if(folderPath=="") {
       query = query + '/cm:documentLibrary//*"';
    } else {
       query = query + '/cm:documentLibrary/';
       var pathTokens = folderPath.split('/');
       for (var each=0; each<pathTokens.length; each ++) {
         query = query +'cm:'+search.ISO9075Encode(pathTokens[each].trim())+'/';
       }
       query = query + '/*"';

    }
  
    var contentTypeArr = contentTypes.split(',');
	var arrayLength = contentTypeArr.length;

	if(arrayLength == 1) {
		query = query +' AND (TYPE:"' +contentTypeArr+'")';
	} else {
		query = query +' AND (';
		for (var each=0; each<arrayLength; each ++) {
			query = query + 'TYPE:"'+contentTypeArr[each].trim()+'"';
			if(each != arrayLength-1) {
				query = query + ' OR ';
			}
		}
      
		query = query +')';
	}
  
    //Append property and value query.
    if(!!existingPropertyVal) {
        var propertyParts = propertyName.split(':');
        if (propertyParts.length ==1 && (propertyName=="mimetype" || propertyName=="size")) {
           
           query = query +' AND @content.'+propertyName+':"'+existingPropertyVal+'"';
        } else {
           query = query +' AND @'+propertyParts[0]+'\\:'+propertyParts[1]+':"'+existingPropertyVal+'"';
        }
    }
    return query;
}

To execute the webscript, e.g.:

http://127.0.0.1:800/alfresco/service/cleanupProperty?propertyName=cm:autoVersionOnUpdateProps&exist...

You can utilize the folder path as well as use multiple content types (',' separated) as param.

I would strongly recommed to go through the tutorials and docs given above for better understanding and future prospects of webscript development.

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

3 Replies
abhinavmishra14
Advanced

Re: To unable cm:autoVersionOnUpdateProps

Jump to solution

You did right, you need to add the properties in alfresco-global.properties. Either platform project or docker project's alfresco-global.properties should work.

It will take effect for all newly created nodes. But for existing nodes, you have to write a script to reset the property and set value to true.

Refer this post for more details: https://hub.alfresco.com/t5/alfresco-content-services-forum/versioning-properties/m-p/298655/highlig...

https://hub.alfresco.com/t5/alfresco-content-services-forum/version-history-does-not-include-propert...

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
piyush48
Established Member

Re: To unable cm:autoVersionOnUpdateProps

Jump to solution

Hi @abhinavmishra14 ,

Thanks for making me understand how this work with old Node. Could you please guide me for Script how to create and Path to Place it in SDK?? That will be very helpful.

 

Thanks,

Piyush

abhinavmishra14
Advanced

Re: To unable cm:autoVersionOnUpdateProps

Jump to solution

You can write a repository tier webscript (java or javascript) to cleanup nodes where "cm:autoVersionOnUpdateProps" property is set to false. 

Javascript based webscript can be directly deployed to "Data Dictionary > Web Scripts Extensions " directory without restarting the server. Follow the document here to learn more: https://docs.alfresco.com/6.2/tasks/ws-config.html

Learn more on creating webcripts here: 

https://docs.alfresco.com/6.2/concepts/ws-overview.html

https://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html#what-...

Steps you would do in the webscript:

1- Prepare a search query to return the nodes having  "cm:autoVersionOnUpdateProps" property as false. You could choose to do site by site/folder by folder or get all sites and iterate your search query using site short name.

2- Once nodes are returned, double check that whether "cm:autoVersionOnUpdateProps" property is false, if true- set the property value to true

3- save the node

-------------------

If you decide to use javascript based repo webscript, here is a sample webscript which you can try and make changes/tweak as per your need.

cleanupProperty.get.desc.xml

<webscript>
	<shortname>Cleanup existing value of a property</shortname>
	<description>Cleanup existing value of a property</description>
	<url>/cleanupProperty?propertyName={propertyName}&amp;existingPropertyVal={existingPropertyVal}&amp;newPropertyVal={newPropertyVal}&amp;folderPath={folderPath}&amp;siteShortName={siteShortName}&amp;contentTypes={contentTypes}&amp;skipCount={skipCount}&amp;maxCount={maxCount}</url>
	<format default="html">any</format>
  	<authentication>admin</authentication>
</webscript>
cleanupProperty.get.html.ftl

<html> <head> <title>Cleanup existing value of a property</title> </head> <body> <h4>Nodes which failed during update</h4> <#if failedNodes?is_hash_ex> <#assign keys = failedNodes ?keys> <#list keys as key>${key} - ${failedNodes [key]}; <br></#list> </#if> <h4>Successfully updated nodes</h4> <#if successNodes?is_hash_ex> <#assign keys = successNodes ?keys> <#list keys as key>${key} - ${successNodes [key]}; <br></#list> </#if> </body> </html>
cleanupProperty.get.js

main();

function main(){
	var propertyName =  args["propertyName"];
    var existingPropertyVal = args["existingPropertyVal"];
    var newPropertyVal = args["newPropertyVal"];
    var contentTypes = args["contentTypes"];
	var siteShortName = args["siteShortName"];
    var folderPath = args["folderPath"];
	var skipCount = (args["skipCount"]==null || args["skipCount"]==undefined)?0:args["skipCount"];
	var maxCount = (args["maxCount"]==null || args["maxCount"]==undefined)?100000:args["maxCount"];
  	
	var successNodes = [];
	var failedNodes = [];
  
    var query = buildSearchQuery(siteShortName, contentTypes, folderPath, propertyName, existingPropertyVal)
	var page = {
			skipCount : parseInt(skipCount),
			maxItems : parseInt(maxCount)
	};

	var searchQuery = {
			query : query,
			language : "fts-alfresco",
			page : page
	};
	
 	logger.log("Executing Search: "+query)
 	var nodes = search.query(searchQuery);
 	logger.log("Total Nodes found: "+nodes.length)
      
    for each(node in nodes) {
		try {
              logger.log("Updating the "+propertyName+" of node: "+node.name);
              node[propertyName] = newPropertyVal;
              node.save();
              successNodes[node.nodeRef] = node.name+" - Success";
		} catch(ex) {
			logger.log("Exception occurred: "+ex.message);
			failedNodes[node.nodeRef] = node.name+" - "+ex.message;
		}
	}
	model.successNodes = successNodes;
	model.failedNodes = failedNodes;
}

function buildSearchQuery(siteShortName, contentTypes, folderPath, propertyName, existingPropertyVal) {
    var query = 'PATH:"/app:company_home/st:sites/cm:' +siteShortName;
  
    if(folderPath=="") {
       query = query + '/cm:documentLibrary//*"';
    } else {
       query = query + '/cm:documentLibrary/';
       var pathTokens = folderPath.split('/');
       for (var each=0; each<pathTokens.length; each ++) {
         query = query +'cm:'+search.ISO9075Encode(pathTokens[each].trim())+'/';
       }
       query = query + '/*"';

    }
  
    var contentTypeArr = contentTypes.split(',');
	var arrayLength = contentTypeArr.length;

	if(arrayLength == 1) {
		query = query +' AND (TYPE:"' +contentTypeArr+'")';
	} else {
		query = query +' AND (';
		for (var each=0; each<arrayLength; each ++) {
			query = query + 'TYPE:"'+contentTypeArr[each].trim()+'"';
			if(each != arrayLength-1) {
				query = query + ' OR ';
			}
		}
      
		query = query +')';
	}
  
    //Append property and value query.
    if(!!existingPropertyVal) {
        var propertyParts = propertyName.split(':');
        if (propertyParts.length ==1 && (propertyName=="mimetype" || propertyName=="size")) {
           
           query = query +' AND @content.'+propertyName+':"'+existingPropertyVal+'"';
        } else {
           query = query +' AND @'+propertyParts[0]+'\\:'+propertyParts[1]+':"'+existingPropertyVal+'"';
        }
    }
    return query;
}

To execute the webscript, e.g.:

http://127.0.0.1:800/alfresco/service/cleanupProperty?propertyName=cm:autoVersionOnUpdateProps&exist...

You can utilize the folder path as well as use multiple content types (',' separated) as param.

I would strongly recommed to go through the tutorials and docs given above for better understanding and future prospects of webscript development.

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)