Automatic email pdf report not working

krasten, do this test.

  1. create a daily report
  2. add this test code in
    function dailySchedule()
    {
    // flag here
    $myFile = “/home/flag_dailyschedule.txt”;
    $fh = fopen($myFile, ‘w’);
    fwrite($fh, ‘ok’);
    fclose($fh);
    // end flag
    $this->generateAndSendScheduledReports(‘day’);
    }
  3. delete tmp/cache/tracker/general.php
  4. Open your homepage
  5. Delete the flag
    // flag here
    $myFile = “/home/flag_dailyschedule.txt”;
    $fh = fopen($myFile, ‘w’);
    fwrite($fh, ‘ok’);
    fclose($fh);
    // end flag

You should have the tmp/cache/tracker/general.php again
Do you have the file flag_dailyschedule.txt created?

@bolero:
No ‘noreply’ in mail.log, mail.err oder mail.info :frowning:

@jobs.mowster.net:

flag_dailyschedule.txt is created. So I headed to generateAndSendScheduledReports() and added

//flag here
$myFile = "/tmp/flag_generateAndSendScheduledReports.txt";
$fh = fopen($myFile, 'w');
fwrite($fh, $report['idreport'] );
fclose($fh);
// end flag

which is creating the file, too.

Next was sendEmailReport() and I inserted


//flag here
$myFile = "/tmp/flag_sendEmailReport.txt";
$fh = fopen($myFile, 'a+');
fwrite($fh, "\nStart: ".$outputFilename."\n" );
foreach($emails as $key=>$val){
  fwrite($fh, $key.': '.$val."\n" );
}
foreach($report as $key=>$val){
  fwrite($fh, $key.': '.$val."\n" );
}
fclose($fh);
// end flag

right above $this->sendReportEmailPdfAttached(
This file was not created.

@karsten
In my case, it hangs in getScheduledTasks. It’s my last flag I can get…

Karsten, I’m not convinced that it is the emailing step that fails for you. The PDF report is saved in the piwik tmp directory before the message gets created and sent. I told this before and asked to look there. As you didn’t tell us that you had reports piling up there I assume you don’t. Which means the report isn’t getting created. That’s a step before the sending. Did you check your php error log? If you don’t have one set logging to a file in php.ini.

@bolero

pdf file is created in sendEmailReport() function
his routine is not reaching there, impossible to find the pdf in the tmp folder

So, as I wrote, it is not the sending but the creation that fails.

@bolero
Sorry I forgot to mention.
Neither /path/to/piwik/tmp nor /tmp contains any pdf. The error log is ok.

It’s /path/to/piwik/tmp that would contain it. You do have a php error log? If there is an error it won’t be in any system log. Maybe you need to make it more verbose.

Ok, I think I found something:

In /plugins/PDFReports/API.php function generateReport() you call:


$report = Piwik_API_API::getInstance()->getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters, $language);

Please note that there’s no try-catch around that report = Piwik_API_API::getInstance()->getProcessedReport().

In /plugins/API/API.php, function getProcessedReport() which is called by above code:


try {
  /** @var Piwik_DataTable */
  $dataTable = $request->process();
} catch(Exception $e) {
  throw new Exception("API returned an error: ".$e->getMessage()."\n");
}

Within the catch you throw another exception, but that’s not catched from PDFReport/API.php as there is no try/catch-block.
In my case, the API want’s to throw an exception ('No entry is registered for key ‘logger_message’.), but that did not work and the script breaks.

Sidenote: For some strange reasons, there is no php errorlog on my server and the apache errorlog is ok. I’ll look into that.

In my case routine stops here

$tasks[] = new Piwik_ScheduledTask ( $this, ‘dailySchedule’, $dailySchedule );
:S

Karsten, it’s the default to have no php error log. But it’s good hoster practice to set one in php.ini, it’s really helpful for getting a feeling of what’s going on. That’s why I have it on all my servers :slight_smile:

Bolero: The point with the logging is: It’s my server and I was sure that it’s enabled. I fixed it now.

But I not sure how to accurately fix the ‘un-catched’ exception I mentioned earlier.
When adding a try/catch block around

$report = Piwik_API_API::getInstance()->getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters, $language);

the mails are generated. But each time the script tried to throw an exeption before, it now generates an empty PDF and could not find a Site-Name. :frowning:
I suppose before calling Piwik_API_API::getInstance()->getProcessedReport(), I will have to check each parameter. It only set has to be set, but it has to have a valid value. Right now I do not know which values are expected by the method, so I have to investigate a little more…

Yes, maybe the $idSite is empty, maybe something else. I think you didn’t say in the orginal message if this is new to piwik 1.2 or if you just started using it. I don’t know if code in this specific area was changed, but some PDF scheduling code definitely got changed with the last release in order to fix other “no send” issues. I’ll see next Monday if our reports still work …

I can now confirm that the new code works for us. I got the first report this morning.

It is v1.2
Everyone would have told me to update, if I’d use something outdated… :wink:

Of course. So, this is a new installation?

Coming from Piwik 1.1.1, to 1.2-RC5, then to R1.2.
I thought this was clear because of my first post in this topic. Sorry.

Thanks for the report - we fixed a bug where PDF reports created for websites that are now deleted cause the automatic schedule to fail to send emails. Please test the patch (2 lines) in: http://dev.piwik.org/trac/changeset/4458 and report if you’re still not receiving PDF reports

Thanks, I’ll check and report on Monday.

Hi Matt,
No luck, http://dev.piwik.org/trac/changeset/4458 did not work for me.
Sorry, but I abandon. Switching to another machine, where Cron is available. :-/

karsten are you using 1.3 ? if yes, send me a PM with FTP access to piwik your piwik URL + login + password + bug description, thanks