Closed dafuer closed 9 years ago
Hello @dafuer,
Thanks for your PR, it's a great idea. I reviewed it, and I've made some comments, so if you can fix or tell me what you think, it will be great.
Hi @dizda ,
I have followed all your comments and pulled another commit fixing everything. Thanks you very much, it was really useful. Comments:
Long live the CloudBackupBundle! :)
Hey @dafuer :)
Thanks for the fixes. Instead of the current code, it's more proper to do something like this:
if($this->getContainer()->getParameter('dizda_cloud_backup.error_notification')['to']!=NULL){
$mailer = $container = $this->getContainer()->get('mailer');
$message = $mailer->createMessage()
->setFrom($this->getContainer()->getParameter('dizda_cloud_backup.error_notification')['from'])
->setTo($this->getContainer()->getParameter('dizda_cloud_backup.error_notification')['to'])
->setSubject("DizdaBackupBundle: Backup error")
->setBody($e->getMessage()."( code: ".$e->getCode()."; file: ".$e->getFile()."; line: ".$e->getLine().")")
;
$mailer->send($message);
}
throw new \Exception($e->getMessage(), $e->getCode(), $e);
Nice pr!
What do you think about having the to-parameter as an array that allows multiple recipients?
Regarding @dizda's last comment you can just re-throw the exception with throw $e
.
Also, omit the $container =
in $mailer = $container = $this->getContainer()->get('mailer');
Indeed @jongotlin, you're right!
I'm also agree that an array of multiple recipients could be a great idea :+1:
Yes, ok! I've understood!
This afternoon I'll do that change and I'll add the possibility to set an array of recipients.
And you'll have to rebase to be sync with the master
Hi,
I think is done, but I had some problems with the rebase and I think the commit history has some incongruences (commits repeated?). Do you prefer that I try to fork the repository again and applying the changes from the beginning?
In addition (I just watched it): Has travis found an error?
Hi,
I do the foreach as test the emails exists and then send them one by one. It's tested with and without define the settings. In addition, with this test, we are testing that "to" exists, which is completely mandatory.
What's about travis?
Cheers,
I think it's better to test if emails are setted this way:
$emails = $this->getContainer()->getParameter('dizda_cloud_backup.error_notification')['to'];
if (count($emails) > 0) {
// send emails there
$message = $this->getContainer()->get('mailer')->createMessage()
->setFrom($this->getContainer()->getParameter('dizda_cloud_backup.error_notification')['from'])
->setTo($emails)
->setSubject("DizdaBackupBundle: Backup error")
->setBody($e->getMessage()."( code: ".$e->getCode()."; file: ".$e->getFile()."; line: ".$e->getLine().")")
;
$this->getContainer()->get('mailer')->send($message);
}
throw $e;
Instead of the foreach. What do you think?
Ok,
as you prefer. I'll do it this afternoon. But... if I'm going to remove this line:
$container->setParameter('dizda_cloud_backup.error_notification', $config['error_notification']);
from DependencyInjection/DizdaCloudBackupExtension.php and this task will be done by the line 34 when I'll call getParameter('dizda_cloud_backup.error_notification') if it does not exists I think is going to crash...
What do you think? I can check it this evening.
You can use $this->getContainer()->hasParameter('dizda_cloud_backup.error_notification')
to test if exist.
Moreover, the setTo() can accept string, but also array. That's the reason why I think you should remove the foreach and put the variable directly, SwiftMailer will take care of the rest.
Done :)
That's great, thank you @dafuer :-)
Hello,
I had many times a problem: DropBox changes something in the API and the bundle stops to work. I realised the problem after long time. So, I hadn't backup and this could be dangerous. I have added a functionality to send an email if something happen during the backup process. What do you think? It could be useful for everybody?
If you want to use it, you have to define an email account to be notified:
Cheers,