Commit 8450e551 authored by mickadoo's avatar mickadoo

68: Fix send email function

parent fd72ce8d
......@@ -2,6 +2,7 @@
namespace AppBundle\Controller;
use AppBundle\Utils\Publisher;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
......@@ -12,7 +13,7 @@ use AppBundle\Model\Library;
class PublishController extends Controller {
/**
* @var \AppBundle\Utils\Publisher
* @var Publisher
*/
private $publisher;
......@@ -22,9 +23,13 @@ class PublishController extends Controller {
private $publishSuccess;
/**
* @param string $identifier
*
* @return Response
*
* @Route("/admin/publish{identifier}" , requirements={"identifier": ".*"})
*/
public function PublishAction(Request $request, $identifier) {
public function PublishAction($identifier) {
$this->publisher = $this->get('publisher');
$bookSlug = Library::parseIdentifier($identifier)['bookSlug'];
if ($bookSlug) {
......@@ -44,6 +49,10 @@ class PublishController extends Controller {
}
/**
* @param Request $request
*
* @return Response
*
* @Route("/admin/listen")
*/
public function ListenAction(Request $request) {
......@@ -63,45 +72,55 @@ class PublishController extends Controller {
if ($identifiers) {
$this->publisher = $this->get('publisher');
foreach ($identifiers as $identifier) {
$this->publisher->publish("{$identifier}/{$processor->branch}");
if ($this->publisher->version) {
$this->sendEmail($processor->recipients);
}
$fullIdentifier = "{$identifier}/{$processor->branch}";
$this->publisher->publish($fullIdentifier);
$this->sendEmail($identifier);
}
$response = $this->publisher->getMessagesInPlainText();
}
else {
$response = "CRITICAL - No books found which match {$processor->repo}";
}
return new Response($response, 200);
}
/**
* Send notification emails after publishing
*
* @param array $extraRecipients
* Array of strings for email addresses that should receive the
* notification email. If non are specified, then the email will be sent to
* all addresses set in the book's yaml configuration.
* @param string $identifier
*/
private function sendEmail($extraRecipients = array()) {
$subject = $this->publisher->status;
$recipients = array_unique(array_merge(
$extraRecipients,
$this->publisher->language->watchers));
private function sendEmail(string $identifier) {
/**
* Array of strings for email addresses that should receive the
* notification email. If none are specified, then the email will be sent to
* all addresses set in the book's yaml configuration
*/
$extraRecipients = $this->get('github.hook.processor')->recipients;
$library = $this->get('library');
$messages = $this->get('publisher')->getMessages();
$parts = $library::parseIdentifier($identifier);
$book = $library->getBookBySlug($parts['bookSlug']);
$language = $book->getLanguageByCode($parts['languageCode']);
$version = $language->getVersionByDescriptor($parts['versionDescriptor']);
$webPath = sprintf('%s/%s/%s', $book->slug, $language->code, $version->branch);
$subject = "Publishing Successful";
$recipients = array_unique(array_merge($extraRecipients, $language->watchers));
$renderParams = [
'publishURLBase' => $webPath,
'status' => $subject,
'messages' => $messages,
];
$body = $this->renderView('AppBundle:Emails:notify.html.twig', $renderParams);
$mail = \Swift_Message::newInstance()
->setSubject("$subject")
->setSubject($subject)
->setFrom('no-reply@civicrm.org', "CiviCRM docs")
->setTo($recipients)
->setBody(
$this->renderView('AppBundle:Emails:notify.html.twig',
array(
'publishURLBase' => $this->publisher->publishURLBase,
'status' => $this->publisher->status,
'messages' => $this->publisher->messages,
)
), 'text/html'
);
->setBody($body, 'text/html');
$this->get('mailer')->send($mail);
}
......
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