Sometimes we need to check info on certain attribute, content, templates, etc. for their existence or shared/unshared or status, etc. For such cases, you can write your own utility to do batch audit operations. I am listing sample code for few cases:
1. Any asset of a particular asset type with a name exists or not?
2. If a particular asset is present in site or not?
3. Check all variables of a particular asset
1. Any asset of a particular asset type with a name exists or not?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%><asset:list type="<%=asset_type%>" list="myList"><% | |
%><asset:argument name="name" value="<%=asset_name%>"/><% | |
%></asset:list><% | |
IList myList = ics.GetList("myList"); | |
if (myList != null && myList.hasData()) { | |
ics.SetVar(outputVar,"true"); | |
}else{ | |
ics.SetVar(outputVar,"false"); | |
} |
2. If a particular asset is present in site or not?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String siteId = ics.GetVar("pubidCS"); | |
if(Utilities.goodString(siteId)){ | |
%><asset:sites type="<%= asset_type %>" objectid="<%= asset_id%>" list="isinPub" pubid='<%= siteId%>' /> | |
<% if (ics.GetErrno()==0 && ics.GetList("isinPub")!=null && ics.GetList("isinPub").hasData()){ | |
ics.SetVar(outputVar,"true"); | |
} | |
}%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asset:load name = "theAsset" type = '<%=ics.GetVar("assettype")%>' objectid = '<%=ics.GetVar("assetid")%>' / > <% | |
if (ics.GetErrno() == 0) { %> | |
<asset:scatter name = "theAsset" prefix = "myAsset" /><br/><br/> | |
<h3>Asset Variables( <%= ics.GetVar("assettype") %> : <%= ics.GetVar("assetid") %> ) < /h3> | |
<table><% | |
Set<String> vars = new TreeSet<String>(); | |
for (Enumeration e = ics.GetVars(); e.hasMoreElements();) { | |
String sVarName = (String)e.nextElement(); | |
vars.add(sVarName); | |
} | |
for (String var:vars){ | |
String sVarValue = ics.GetVar( var ); | |
%><tr><td><%= var %></td> | |
<td> <%= sVarValue %></tr> | |
<%}%> | |
</table><% | |
} else { | |
%> Error Loading <%= ics.GetVar("assettype") %> : <%= ics.GetVar("assetid") %> ! < br / > <% | |
}%> |
Disclaimer: Any sample code on this blog is not officially recommended, use at your own risk.
No comments:
Post a Comment