public function __call($method, $args)
{
// If observer enabled
if (!$this->Config || $this->Config->GetFieldByName("IsEnabled")->Value == 0) {
return;
}
$enabled = $this->Config->GetFieldByName("{$method}Notify");
if (!$enabled || $enabled->Value == 0) {
return;
}
$DB = \Scalr::getDb();
// Event name
$name = substr($method, 2);
// Event message
$message = $DB->GetOne("SELECT message FROM events WHERE event_id = ? LIMIT 1", array($args[0]->GetEventID()));
$farm_name = $DB->GetOne("SELECT name FROM farms WHERE id=? LIMIT 1", array($args[0]->GetFarmID()));
// Set subject
if (!$farm_name) {
$this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()})");
} else {
$this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()} FarmName: {$farm_name})");
}
// Set body
$this->Mailer->setMessage($message);
// Send mail
try {
$res = $this->Mailer->send();
} catch (\Exception $e) {
$res = false;
}
if (!$res) {
Logger::getLogger(__CLASS__)->info("Mail sent to '{$this->Config->GetFieldByName("EventMailTo")->Value}'. Result: {$res}");
}
}