XF 2.2 Template email:activity_summary_latest_threads error

MJ0730

Active member
Just got this error for all the activity summary emails that tried to send.

Code:
TypeError: Template email:activity_summary_latest_threads error: Argument 1 passed to XF\Str\Formatter::wholeWordTrimBbCode() must be of the type string, null given, called in /home/pointsixtyfive/public_html/xenforo/src/XF/Template/Templater.php on line 2375 src/XF/Str/Formatter.php:644
Generated by: KiloFoxtrot1 Jul 19, 2021 at 9:20 AM
Stack trace
#0 src/XF/Template/Templater.php(2375): XF\Str\Formatter->wholeWordTrimBbCode(NULL, 300)
#1 src/XF/Template/Templater.php(2387): XF\Template\Templater->fnBbCodeSnippet(Object(XF\Mail\Templater), false, NULL, 'post', NULL, 300, Array, 'emailHtml')
#2 [internal function]: XF\Template\Templater->fnBbCodeTypeSnippet(Object(XF\Mail\Templater), false, 'emailHtml', NULL, 'post', NULL, 300)
#3 src/XF/Template/Templater.php(1121): call_user_func_array(Array, Array)
#4 internal_data/code_cache/templates/l1/s5/email/activity_summary_latest_threads.php(41): XF\Template\Templater->func('bb_code_type_sn...', Array, false)
#5 src/XF/Template/Templater.php(1644): XF\Template\Templater->{closure}(Object(XF\Mail\Templater), Array, NULL)
#6 src/XF/Mail/Mailer.php(216): XF\Template\Templater->renderTemplate('activity_summar...', Array)
#7 src/XF/ActivitySummary/AbstractSection.php(172): XF\Mail\Mailer->renderPartialMailTemplate('activity_summar...', Array, Object(XF\Language), Object(SV\WarningImprovements\XF\Entity\User))
#8 src/XF/ActivitySummary/LatestThreads.php(123): XF\ActivitySummary\AbstractSection->renderSectionTemplate(Object(XF\ActivitySummary\Instance), 'activity_summar...', Array)
#9 src/XF/ActivitySummary/AbstractSection.php(46): XF\ActivitySummary\LatestThreads->renderInternal(Object(XF\ActivitySummary\Instance))
#10 src/XF.php(613): XF\ActivitySummary\AbstractSection->XF\ActivitySummary\{closure}()
#11 src/XF/ActivitySummary/AbstractSection.php(47): XF::asVisitor(Object(SV\WarningImprovements\XF\Entity\User), Object(Closure))
#12 src/XF/Job/ActivitySummaryEmail.php(144): XF\ActivitySummary\AbstractSection->render(Object(XF\ActivitySummary\Instance))
#13 src/XF/Job/ActivitySummaryEmail.php(111): XF\Job\ActivitySummaryEmail->generateEmailData(Object(SV\WarningImprovements\XF\Entity\User))
#14 src/XF/Job/ActivitySummaryEmail.php(67): XF\Job\ActivitySummaryEmail->generateAndSendEmail(Object(SV\WarningImprovements\XF\Entity\User))
#15 src/XF/Job/Manager.php(258): XF\Job\ActivitySummaryEmail->run(8)
#16 src/XF/Job/Manager.php(200): XF\Job\Manager->runJobInternal(Array, 8)
#17 src/XF/Job/Manager.php(84): XF\Job\Manager->runJobEntry(Array, 8)
#18 job.php(43): XF\Job\Manager->runQueue(false, 8)
#19 {main}
Request state
array(4) {
  ["url"] => string(16) "/xenforo/job.php"
  ["referrer"] => string(35) "https://****.com/xenforo/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 
Solution
I'd strongly recommend not using that add-on in future. That may have introduced the unexpected data.

Anyway, to fix this you just need to go to Admin > Tools > Rebuild caches.

You need to run the "Rebuild threads" tool.

That should fix the first/last post info. After that has completed you should be able to run the last MySQL query I posted and hopefully it shouldn't yield any results.

Chris D

XenForo developer
Staff member
We've looked into this and it's not something we can reproduce and the output of the stack trace seems to be unexpected:

Code:
#2 [internal function]: XF\Template\Templater->fnBbCodeTypeSnippet(Object(XF\Mail\Templater), false, 'emailHtml', NULL, 'post', NULL, 300)

The NULL values here imply that the usage of $thread.FirstPost in the template results in a null value:

Code:
arg-content="{{ bb_code_type_snippet('emailHtml', $thread.FirstPost.message, 'post', $thread.FirstPost, 300) }}"

For FirstPost to be null, it indicates that the thread has a first_post_id value that doesn't exist in the post_id column in the xf_post table.

Ideally you need to ascertain if there are any threads in this state, how they got into that state and fix them.

To check which threads exhibit this issue, you may be able to run this query:

SQL:
SELECT thread.thread_id
FROM xf_thread AS thread
LEFT JOIN xf_post AS post ON
    (thread.first_post_id = post.post_id)
WHERE post.post_id IS NULL
    AND thread.discussion_type <> 'redirect'

That may help you identify those threads and hopefully shed some light on why this is happening.

Once you can see that, we may have further advice to help fix the issue but let us know first :)
 

MJ0730

Active member
the query produced some results.

SQL:
thread_id
3420
3539
3661
3690
3691
3692
3694
3695
3697
3698
3700
3701
3702
3703
3708
3709
3710
3712
3713
3714
3715
3716
3717
3718
3719

Not sure what I'm looking for on those threads though.

I think I've also narrowed down the error to only occurring when a specific addon is enabled, but the author says it's an xF issue and not related to the addon. You can see it in the error message
#11 src/XF/ActivitySummary/AbstractSection.php(47): XF::asVisitor(Object(SV\WarningImprovements\XF\Entity\User), Object(Closure))
 

Chris D

XenForo developer
Staff member
That add-on being mentioned there doesn't necessarily imply that it is causing any issue. That is just the last add-on in the chain of add-ons that may extend the XF user entity and, because that is user related it's almost certainly not relevant.

But, perhaps, it is an add-on that is relevant here.

If you go to your forum home page and add threads/3710/ to the URL this will open one of the threads that's been identified by that query.

If I had to hazard a guess, it looks like some sort of wiki page? That may be inserted into the database in such a way that it doesn't have a first or last post.

But not all threads appear to be wiki pages. Some are resource discussions, others look like normal threads. These should definitely have first post IDs.

Can you run this query:

SQL:
SELECT thread.thread_id, thread.first_post_id
FROM xf_thread AS thread
LEFT JOIN xf_post AS post ON
    (thread.first_post_id = post.post_id)
WHERE post.post_id IS NULL
    AND thread.discussion_type <> 'redirect'

This will tell us what first_post_id the threads are trying to reference (if any).

There's still an easy way to repair this situation but ideally still want to see what data is in there in case there's anything we can do to workaround it or figure out why the data might not be correct.
 

MJ0730

Active member
The wiki pages make sense, I had to move some pages around when I converted it. As for the addon, I don't get this error when it's disabled, so maybe not directly effecting it but some side effect.

heres the query.

thread_idfirst_post_id
342053691
35398
366153691
36908
36918
36928
36948
36958
36978
36988
37008
37018
37028
37038
370853691
370953691
371053691
371253691
371353691
371453691
371553691
371653691
371753691
371853691
371953691
 

Chris D

XenForo developer
Staff member
Well those results are entirely unexpected.

Have you ever done anything in the database directly that may have changed the first_post_of value or ran any tool to try and split threads or anything like that?

Just seems odd.

There’s only two different first_post_id values in your list there but of course each thread should have its own first post ID. It shouldn’t be possible for different threads to have the same post.

Any idea how that might have happened?
 

MJ0730

Active member
Haven't touched the database. For some of the wiki pages I used an addon to change the first post, but there were more threads I did that to than are listed here. They're all sorta grouped together, and those threads were created a while ago, so maybe an upgrade or addon somewhere along the line messed with it.
 

Chris D

XenForo developer
Staff member
I'd strongly recommend not using that add-on in future. That may have introduced the unexpected data.

Anyway, to fix this you just need to go to Admin > Tools > Rebuild caches.

You need to run the "Rebuild threads" tool.

That should fix the first/last post info. After that has completed you should be able to run the last MySQL query I posted and hopefully it shouldn't yield any results.
 
Solution

MJ0730

Active member
Yeah, I only used it when I was merging some old threads into the wiki section.

Query comes back empty now. I reenabled warning improvements addon to see if the errors get generated again.
 
Top