[ticket/12034] Move similar code in the two callbacks to separate function.

PHPBB3-12034