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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Could Scriptrunner be used to identify Confluence pages with broken image links?

Hello, 

The company I work for, among with many others, has been affected by this Confluence bug (https://jira.atlassian.com/browse/CONFSERVER-55928) that causes images in Confluence pages to not appear within the page. Atlassian has released a fix in the 7.7.3 version of Confluence that will prevent this from happening again, but won't fix existing pages, or identify pages that are affected. 

Does anyone know if it would be possible to write code using Scriptrunner for Confluence that would identify pages that are affected by this issue, so we can quickly find all the affected pages and correct them?

Thank you,

Anja Brkljacic

2 answers

1 accepted

Hey there Anja! :D

In short, yes absolutely you can do this! :)

I've reproduced the bug that you linked and it looks like any page that is experiencing the bug will contain some place-holder "unknown-attachment" image in the Storage Format that looks something like this:

<p><br /></p>
<p><ac:image><ri:url ri:value="{hiddenPersonalUrl}/plugins/servlet/confluence/placeholder/unknown-attachment?locale=en_US&amp;version=2" /></ac:image></p>

So, one thing we can do is search all of your pages and their content to see if the page contains this "unknown-attachment" image. You could technically just create a custom script that searches every single page in your instance, but something like that could take a looooooong long time to run...so it's probably not the best approach. Instead, an easier way to do this would be to just create a simple Search Extractor. Doing this will allow you to go through each Space individually (instead of every space all at once) and identify troublesome pages. I tested this locally and used a search extractor with the following code as my Inline script:

import com.atlassian.confluence.pages.Page
import org.apache.lucene.document.Field
import org.apache.lucene.document.StringField

if (searchable instanceof Page) {
Page page = searchable as Page
def pageBodyContent = page.bodyContents
def containsUnknown = pageBodyContent.find { it.body.contains("unknown-attachment") }

if (containsUnknown) {
document.add(new StringField("containsUnknown", "true", Field.Store.YES))
} else {
document.add(new StringField("containsUnknown", "false", Field.Store.YES))
}
}

Keep in mind, after creating this extractor you'll need to reindex your instance so that all of your content is appropriately flagged with the "containsUnknown" field. But after indexing, you should be able to run an Advanced Search like the following and specify which space(s) you'd like to search:


Screen Shot 2020-09-03 at 4.41.35 PM.png

Now, disclaimer, I only tested this on a very small group of test pages and in an instance that's basically empty, so your mileage may vary. But I'd give that a shot and see if it returns the problem pages that you're looking for. 

Hope that helps! :D

Best,

Aidan

Thanks, Aidan! We will try this out and let you know how it worked/mark it as the answer :)

We tried this and it seems to have worked so far :) thanks, again!

Hey there Anja! :D

In short, yes absolutely you can do this! :)

I've reproduced the bug that you linked and it looks like any page that is experiencing the bug will contain some place-holder "unknown-attachment" image in the Storage Format that looks something like this:

<p><br /></p>
<p><ac:image><ri:url ri:value="{hiddenPersonalUrl}/plugins/servlet/confluence/placeholder/unknown-attachment?locale=en_US&amp;version=2" /></ac:image></p>

So, one thing we can do is search all of your pages and their content to see if the page contains this "unknown-attachment" image. You could technically just create a custom script that searches every single page in your instance, but something like that could take a looooooong long time to run...so it's probably not the best approach. Instead, an easier way to do this would be to just create a simple Search Extractor. Doing this will allow you to go through each Space individually (instead of every space all at once) and identify troublesome pages. I tested this locally and used a search extractor with the following code as my Inline script:

import com.atlassian.confluence.pages.Page
import org.apache.lucene.document.Field
import org.apache.lucene.document.StringField

if (searchable instanceof Page) {
Page page = searchable as Page
def pageBodyContent = page.bodyContents
def containsUnknown = pageBodyContent.find { it.body.contains("unknown-attachment") }

if (containsUnknown) {
document.add(new StringField("containsUnknown", "true", Field.Store.YES))
} else {
document.add(new StringField("containsUnknown", "false", Field.Store.YES))
}
}

Keep in mind, after creating this extractor you'll need to reindex your instance so that all of your content is appropriately flagged with the "containsUnknown" field. But after indexing, you should be able to run an Advanced Search like the following and specify which space(s) you'd like to search:


Screen Shot 2020-09-03 at 4.41.35 PM.png

Now, disclaimer, I only tested this on a very small group of test pages and in an instance that's basically empty, so your mileage may vary. But I'd give that a shot and see if it returns the problem pages that you're looking for. 

Hope that helps! :D

Best,

Aidan

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.5.2
TAGS
Community showcase
Published in Confluence Cloud

Get to know the Confluence team!

Go “behind the screen” to meet some of the Confluence Cloud team. In this video series, we tackle some of the hard-hitting questions you never knew you wanted the answer to!  Meet some of the ...

236 views 0 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you