Schedule for emailing PDF reports

When creating a PDF report and setting the email schedule the text says

Weekly schedule: report will be sent the first Monday of each week.
Monthly schedule: report will be sent the first day of each month.

This doesn’t seem to happen.
I have set up a cron job to run every hour and found that:
a new pdf report is emailed when the cron job is next run
then, for a weekly report, it seems to be scheduled for one week later, not on the next Monday
for a monthly report, seems to be scheduled for one month later, not on the first day of the month

I have looked at the code in plugins/PDFReports/PDFReports.php at method getScheduledTasks()

[size=8pt] function getScheduledTasks ( $notification )
{
$tasks = &$notification->getNotificationObject();
$tasks[] = new Piwik_ScheduledTask ( $this, ‘dailySchedule’, new Piwik_ScheduledTime_Daily() );
$tasks[] = new Piwik_ScheduledTask ( $this, ‘weeklySchedule’, new Piwik_ScheduledTime_Weekly() );
$tasks[] = new Piwik_ScheduledTask ( $this, ‘monthlySchedule’, new Piwik_ScheduledTime_Monthly() );
}[/size]

I think that the scheduled tasks need to set hour/day/week so that the PDF reports are generated at the expected times.

set Hour to be 1 (for 1:00 am) for each scheduled task
set Day to be 1 (this is actually day of week, 1 = Monday) for the weekly task

But it is not clear how to make the monthly task run on the first day of the month, as Piwik_ScheduledTime_Monthly does not provide a method to set that. We can set only the hour/day of week/week of month. The lines below for $daily and $weekly have the correct effect but $monthly doesn’t.

[size=8pt] function getScheduledTasks ( $notification )
{
$tasks = &$notification->getNotificationObject();[/size]

[size=8pt] $daily = new Piwik_ScheduledTime_Daily();
$daily->setHour(1);
$tasks[] = new Piwik_ScheduledTask ( $this, ‘dailySchedule’, $daily);[/size]

[size=8pt] $weekly = new Piwik_ScheduledTime_Weekly();
$weekly->setHour(1);
$weekly->setDay(1);
$tasks[] = new Piwik_ScheduledTask ( $this, ‘weeklySchedule’, $weekly);[/size]

[size=8pt] $monthly = new Piwik_ScheduledTime_Monthly();
$monthly->setHour(1);
$monthly->setDay(1);
$monthly->setWeek(1);
$tasks[] = new Piwik_ScheduledTask ( $this, ‘monthlySchedule’, $monthly);
}[/size]

I have looked in the forums and also in Trac and cannot see any issue addressing this problem.

hello
patch in http://dev.piwik.org/trac/changeset/3038 should fix this issue

[quote=matthieu @ Sep 6 2010, 03:01 PM]hello
patch in dev.piwik.org/trac/changeset/3038 should fix this issue[/quote]

Thanks for the reply. That patch fixes a different problem of pdf reports not being emailed at all. I have already applied that fix and now piwik does email pdf reports.
The problem that I tried to describe is the scheduling of the weekly and monthly reports does not match the advisory text on the page. The weekly schedule can be set to be the Monday with the code in my example, but there doesn’t seem to be a way to make the monthly schedule happen on the first day of the month.

How do I set up a cron job for the mail sceduler. I cant find any info about that. I have set up the daily archive cron but I can’t find a .sh file for mail.

The archive script also runs scheduled tasks which include the pdf reports.
Emails though will not be sent unless you apply trac entry 3038.

Okay, thanks for that information. Maybe that script should be called something else so its clear what it does. I thought it only did take care of archiving my reports.

I just wanted to say thanks, as the OP helped me sort out an issue I was having with getting the reports to send as well.

Just out of interest, did you have an issue where the reports were sent to the email address of the Superuser only?

If not, I’ll start my own thread.

[quote=Sid351 @ Sep 8 2010, 09:29 AM]Just out of interest, did you have an issue where the reports were sent to the email address of the Superuser only?

If not, I’ll start my own thread.[/quote]

No problem with sending to more than one destination. My reports are sent to the super user and to one extra email address.

Sorry, I wasn’t clear enough.

I’ve got a couple extra users defined, and when “User1” created the report it got emailed to the address associated with the “Superuser” account.

I’ll start a new thread.

[quote=duncanc @ Sep 6 2010, 04:46 PM]Thanks for the reply. That patch fixes a different problem of pdf reports not being emailed at all. I have already applied that fix and now piwik does email pdf reports.
The problem that I tried to describe is the scheduling of the weekly and monthly reports does not match the advisory text on the page. The weekly schedule can be set to be the Monday with the code in my example, but there doesn’t seem to be a way to make the monthly schedule happen on the first day of the month.[/quote]

Hi duncanc,
I have applied your fix (setting 1st Hr and 1st day) to my code but it seems like not working.
If I check scheduled time in Piwik_option table, it is showing me with exact day/week difference with scheduling time.
What I mean is, I scheduled a daily report today 3pm…next schedule time is tomorrow 3pm (not 1AM),
Same behavior with month and week…I scheduled weekly report Thursday…next run time is next Thursday(not monday).
anyone facing the same issue?

Sorry for my bad explaination style_emoticons/<#EMO_DIR#>/sad.gif

Thanks for the report, we will investigate this issue asap.

Thanks for the report.

We created 3 track tickets to solve the issues :

Sincerely.

These issues were fixed in Piwik 1.3, but also the issue that emails were not send if you are not using the cron, is also fixed in the latest RC: 301 Moved Permanently

I am on 1.8.4, email PDF report daily. Archiving is running every hour, on the dot, by CRON daily.

The first PDF report arrives at 8:45AM, and continue to do so for a few days. Later, the reports are sent at 9:00AM, automagically.

Is it possible to specify the time the reports (daily, weekly and monthly) are sent? It is difficult to tell clients to “just wait for the report, we don’t know what time we get them neither”.

Please add your suggestion to Scheduled report list of improvements · Issue #3088 · matomo-org/matomo · GitHub with use case & convincing :wink: