Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel3
minLevel3
typeflat
separatorpipe

Description

Often the need arises to find pages that have certain content and modify it slightly. If the number of pages is larger, making manual modifications can be painful and error prone. Automation can help, but you have to make sure that you are modifying exactly what you want and not something unintentional. See also this user question for a discussion on this topic.

Tip
titleRequires CLI 3.6 or higher

While this can be done using older releases, a number of simplifications have been added to 3.6 to make it easier to deal difficult escaping rules for dealing with XHTML content and command line special values.

Warning
titleUpdating storage format

Always be careful updating storage format data and make sure you test before doing mass updates.

Example 1: Changing a url

Changing a link. For instance: http://myjira.com to http://mynewjira.com.

Steps

  1. Setup an example page 

    No Format
    --action storePage --space xxx --title test --parent @home --content "aaa http://myjira.com bbb"
  2. Construct a modifyPage action for a single page using a simple text replace. Since : (colon) is in the text and is the default key:value separator for CLI, use # instead using the special parameter (spaces are significant!) 

    No Format
    --action modifyPage --space xxx --title at --findReplace "http://myjira.com#http://mynewjira.com" --special " #"
  3. Run against all pages with the link (using unix style escaping - see Tips). Run against your test space first before using @all.

    No Format
    --action runFromContentList --search "\"http://myjira.com\"" --space @all --common "--action modifyPage --id @pageId@ --findReplace \"http://myjira.com#http://mynewjira.com\" --special \" #\" "
  4. Results 

    No Format
    Run: --action modifyPage --id 112197680 --findReplace "http://myjira.com#http://mynewjira.com" --special " #" 
    Page modified: 'at' in space: xxx. Page has id: 112197680
    ...

Example 2: Renaming a macro

There are a few cases why you may need to rename a macro:

  1. A user macro may need a better name or may conflict with macro from a new plugin
  2. A macro may no longer be valid because you have discontinued a plugin or removed a user macro, but you want to save the body of the macro

Steps

  1. Determine the kind of body the existing macro has
    1. Plain text like the noformat macro
    2. Rich text like the panel macro
  2. Make sure the target macro has the same body type
  3. Use the techniques of Example 1
    • runFromPageList may be more appropriate for many case

...

Tip
titleFinding pages with macros

This answer describes a technique using content search to find pages with a macro. Summarizing - use something like: "macroName: table-plus*"

 

Example 3: Changing XHTML content

This site has many pages created via automation, often by a Bamboo build process. Confluence has an annoying feature (sad) that converts simple wiki text like @entry@ into XHTLM reference to a template variable. There doesn't seem to be a way to escape this behavior. The result is a number of pages with incorrect data. This examples shows how this was corrected.

...