Find Add-On by ID
This script searches for a specific add-on by its ID and lists the nodes and portlets associated with it.
warning
Running this script on a system with many nodes can take a long time. Use with caution and consider executing it in a development environment.
Code
const PropertyUtil = require('PropertyUtil');
const SearchUtil = require('SearchUtil');
const NodeTreeUtil = require('NodeTreeUtil');
const addonNodeIds = ['12.3456789abcdef012345', 12.3456789abcdef012345]; // Replace with the actual add-on ID
const result = SearchUtil.search('*:*', null, 0, 9999);
if(result.hasHits()) {
out.println('<table class="env-table env-table--large env-table--borders-around">');
out.println('<thead>');
out.println('<tr>');
out.println('<th>Page</th>');
out.println('<th>Portlet</th>');
out.println('</tr>');
out.println('</thead>');
out.println('<tbody>');
let hits = result.getHits();
while(hits.hasNext()) {
let hit = hits.next();
let hitNode = hit.getNode();
let foundPortlets = NodeTreeUtil.findPortlets(hitNode, (portlet) => addonNodeIds.includes(PropertyUtil.getString(portlet, 'portletName'))).toArray();
foundPortlets.forEach((portlet) => {
out.println('<tr>');
out.println('<td><a href="' + hit.getField('uri') + '">' + hitNode.toString() + '</a></td>');
out.println('<td>' + portlet.toString() + '</td>');
out.println('</tr>');
});
}
out.println('</tbody>');
out.println('</table>');
}
info
The condition PropertyUtil.getString(portlet, 'portletName') === addonNodeId can be replaced with any other property check depending on how the add-on is identified in the portlet's properties. For example:
const PropertyUtil = require('PropertyUtil');
const SearchUtil = require('SearchUtil');
const NodeTreeUtil = require('NodeTreeUtil');
const addonNodeIds = ['dbform', "form"]; // Replace with the actual add-on ID
const result = SearchUtil.search('*:*', null, 0, 9999);
if(result.hasHits()) {
out.println('<table class="env-table env-table--large env-table--borders-around">');
out.println('<thead>');
out.println('<tr>');
out.println('<th>Page</th>');
out.println('<th>Portlet</th>');
out.println('</tr>');
out.println('</thead>');
out.println('<tbody>');
let hits = result.getHits();
while(hits.hasNext()) {
let hit = hits.next();
let hitNode = hit.getNode();
let foundPortlets = NodeTreeUtil.findPortlets(hitNode, (portlet) => addonNodeIds.includes(PropertyUtil.getString(portlet, 'portletName'))).toArray();
foundPortlets.forEach((portlet) => {
out.println('<tr>');
out.println('<td><a href="' + hit.getField('uri') + '">' + hitNode.toString() + '</a></td>');
out.println('<td>' + portlet.toString() + '</td>');
out.println('</tr>');
});
}
out.println('</tbody>');
out.println('</table>');
}
Notes
- The
portletNodesarray is used to collect all matching portlets before rendering the output. - Replace the
addonNodeIdwith the ID of the add-on you want to search for. - Ensure the script is run in an environment where the
SearchUtilandNodeTreeUtilmodules are available.