Digests

Logging just one digest in digests_report_details - Digests

Logging just one digest in digests_report_details

by AndyHenderson » Sun Dec 15, 2024 9:26 am

First, thank you for this extension. I help run a set of forums for a set of volunteer-run charities helping people to make the most of life once they are no longer in full time work by exploring new ideas, skills and interests.

Our forums are dedicated to helping those members that use WordPress for their web sites and recent developments have seen their usefulness increase dramatically. The digests extension helps members stay in touch with those developments.

I also appreciate you are winding down your activities, so it seems a little churlish to report what seems to be an error, but here goes...

In our mailing report, we can see digests are going out at the scheduled time and our Amazon SES console shows corresponding stats for numbers of emails sent. However, if I click the 'Digests mailed' entry I see only one user listed even though there were several digests sent. If I click a non-zero 'Digests skipped' entry, I see "The database may be inconsistent. No digest detail records can be found for this date and hour."

Looking at the database, I see there is just one xxx_digests_report_details record for any given xxx_digests_report record. The mailing report is showing what it can from the database, which is incomplete.

Looking at the code for version 3.3.18, I think there's an error in the save_report_statistics routine in phpbbservices/digests/cron/task/digests.php.

Inside the loop started at 2558:

Code: Select all

foreach ($details as $detail)
Line 2563 is:

Code: Select all

$detail['user_id'] = key($details);
You then create a xxx_digests_report_details record for that user_id. Unfortunately, using key() inside a foreach loop this way will always return the key of the first entry so, each time around the loop, you are writing/overwriting the same xxx_digests_report_details record.

I suggest the loop should be:

Code: Select all

foreach ($details as $key => $detail)
and line 2563 should be:

Code: Select all

$detail['user_id'] = $key;
I can't apply that patch right now because we are in the middle of producing our first digests under a new environment that triggers app.php/cron/phpbbservices.digests.cron.task.cron_task from an external site, and uses Amazon SES for emailing, so I don't want to add another complicating factor to the run. I'll make the change later in the week as we have just a few daily digests so less impact if I got that wrong.

Thanks again,

Andy
AndyHenderson
Registered User
Posts: 2
Joined: Wed Jan 19, 2022 2:58 pm

Re: Logging just one digest in digests_report_details

by AndyHenderson » Mon Dec 16, 2024 8:35 am

After a successful day yesterday, I decided to chance my arm and applied the patch and arranged for a daily digest to include two digests for 8am.

Fortunately, I spotted that another change was needed. Line 2566:

Code: Select all

$sql = 'DELETE FROM ' . $this->report_details_table . ' WHERE ' . $this->db->sql_build_array('DELETE', array('digests_report_id' => (int) $digests_report_id, 'user_id' => key($details)));
should be:

Code: Select all

$sql = 'DELETE FROM ' . $this->report_details_table . ' WHERE ' . $this->db->sql_build_array('DELETE', array('digests_report_id' => (int) $digests_report_id, 'user_id' => $key));
The patch worked. It now shows everyone included in each set of digests, but with one issue. You are using a br tag to separate each line, which doesn't work in Javascript Alerts. To fix that, in phpbbservices/digests/controller/acp_controller.php line 2191:

Code: Select all

return (count($detail_rows) == 0) ? $this->language->lang('DIGESTS_NO_DETAILS_ERROR') : implode('<br>', $detail_rows);
should be:

Code: Select all

return (count($detail_rows) == 0) ? $this->language->lang('DIGESTS_NO_DETAILS_ERROR') : implode('\n', $detail_rows);
I hope that helps.
AndyHenderson
Registered User
Posts: 2
Joined: Wed Jan 19, 2022 2:58 pm