Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is it possible to search the Confluence Databases for instances of a specific macros?

Ian Mason May 2, 2014

We are looking to remove/disable a macros on our instance of confluence, but we need to run a check to see if any pages are using the plugin to preclude their media from breaking? Can one query the Confluence DB for occurrences of a macros on any pages within Confluence?

2 answers

1 vote
Evelin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2014

You can use the search to find out if a macro was inserted on one or more pages. An example: If you like to know if the multiexcerpt or multiexcerpt-include macro has been used in your Confluence, type macroName:multi* in the Search field, and hit Enter.

Ian Mason May 4, 2014

So if I'm looking for Widget Connector, can I search "macroName:'Widget Connector'"?

Evelin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2014

Yes, I tried macroName:widget* and it worked.

0 votes
discountrobot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2014

Hey, Ian.

You can do this via the XMLRPC

Here is a example written in python finding all pages with a instance of the thumbnail macro (ac:thumbnail)

Once complete all links containing said macro are written to a errors.json file.

#!/usr/bin/env python
import xmlrpclib
import json

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

    def disable(self):
        self.HEADER = ''
        self.OKBLUE = ''
        self.OKGREEN = ''
        self.WARNING = ''
        self.FAIL = ''
        self.ENDC = ''

#Confluence XML-RPC info
url 		= 'http://localhost:1990/rpc/xmlrpc'
client 		= xmlrpclib.Server(url, verbose=0);
authToken	= client.confluence2.login("admin", "admin");
spaces 		= client.confluence2.getSpaces(authToken);
# Error stack
errors 		= []
# Macro definition we're looking for
macro = "ac:thumbnail"

for space in spaces:
  print ("Parsing space: " + space['name']);
  spacePages = client.confluence2.getPages(authToken,space['key'])
  for spacePage in spacePages:
      print ("- Parsing page: " + spacePage['title']);
      # get the page in question with content
      page = client.confluence2.getPage(authToken, spacePage["id"])
      # did we find the macro definition?
      if(page["content"].find(macro) > 0):
        print ("{0}Found {1} macro!{2}".format(bcolors.WARNING, macro, bcolors.ENDC))
        errors.append(spacePage["url"])

# print the errors
for error in errors:
	print error["url"]

#store the errors
with open('errors.json', 'w') as outfile:
  json.dump([errors], outfile)

client.confluence2.logout(authToken)

Ian Mason May 4, 2014
For this line of code -
# Macro definition we're looking for
macro = "ac:thumbnail"
where do we find macro = "sometext" in Confluence?
discountrobot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2014

To view the macro handle, go to a page containing the macro and click Tools->View Storage format

You should now see something like this:

<ac:structured-macro ac:name="tip">

where tip is the macro handle. Try this with the answer by Evelin
Or simply update the lines

# Macro definition we're looking for
macro = 'ac:structured-macro ac:name="tip"'

discountrobot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2014

The macro handle for Widget Connector is simply :)

ac:structured-macro ac:name="widget"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events