Commit 872e5775 authored by cividesk's avatar cividesk

Adding email alerts (draft for debug)

parent 4fa5f301
......@@ -2,6 +2,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"chobie/jira-api-restclient": "2.0.*"
"chobie/jira-api-restclient": "2.0.*",
"swiftmailer/swiftmailer": "@stable",
"twig/twig": "~1.0"
}
}
}
\ No newline at end of file
<?php
require_once('vendor/autoload.php');
require_once('config.php');
$alerts = array(
array(
'recipients' => array('nicolas@cividesk.com'),
'subject' => '[CiviCRM] Weekly security issues status',
'query' => "
SELECT issue, summary, priority, SUBSTRING(security, 12) as security, resolution, assignee
FROM jira_issue
WHERE status = 'Open' AND security IS NOT NULL
",
'template' => 'security.twig',
),
);
// Initialize database
$dbh = new PDO('mysql:dbname='.DBNAME.';host='.DBHOST, DBUSER, DBPASS);
// Initialize Twig
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array(
'cache' => 'tmp_cache',
));
// Initialize SwiftMailer
$transport = Swift_SendmailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
// Loop on each alert, query, format, compose and send
foreach ($alerts as $alert) {
// Run the query
$results = $dbh->query($alert['query']);
// Format the email with the template
$variables = array(
'results' => $results
);
$body = $twig->render($alert['template'], $variables);
// Compose and send the email
$message = Swift_Message::newInstance()
->setSubject($alert['subject'])
->setFrom(array('info@civicrm.org' => 'CiviCRM'))
->setTo($alert['recipients'])
->setBody($body, 'text/html');
$mailer->send($message);
}
\ No newline at end of file
<p>Hi security team,</p>
<p>This is your weekly recap of all open security issues. Let's work on closing these issues!</p>
<table>
{% for item in results %}
<tr>
<td align="right">{{ item.issue }}</td>
<td colspan=3>{{ item.summary }} </td>
</tr><tr>
<td align="right">{{ item.priority }}</td>
<td>{{ item.security }}</td>
<td>{{ item.resolution }}</td>
<td>{{ item.assignee }}</td>
</tr>
{% endfor %}
</table>
<p>Cheers!<br/>
<pre>--<a href="'https://stats.civicrm.org">stats.civicrm.org</a></pre></p>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment