Skip to content

Commit

Permalink
Merge branch 'release-1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhartless committed Sep 3, 2015
2 parents 6e1ec96 + 018c98a commit 51f4ca2
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/bundles/ConfigBundle/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function editAction ()
// We must clear the application cache for the updated values to take effect
/** @var \Mautic\CoreBundle\Helper\CacheHelper $cacheHelper */
$cacheHelper = $this->factory->getHelper('cache');
$cacheHelper->clearCache();
$cacheHelper->clearCache(false, true);
} catch (RuntimeException $exception) {
$this->addFlash('mautic.config.config.error.not.updated', array('%exception%' => $exception->getMessage()), 'error');
}
Expand Down
40 changes: 36 additions & 4 deletions app/bundles/CoreBundle/Helper/CacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Filesystem\Filesystem;

/**
* Class CacheHelper
Expand All @@ -35,14 +36,19 @@ public function __construct(MauticFactory $factory)
* Clear the application cache and run the warmup routine for the current environment
*
* @param bool $noWarmup Skips the warmup routine
*
* @param bool $configSave True if clearing the cache after saving the configuration
* @return void
*/
public function clearCache($noWarmup = false)
public function clearCache($noWarmup = false, $configSave = false)
{
$this->clearSessionItems();

ini_set('memory_limit', '128M');
$memoryLimit = ini_get('memory_limit');
if ((int) substr($memoryLimit, 0, -1) < 128) {
ini_set('memory_limit', '128M');
}

$this->clearOpcaches($configSave);

//attempt to squash command output
ob_start();
Expand Down Expand Up @@ -78,7 +84,7 @@ public function nukeCache()

$cacheDir = $this->factory->getSystemPath('cache', true);

$fs = new \Symfony\Component\Filesystem\Filesystem();
$fs = new Filesystem();
$fs->remove($cacheDir);
}

Expand All @@ -87,6 +93,8 @@ public function nukeCache()
*/
public function clearCacheFile()
{
$this->clearOpcaches(true);

$env = $this->factory->getEnvironment();
$debug = ($this->factory->getDebugMode()) ? 'Debug' : '';
$cacheDir = $this->factory->getSystemPath('cache', true);
Expand All @@ -108,4 +116,28 @@ protected function clearSessionItems()
$session->remove('mautic.menu.items');
$session->remove('mautic.menu.icons');
}

/**
* Clear opcaches
*
* @param bool|false $configSave
*/
protected function clearOpcaches($configSave = false)
{
// Clear opcaches before rebuilding the cache to ensure latest filechanges are used
if (function_exists('opcache_reset')) {
if ($configSave) {
// Clear the cached config file
$configFile = $this->factory->getLocalConfigFile(false);
opcache_invalidate($configFile);
} else {
// Clear the entire cache as anything could have been affected
opcache_reset();
}
}

if (function_exists('apc_clear_cache')) {
apc_clear_cache('user');
}
}
}
36 changes: 19 additions & 17 deletions app/bundles/EmailBundle/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ class PublicController extends CommonFormController
public function indexAction($idHash)
{
/** @var \Mautic\EmailBundle\Model\EmailModel $model */
$model = $this->factory->getModel('email');
$translator = $this->get('translator');
$stat = $model->getEmailStatus($idHash);
$model = $this->factory->getModel('email');
$stat = $model->getEmailStatus($idHash);

if (!empty($stat)) {
$entity = $stat->getEmail();
$entity = $stat->getEmail();
$model->hitEmail($stat, $this->request, true);

// Check for stored copy
Expand Down Expand Up @@ -56,12 +55,12 @@ public function indexAction($idHash)
$response = $this->render(
'MauticEmailBundle::public.html.php',
array(
'inBrowser' => true,
'slots' => $slots,
'content' => $entity->getContent(),
'email' => $entity,
'lead' => $lead,
'template' => $template
'inBrowser' => true,
'slots' => $slots,
'content' => $entity->getContent(),
'email' => $entity,
'lead' => $lead,
'template' => $template
)
);

Expand All @@ -77,13 +76,16 @@ public function indexAction($idHash)
// Override tracking_pixel so as to not cause a double hit
$tokens['{tracking_pixel}'] = MailHelper::getBlankPixel();

$event = new EmailSendEvent(array(
'content' => $content,
'lead' => $lead,
'email' => $entity,
'idHash' => $idHash,
'tokens' => $tokens
));
$event = new EmailSendEvent(
null,
array(
'content' => $content,
'lead' => $lead,
'email' => $entity,
'idHash' => $idHash,
'tokens' => $tokens
)
);
$this->factory->getDispatcher()->dispatch(EmailEvents::EMAIL_ON_DISPLAY, $event);
$content = $event->getContent(true);
}
Expand Down
20 changes: 5 additions & 15 deletions app/bundles/EmailBundle/EventListener/EmailSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,11 @@ public function onEmailFailed(Events\QueueEmailEvent $event)
*/
public function onEmailSend(Events\EmailSendEvent $event)
{
/** @var \Mautic\EmailBundle\Model\EmailModel $model */
$model = $this->factory->getModel('email');
if ($config = $model->getMonitoredMailbox('EmailBundle', 'unsubscribes')) {
$headers = $event->getTextHeaders();
$existing = (isset($headers['List-Unsubscribe'])) ? $headers['List-Unsubscribe'] : '';

$append = 'unsubscribe';
$idHash = $event->getIdHash();
if ($idHash) {
$append .= "_{$idHash}";
}

list($email, $domain) = explode('@', $config['address']);
$unsubscribeEmail = "<mailto:$email+$append@$domain>";
$updatedHeader = ($existing) ? $unsubscribeEmail . ", " . $existing : $unsubscribeEmail;
if ($unsubscribeEmail = $event->getHelper()->generateUnsubscribeEmail()) {
$headers = $event->getTextHeaders();
$existing = (isset($headers['List-Unsubscribe'])) ? $headers['List-Unsubscribe'] : '';
$unsubscribeEmail = "<mailto:$unsubscribeEmail>";
$updatedHeader = ($existing) ? $unsubscribeEmail.", ".$existing : $unsubscribeEmail;

$event->addTextHeader('List-Unsubscribe', $updatedHeader);
}
Expand Down
17 changes: 11 additions & 6 deletions app/bundles/EmailBundle/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public function __construct(MauticFactory $factory, \Swift_Mailer $mailer, $from

$this->from = (!empty($from)) ? $from : array($factory->getParameter('mailer_from_email') => $factory->getParameter('mailer_from_name'));
$this->returnPath = $factory->getParameter('mailer_return_path');
$this->message = $this->getMessageInstance();

// Check if batching is supported by the transport
if ($this->factory->getParameter('mailer_spool_type') == 'memory' && $this->transport instanceof InterfaceTokenTransport) {
Expand All @@ -208,6 +207,8 @@ public function __construct(MauticFactory $factory, \Swift_Mailer $mailer, $from
if (method_exists($this->transport, 'setMauticFactory')) {
$this->transport->setMauticFactory($factory);
}

$this->message = $this->getMessageInstance();
}

/**
Expand Down Expand Up @@ -596,7 +597,7 @@ static public function getBlankPixel()
public function getMessageInstance()
{
try {
$message = ($this->tokenizationEnabled) ? MauticMessage::newInstance() : \Swift_Message::newInstance();
$message = ($this->tokenizationSupported) ? MauticMessage::newInstance() : \Swift_Message::newInstance();

return $message;
} catch (\Exception $e) {
Expand Down Expand Up @@ -1513,10 +1514,12 @@ public function isMontoringEnabled($bundleKey, $folderKey)
*
* @param null $idHash
*
* @return bool|mixed|null|string
* @return bool|string
*/
protected function generateBounceEmail($idHash = null)
public function generateBounceEmail($idHash = null)
{
$monitoredEmail = false;

if ($settings = $this->isMontoringEnabled('EmailBundle', 'bounces')) {
// Append the bounce notation
list ($email, $domain) = explode('@', $settings['address']);
Expand All @@ -1535,10 +1538,12 @@ protected function generateBounceEmail($idHash = null)
*
* @param null $idHash
*
* @return bool|mixed|null|string
* @return bool|string
*/
protected function generateUnsubscribeEmail($idHash = null)
public function generateUnsubscribeEmail($idHash = null)
{
$monitoredEmail = false;

if ($settings = $this->isMontoringEnabled('EmailBundle', 'unsubscribes')) {
// Append the bounce notation
list ($email, $domain) = explode('@', $settings['address']);
Expand Down
13 changes: 10 additions & 3 deletions app/bundles/EmailBundle/Model/EmailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ public function sendEmailToLists (Email $email, $lists = null, $limit = null)
$failed = array();
$sentCount = 0;
$failedCount = 0;

foreach ($lists as $list) {
if ($limit !== null && $limit <= 0) {
// Hit the max for this batch
Expand Down Expand Up @@ -971,6 +972,7 @@ public function sendEmail ($email, $leads, $options = array())
$contentGenerated = false;

$flushQueue = function($reset = true) use (&$mailer, &$saveEntities, &$errors, $sendBatchMail) {

if ($sendBatchMail) {
$flushResult = $mailer->flushQueue();
if (!$flushResult) {
Expand Down Expand Up @@ -1342,9 +1344,14 @@ public function updateBouncedStats(array $bounces)
*/
public function getMonitoredMailbox($bundleKey, $folderKey)
{
/** @var \Mautic\EmailBundle\Helper\MailHelper $mailHelper */
$mailHelper = $this->factory->getMailer();
/** @var \Mautic\EmailBundle\MonitoredEmail\Mailbox $mailboxHelper */
$mailboxHelper = $this->factory->getHelper('mailbox');

if ($mailboxHelper->isConfigured($bundleKey, $folderKey)) {

return $mailboxHelper->getMailboxSettings();
}

return $mailHelper->isMontoringEnabled($bundleKey, $folderKey);
return false;
}
}

0 comments on commit 51f4ca2

Please sign in to comment.