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
$alerts = array(
'recipients' => array(''),
'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
$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()
->setFrom(array('' => 'CiviCRM'))
->setBody($body, 'text/html');
\ 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>
{% for item in results %}
<td align="right">{{ item.issue }}</td>
<td colspan=3>{{ item.summary }} </td>
<td align="right">{{ item.priority }}</td>
<td>{{ }}</td>
<td>{{ item.resolution }}</td>
<td>{{ item.assignee }}</td>
{% endfor %}
<pre>--<a href="'"></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