Some questions or answers are missing after a XML import

Symptoms

After importing data from another instance using a Confluence XML Backup you will notice that some questions/answers will be missing or will not show up in in the unanswered/Recent section:

The popular tab may also display no questions.

The following appears in the atlassian-confluence.log:

2014-08-11 13:27:03,328 ERROR [ajp-bio-8010-exec-2] [atlassian.confluence.servlet.ConfluenceServletDispatcher] sendError Could not execute action
 -- url: /questions | userName: lavitz | referer: http://confluence:8090/admin/mail/viewmailqueue.action
java.lang.IllegalArgumentException: author is required
	at com.atlassian.confluence.plugins.questions.model.QuestionImpl.<init>(QuestionImpl.java:49)
	at com.atlassian.confluence.plugins.questions.model.QuestionImplBuilder.build(QuestionImplBuilder.java:118)
	at com.atlassian.confluence.plugins.questions.contenttype.repository.ContentTypeMapper.toQuestion(ContentTypeMapper.java:93)
	at com.atlassian.confluence.plugins.questions.contenttype.repository.ContentTypeMapper.toAnswer(ContentTypeMapper.java:120)
	at com.atlassian.confluence.plugins.questions.contenttype.repository.ContentTypeMapper$1.apply(ContentTypeMapper.java:175)
	at com.atlassian.confluence.plugins.questions.contenttype.repository.ContentTypeMapper$1.apply(ContentTypeMapper.java:171)
	at com.google.common.collect.Iterators$8.next(Iterators.java:812)
	at com.google.common.collect.Lists.newArrayList(Lists.java:139)

 

Diagnosis

To validate if you have orphan questions or answers please run the queries below:

Answers without questions:

SELECT * FROM CONTENT WHERE PLUGINKEY IN ('com.atlassian.confluence.plugins.confluence-questions:answer', 'com.atlassian.confluence.plugins.confluence-questions:comment') AND PARENTCCID IS NULL AND PREVVER IS NULL;

Questions and answers without a creator:

SELECT * FROM CONTENT WHERE PLUGINKEY LIKE 'com.atlassian.confluence.plugins.confluence-questions:%' AND CREATOR IS NULL;

 

If any of the above returned results please read the Cause and Resolution sections.

Cause

During the xml import process the data was corrupted and some of the questions/answers were orphaned (they do not have a parent question or creator), due to that, the plugin will not be able to run its indexing tasks on the startup. This will cause the unanswered/Recent section to not show any results and some questions or sections will no longer be reachable.

Resolution

The resolution for this misbehaviour is to map the orphan answers to a parent question and the orphan questions to a creator. Based on the results on the diagnostic section you might only need to follow one of below set of instructions instead of both.

Before applying this procedure make sure to test it on a test instance and please backup your database and application directories before applying in production.

In case of answers without questions:

  1. Create a new question with the name of "Answers to Purge"

    This will be the parent question for the orphan answers.

  2. Once the question is created you will see that the URL contains a number, that is the contentid which we will need to take note of:
  3. Shutdown Confluence.
  4. Run the below update query against your database:

    Query for MySQL database
    UPDATE CONTENT answers
    LEFT JOIN CONTENT questions
            ON questions.PLUGINKEY = 'com.atlassian.confluence.plugins.confluence-questions:question'
            AND questions.contentid = answers.parentccid
    INNER JOIN CONTENTPROPERTIES as answerProperties
            ON answerProperties.contentid = answers.contentid
                    AND answerProperties.propertyname = 'accepted'
    SET answers.parentccid = '2850828', answerProperties.longval = 0
    WHERE answers.pluginkey = 'com.atlassian.confluence.plugins.confluence-questions:answer'
            AND answers.prevver IS NULL
            AND questions.contentid IS NULL;

    Make sure to replace the 2850828 value in the above query with the contentid noted in step 2.

  5. Start Confluence.

  6. Test the section feature again.
  7. If everything is working you can delete the "Answers to Purge" question.

 

In case of questions and answers without a creator:

  1. Choose a existing user or create a new one to be the author of the orphan answers/questions.
  2. Shutdown Confluence.
  3. Take note of the user key for that chosen user in step 1:

    SELECT user_key
    FROM user_mapping
    WHERE username = 'admin'

    Make sure to replace the admin value in the above query with the user name of the chosen user from step 1.

  4. Now run the below update query so we can link the orphan answers/question to the chosen user:

    UPDATE CONTENT
    SET CONTENT.creator = "8a8ba1dc46f894650146f97ba5930003", content.lastmodifier = "8a8ba1dc46f894650146f97ba5930003"
    WHERE CONTENT.pluginkey LIKE 'com.atlassian.confluence.plugins.confluence-questions:%'
    AND CONTENT.CREATOR IS NULL;

    Make sure to replace the "8a8ba1dc46f894650146f97ba5930003" value in above query with the user key from step 3.

  5. Start Confluence.

  6. Check if the feature is working again.
Last modified on Nov 2, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.