Skip to content

Commit 3e739c2

Browse files
committed
Add Mailer component instead of swiftmailer
1 parent 9115384 commit 3e739c2

File tree

9 files changed

+45
-132
lines changed

9 files changed

+45
-132
lines changed

.env

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ DATABASE_USER='{{DATABASE_USER}}'
1010
DATABASE_PASSWORD='{{DATABASE_PASSWORD}}'
1111
###< doctrine/doctrine-bundle ###
1212

13-
###> symfony/swiftmailer-bundle ###
14-
MAILER_TRANSPORT='sendmail'
15-
MAILER_USERNAME=''
16-
MAILER_PASSWORD=''
17-
MAILER_HOST=''
18-
MAILER_PORT=''
19-
###< symfony/swiftmailer-bundle ###
20-
2113
###> symfony/framework-bundle ###
2214
APP_ENV='dev'
2315
APP_DEBUG='1'
@@ -35,3 +27,7 @@ APP_LOCALE='en'
3527
APP_MULTIPLE_ACCESS_URL=''
3628

3729
###< chamilo ###
30+
31+
###> symfony/mailer ###
32+
MAILER_DSN=sendmail://localhost
33+
###< symfony/mailer ###

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@
7070
"symfony/framework-bundle": "^4.0",
7171
"symfony/http-kernel": "^4.0",
7272
"symfony/monolog-bundle": "^3.1",
73+
"symfony/mailer": "^4.0",
7374
"symfony/polyfill-apcu": "^1.9",
7475
"symfony/security-bundle": "^4.0",
75-
"symfony/swiftmailer-bundle": "^3.2",
7676
"symfony/templating" : "^4.0",
7777
"symfony/translation": "^4.0",
7878
"symfony/twig-bundle": "^4.0",

config/bundles.php

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
99
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
1010
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
11-
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
1211
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
1312
WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true],
1413
Sonata\EasyExtendsBundle\SonataEasyExtendsBundle::class => ['all' => true],

config/packages/dev/swiftmailer.yaml

-4
This file was deleted.

config/packages/swiftmailer.yaml

-7
This file was deleted.

config/packages/test/swiftmailer.yaml

-2
This file was deleted.

config/services.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ parameters:
1010
resources:
1111
- 'GeneratorBundle::fields.html.twig'
1212

13-
mailer_transport: smtp
14-
mailer_host: 127.0.0.1
15-
mailer_user: [email protected]
16-
mailer_password: null
1713
course_info_is_not_editable: false
1814
sonata_media.cdn.host: '/var/upload/media/'
1915
sonata_page.varnish.command: 'if [ ! -r "/etc/varnish/secret" ]; then echo "VALID ERROR :/"; else varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 {{ COMMAND }} "{{ EXPRESSION }}"; fi;'
@@ -79,6 +75,9 @@ services:
7975
- '@Chamilo\CoreBundle\Repository\ResourceFactory'
8076
- '@Chamilo\CoreBundle\Block\BreadcrumbBlockService'
8177

78+
Symfony\Component\Mailer\Mailer:
79+
public: true
80+
8281
Chamilo\ThemeBundle\:
8382
autowire: true
8483
resource: '../src/ThemeBundle/*'

public/main/inc/lib/api.lib.php

+36-93
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
use Chamilo\ThemeBundle\Controller\ExceptionController;
1212
use Chamilo\UserBundle\Entity\User;
1313
use ChamiloSession as Session;
14+
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
1415
use Symfony\Component\Debug\Exception\FlattenException;
1516
use Symfony\Component\Finder\Finder;
17+
use Symfony\Component\Mime\Address;
18+
use Symfony\Component\Mime\Email;
1619
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1720

1821
/**
@@ -1845,7 +1848,7 @@ function api_get_anonymous_id()
18451848
$ip = Database::escape_string(api_get_real_ip());
18461849
$max = (int) api_get_configuration_value('max_anonymous_users');
18471850
if ($max >= 2) {
1848-
$sql = "SELECT * FROM $table as TEL
1851+
$sql = "SELECT * FROM $table as TEL
18491852
JOIN $tableU as U
18501853
ON U.user_id = TEL.login_user_id
18511854
WHERE TEL.user_ip = '$ip'
@@ -1880,8 +1883,8 @@ function api_get_anonymous_id()
18801883
}
18811884

18821885
$table = Database::get_main_table(TABLE_MAIN_USER);
1883-
$sql = "SELECT user_id
1884-
FROM $table
1886+
$sql = "SELECT user_id
1887+
FROM $table
18851888
WHERE status = ".ANONYMOUS." ";
18861889
$res = Database::query($sql);
18871890
if (Database::num_rows($res) > 0) {
@@ -4679,7 +4682,7 @@ function api_display_language_form($hide_if_no_choice = false, $showAsButton = f
46794682
} else {
46804683
$html = '
46814684
<a href="'.$url.'" class="dropdown-toggle" data-toggle="dropdown" role="button">
4682-
<span class="flag-icon flag-icon-'.$countryCode.'"></span>
4685+
<span class="flag-icon flag-icon-'.$countryCode.'"></span>
46834686
'.$currentLanguageInfo['original_name'].'
46844687
<span class="caret"></span>
46854688
</a>
@@ -4795,7 +4798,7 @@ function languageToCountryIsoCode($languageIsoCode)
47954798
function api_get_languages()
47964799
{
47974800
$table = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4798-
$sql = "SELECT * FROM $table WHERE available='1'
4801+
$sql = "SELECT * FROM $table WHERE available='1'
47994802
ORDER BY original_name ASC";
48004803
$result = Database::query($sql);
48014804
$languages = [];
@@ -8027,8 +8030,8 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
80278030
};
80288031
80298032
$(function() {
8030-
var lang = ".json_encode($translations).";
8031-
var options = {
8033+
var lang = ".json_encode($translations).";
8034+
var options = {
80328035
onLoad : function () {
80338036
//$('#messages').text('Start typing password');
80348037
},
@@ -8046,7 +8049,7 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
80468049
options.i18n = {
80478050
t: function (key) {
80488051
var result = lang[key];
8049-
return result === key ? '' : result; // This assumes you return the
8052+
return result === key ? '' : result; // This assumes you return the
80508053
}
80518054
};
80528055
$('".$passwordInputId."').pwstrength(options);
@@ -8717,68 +8720,22 @@ function api_mail_html(
87178720
$replyToName = $extra_headers['reply_to']['name'];
87188721
}
87198722

8720-
//If the SMTP configuration only accept one sender
8721-
/*if (isset($platform_email['SMTP_UNIQUE_SENDER']) && $platform_email['SMTP_UNIQUE_SENDER']) {
8722-
$senderName = $platform_email['SMTP_FROM_NAME'];
8723-
$senderEmail = $platform_email['SMTP_FROM_EMAIL'];
8724-
$valid = PHPMailer::validateAddress($senderEmail);
8725-
if ($valid) {
8726-
//force-set Sender to $senderEmail, otherwise SetFrom only does it if it is currently empty
8727-
$mail->Sender = $senderEmail;
8728-
}
8729-
}*/
8730-
8731-
/*$mail->SetFrom($senderEmail, $senderName);
8732-
$mail->Subject = $subject;
8733-
$mail->AltBody = strip_tags(
8734-
str_replace('<br />', "\n", api_html_entity_decode($message))
8735-
);*/
8736-
8737-
/*if (is_array($extra_headers) && count($extra_headers) > 0) {
8738-
foreach ($extra_headers as $key => $value) {
8739-
switch (strtolower($key)) {
8740-
case 'encoding':
8741-
case 'content-transfer-encoding':
8742-
$mail->Encoding = $value;
8743-
break;
8744-
case 'charset':
8745-
$mail->Charset = $value;
8746-
break;
8747-
case 'contenttype':
8748-
case 'content-type':
8749-
$mail->ContentType = $value;
8750-
break;
8751-
default:
8752-
$mail->AddCustomHeader($key.':'.$value);
8753-
break;
8754-
}
8755-
}
8756-
} else {
8757-
if (!empty($extra_headers)) {
8758-
$mail->AddCustomHeader($extra_headers);
8759-
}
8760-
}*/
8761-
8762-
// WordWrap the html body (phpMailer only fixes AltBody) FS#2988
8763-
//$mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
87648723
try {
8765-
$message = new \Swift_Message($subject);
8724+
$message = new TemplatedEmail();
8725+
$message->subject($subject);
87668726

87678727
$list = api_get_configuration_value('send_all_emails_to');
87688728
if (!empty($list) && isset($list['emails'])) {
87698729
foreach ($list['emails'] as $email) {
8770-
$message->addCc($email);
8730+
$message->cc($email);
87718731
}
87728732
}
87738733

87748734
// Attachment
87758735
if (!empty($data_file)) {
87768736
foreach ($data_file as $file_attach) {
87778737
if (!empty($file_attach['path']) && !empty($file_attach['filename'])) {
8778-
//$message->attach(Swift_Attachment::fromPath($file_attach['path'], $file_attach['filename']);
8779-
$message->attach(
8780-
Swift_Attachment::fromPath($file_attach['path'])->setFilename($file_attach['filename'])
8781-
);
8738+
$message->attachFromPath($file_attach['path'], $file_attach['filename']);
87828739
}
87838740
}
87848741
}
@@ -8800,41 +8757,27 @@ function api_mail_html(
88008757
$paramsHtml = $paramsText = $params;
88018758

88028759
$paramsHtml['content'] = $body;
8803-
$paramsText['content'] = str_replace('<br />', "\n", api_html_entity_decode($body));
8760+
//$paramsText['content'] = str_replace('<br />', "\n", api_html_entity_decode($body));
88048761

88058762
if (!empty($senderEmail)) {
8806-
$message->setFrom([$senderEmail => $senderName]);
8763+
$message->from(new Address($senderEmail, $senderName));
88078764
}
88088765

88098766
if (!empty($recipientEmail)) {
8810-
$message->setTo([$recipientEmail => $recipientName]);
8767+
$message->to(new Address($recipientEmail, $recipientName));
88118768
}
88128769

88138770
if (!empty($replyToEmail)) {
8814-
$message->setReplyTo([$replyToEmail => $replyToName]);
8771+
$message->replyTo(new Address($replyToEmail, $replyToName));
88158772
}
88168773

88178774
$message
8818-
->setBody(
8819-
Container::getTwig()->render(
8820-
'ChamiloThemeBundle:Mailer:Default/default.html.twig',
8821-
$paramsHtml
8822-
),
8823-
'text/html'
8824-
)
8825-
->addPart(
8826-
Container::getTwig()->render(
8827-
'ChamiloThemeBundle:Mailer:Default/default.text.twig',
8828-
$paramsText
8829-
),
8830-
'text/plain'
8831-
)
8832-
//->setEncoder(\Swift_Encoding::get8BitEncoding())
8775+
->htmlTemplate('ChamiloThemeBundle:Mailer:Default/default.html.twig')
8776+
->textTemplate('ChamiloThemeBundle:Mailer:Default/default.text.twig')
88338777
;
8834-
8835-
$type = $message->getHeaders()->get('Content-Type');
8836-
$type->setCharset('utf-8');
8837-
Container::getMailer()->send($message);
8778+
$message->context($paramsHtml);
8779+
$result = Container::getMailer()->send($message);
8780+
var_dump($result);exit;
88388781

88398782
return true;
88408783
} catch (Exception $e) {
@@ -9325,7 +9268,7 @@ function api_find_template($template)
93259268
function api_get_language_list_for_flag()
93269269
{
93279270
$table = Database::get_main_table(TABLE_MAIN_LANGUAGE);
9328-
$sql = "SELECT english_name, isocode FROM $table
9271+
$sql = "SELECT english_name, isocode FROM $table
93299272
ORDER BY original_name ASC";
93309273
static $languages = [];
93319274
if (empty($languages)) {
@@ -9373,11 +9316,11 @@ function api_get_language_translate_html()
93739316
$hideAll .= '
93749317
$("span:lang('.$language['isocode'].')").filter(
93759318
function(e, val) {
9376-
// Only find the spans if they have set the lang
9377-
if ($(this).attr("lang") == null) {
9319+
// Only find the spans if they have set the lang
9320+
if ($(this).attr("lang") == null) {
93789321
return false;
93799322
}
9380-
9323+
93819324
// Ignore ckeditor classes
93829325
return !this.className.match(/cke(.*)/);
93839326
}).hide();'."\n";
@@ -9394,32 +9337,32 @@ function(e, val) {
93949337

93959338
return '
93969339
$(function() {
9397-
'.$hideAll.'
9398-
var defaultLanguageFromUser = "'.$isoCode.'";
9399-
9340+
'.$hideAll.'
9341+
var defaultLanguageFromUser = "'.$isoCode.'";
9342+
94009343
$("span:lang('.$isoCode.')").filter(
94019344
function() {
94029345
// Ignore ckeditor classes
94039346
return !this.className.match(/cke(.*)/);
94049347
}).show();
9405-
9348+
94069349
var defaultLanguage = "";
94079350
var langFromUserFound = false;
9408-
9351+
94099352
$(this).find("span").filter(
94109353
function() {
94119354
// Ignore ckeditor classes
94129355
return !this.className.match(/cke(.*)/);
94139356
}).each(function() {
9414-
defaultLanguage = $(this).attr("lang");
9357+
defaultLanguage = $(this).attr("lang");
94159358
if (defaultLanguage) {
9416-
$(this).before().next("br").remove();
9359+
$(this).before().next("br").remove();
94179360
if (defaultLanguageFromUser == defaultLanguage) {
94189361
langFromUserFound = true;
94199362
}
94209363
}
94219364
});
9422-
9365+
94239366
// Show default language
94249367
if (langFromUserFound == false && defaultLanguage) {
94259368
$("span:lang("+defaultLanguage+")").filter(

src/CoreBundle/Framework/Container.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,9 @@ public static function getTranslator()
229229
return false;
230230
}
231231

232-
/**
233-
* @return AssetsHelper
234-
*/
235-
public static function getAsset()
236-
{
237-
return self::$container->get('templating.helper.assets');
238-
}
239-
240-
/**
241-
* @return \Swift_Mailer
242-
*/
243232
public static function getMailer()
244233
{
245-
return self::$container->get('mailer');
234+
return self::$container->get('Symfony\Component\Mailer\Mailer');
246235
}
247236

248237
/**

0 commit comments

Comments
 (0)