Schduled emails being sent to Superuser and not to the User account


(Sid351) #1

Hi,

I’ve got a Piwik setup with a handful of users, as well as the “Superuser” account.

I setup some scheduled reports to be emailed while logged in as “User1”, and the mails were sent to the email address of the “Superuser”.

I was just wondering if anyone else has experienced this problem?

I think it might have something to do with the scheduling and the “Email to me” box/function.

I’m going to test un-ticking the box and entering an email address manually to see if that is a viable work-around.


(duncanc) #2

Looking at the code in the PDF Reports plugin, it’s not surprising

        $emails = self::getEmailsFromString($report['additional_emails']);
        if($report['email_me'] == 1)
        {        
            $emails[] = Piwik::getCurrentUserEmail();
        }
        $this->sendReportEmailPdfAttached($emails, $outputFilename, $prettyDate, $websiteName, $report);

If you are using a cron job then when the report id emailed the current user is the super admin, not the user who created the report.
It needs to use the login column, which is the user who created the report, to get the email address. It also then needs to distinguish between the superuser and an ordinary user. Something like this but untested style_emoticons/<#EMO_DIR#>/wink.gif

if($report['email_me'] == 1)
{
  if (isUserIsSuperUserOrTheUser($report['login']))
  {
    $emails[] = Piwik::getCurrentUserEmail();
  }
  else  
  {
    $user = Piwik_UsersManager_API::getInstance()->getUser($report['login']);
    $emails[] = $user['email'];
  }
}

(Sid351) #3

Hi,

When I looked at the code I thought so too, but not knowing anything about php, I thought it best to ask.

Cheers for the un-tested rewrite.

I’ll put that into my test system and see what happens, in the mean time, I’ll just tell my users to untick the box and put thier email addresses in the text box. Hopefully, that should do until i get a chance to properly test this.

Once I have confirmed it fixes it, how do I submit a ticket/proposed fix?

Also, I’m using Windows but I think the cron job is the same as the powershell script anyway, so I don’t think it really matters.

Thanks!


(duncanc) #4

Now tested! Note that it is different to the previous post.

Replace these lines in plugins/PDFReports/API.php

		if($report['email_me'] == 1)
		{		
			$emails[] = Piwik::getCurrentUserEmail();
		}

with these

if ($report['email_me'] == 1)
{
  if (Piwik::getCurrentUserLogin() == $report['login'])
  {
    $emails[] = Piwik::getCurrentUserEmail();
  }
  else  
  {
    $user = Piwik_UsersManager_API::getInstance()->getUser($report['login']);
    $emails[] = $user['email'];
  }
}

Hopefully one of the developers will see this and raise a ticket, otherwise I can.


(Sid351) #5

Awesome, thanks.

I’ll try it out tomorrow when I’m back in the office and let you know how I get on.

Any idea how I can force the report to be sent out, without using the email it now link? In other words, is there a flag I can clear to make it seem like the report hasn’t been sent yet, so when I run the powershell script, it sends it out?

I tried clearing the date in the PDF table, but that didn’t seem to do it.


(Sid351) #6

For those following this thread:

I found the debug code for forcing scheduled tasks to run. It’s in TaskScheduler.php in the “Core” directory.

Uncomment line 50, and the scheduled tasks will be forced, regardless of if they have run already.


(Thomas Seifert) #7

Anyone cared enough to post it as a ticket with a patch resolution?


(duncanc) #8

Entered a ticket into Trac

dev.piwik.org/trac/ticket/1685


(Sid351) #9

Additionally, the next run time of the task is stored in the _option table in the database, under the “TaskScheduler.timetable” option_name.

The dates are stored in a Unix timestamp format (online converter: forum.piwik.org/(ext_link)ww…/unix_time.htm)).