CRM-9499 Scheduled job 'mail_report' does not run - throws invalid error message

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.1.0
    • Fix Version/s: 4.1.0
    • Component/s: CiviReport
    • Labels:
      None

      Description

      NOTE: I had to fix the api_action name provided in civicrm_data.tpl (was 'mail_reports' and should be 'mail_report') - so you'll need to fix that before testing this. I've updated civicrm_data.tpl and added fix to Upgrade/incremental/sql/4.1.beta3.mysql.tpl)

      To recreate:

      • Edit the sample Contribution Summary Report (instance 6) to that Email Delivery Settings are populated (Subject and Email Address)
      • Edit the Scheduled Job to pass version=3 and instanceId=6

      This "should" work based on my review of the code in CRM_Report_Utils_Report::processReport(). However, instead I get this result in the Job Log:
      =========
      Finished execution of Mail Reports with result: Failure, Error message: Could not find valid value for instanceId:

      Parameters raw:
      version=3
      instanceId=6

      Parameters parsed:
      a:2:

      {s:7:"version";s:1:"3";s:10:"instanceId";s:1:"6";}

        Attachments

          Activity

          [CRM-9499] Scheduled job 'mail_report' does not run - throws invalid error message
          Rohan S. Chavan added a comment -

          Fixed in r38460

          David Greenberg added a comment -

          This doesn't seem to be working properly. When I try to run from cli.php - it just spits out (some / not all) of the HTML for the report into the console:

          php bin/cli.php -u admin -p civicrm -e job -a mail_report --instanceId=6 -j -s civicrm40

          When I run it from the UI (passing instanceId=6) - it spits out the report HTML into the browser stream, so I see the report on top of the Scheduled Jobs page.

          In neither case am I getting email output (I have define( 'CIVICRM_MAIL_LOG', 1 ); commented out - and I AM getting email from other processes).

          Lobo was thinking it might require another parameter to tell it to send email (send_mail=1 ?? ). But we tried that and it didn't help. Lobo does think that it's useful to have an OPTION to spit out the complete HTML into the output stream (folks could set up their cron to redirect to a file on their server). However that behavior should be explicitly requested.

          There is supposed to be an option for output=csv - but that didn't work for me either.

          We think the parameter handling should work as follows:
          instanceId=N is required, this is the the report to be processed. If this is missing, return error "Required parameter missing: instanceId"

          Sending mail w/ PDF attached should be the default behavior (if not other params are passed). Then we should support:
          output=csv (attaches a csv formatted file export file to the email instead of PDF)
          send_mail=0 means spit complete output of report to stdout (sort of like it's doing now)

          Deepak Srivastava added a comment -

          Done with the fixes.

          Please note since output is now pdf by default, chances of user hitting memory limit problem is high if cron is run from UI.

          For spitting html out, -output=html is supported. "-sendmail" option is required to be 1 for email to be delivered and its always considered to be true (can't be 0).

          David Greenberg added a comment -

          Output and behaviors look good. One remaining issue:

          • when you run this job from "Scheduled Jobs" admin UI (by clicking 'more' > 'Execute Now') - it should redirect back to the Scheduled Jobs page with status message on top. Currently it leaves you on a white screen (redirect is missing). The status message IS properly set (when I manually go back to admin/jobs the status message is displayed).

          Regarding params - in my testing the parameter that worked for controlling output format is 'format' rather than 'output'. I'll document this on the wiki but posting examples here in case folks read this.

          Send report as PDF attachment using Cli.php:
          $ php bin/cli.php -u admin -p civicrm -e job -a mail_report --instanceId=6

          Send report as CSV formatted attachment using Cli.php:
          $ php bin/cli.php -u admin -p civicrm -e job -a mail_report --instanceId=6 --format=csv

          Push HTML formatted report to stdout (so you can pipe it to an HTML file somewhere on your server)
          $ php bin/cli.php -u admin -p civicrm -e job -a mail_report --instanceId=6 --format=html --sendmail=0

          Deepak Srivastava added a comment -

          White screen / redirection is fixed now.

          I had to add format option mainly for command line cron operation, since --output parameter is already reserved for command line operations.
          And to make it consistent "--format" param work from both UI & command line.

          Another note: --format=html would just render first page (~ 50 rows) as you would see on browser along with "next>> <<prev" links. A better format to capture html is --format=print option.

          Send mail with html content of report (entire result set) as would see with print preview.
          $ php bin/cli.php -u admin -p civicrm -e job -a mail_report --instanceId=6 --format=print --sendmail=1

          Push HTML formatted report (entire result) to stdout (so you can pipe it to an HTML file somewhere on your server)
          $ php bin/cli.php -u admin -p civicrm -e job -a mail_report --instanceId=6 --format=print --sendmail=0

            People

            • Assignee:
              Jamie McClelland
              Reporter:
              David Greenberg

              Dates

              • Created:
                Updated:
                Resolved: