function run($request)
 {
     //IMPORTANT!
     Config::inst()->update("Email", "send_all_emails_to", "no-one@localhost");
     Email::set_mailer(new EcommerceTaskTryToFinaliseOrders_Mailer());
     $orderStatusLogClassName = "OrderStatusLog";
     $submittedOrderStatusLogClassName = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     if ($submittedOrderStatusLogClassName) {
         $sampleSubmittedStatusLog = $submittedOrderStatusLogClassName::get()->First();
         if ($sampleSubmittedStatusLog) {
             $lastOrderStep = OrderStep::get()->sort("Sort", "DESC")->First();
             if ($lastOrderStep) {
                 $joinSQL = "INNER JOIN \"{$orderStatusLogClassName}\" ON \"{$orderStatusLogClassName}\".\"OrderID\" = \"Order\".\"ID\"";
                 $whereSQL = "WHERE \"StatusID\" <> " . $lastOrderStep->ID . " AND \"{$orderStatusLogClassName}\".ClassName = '{$submittedOrderStatusLogClassName}'";
                 $count = DB::query("\r\n\t\t\t\t\t\tSELECT COUNT (\"Order\".\"ID\")\r\n\t\t\t\t\t\tFROM \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t")->value();
                 $do = DB::query("\r\n\t\t\t\t\t\tUPDATE \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\tSET \"Order\".\"StatusID\" = " . $lastOrderStep->ID . "\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t");
                 if ($count) {
                     DB::alteration_message("NOTE: {$count} records were updated.", "created");
                 } else {
                     DB::alteration_message("No records were updated.");
                 }
             } else {
                 DB::alteration_message("Could not find the last order step.", "deleted");
             }
         } else {
             DB::alteration_message("Could not find any submitted order logs.", "deleted");
         }
     } else {
         DB::alteration_message("Could not find a class name for submitted orders.", "deleted");
     }
 }
 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     if (!$this->testSessionEnvironment->isRunningTests()) {
         return;
     }
     $testState = $this->testSessionEnvironment->getState();
     // Date and time
     if (isset($testState->datetime)) {
         SS_Datetime::set_mock_now($testState->datetime);
     }
     // Register mailer
     if (isset($testState->mailer)) {
         $mailer = $testState->mailer;
         Email::set_mailer(new $mailer());
         Config::inst()->update("Email", "send_all_emails_to", null);
     }
     // Allows inclusion of a PHP file, usually with procedural commands
     // to set up required test state. The file can be generated
     // through {@link TestSessionStubCodeWriter}, and the session state
     // set through {@link TestSessionController->set()} and the
     // 'testsession.stubfile' state parameter.
     if (isset($testState->stubfile)) {
         $file = $testState->stubfile;
         if (!Director::isLive() && $file && file_exists($file)) {
             // Connect to the database so the included code can interact with it
             global $databaseConfig;
             if ($databaseConfig) {
                 DB::connect($databaseConfig);
             }
             include_once $file;
         }
     }
 }
 public function tearDown()
 {
     $_SERVER['HTTP_HOST'] = $this->oldhost;
     Config::unnest();
     Email::set_mailer(new Mailer());
     parent::tearDown();
 }
 /**
  * @BeforeScenario
  */
 public function before(ScenarioEvent $event)
 {
     // Also set through the 'supportbehat' extension
     // to ensure its available both in CLI execution and the tested browser session
     $this->mailer = new \SilverStripe\BehatExtension\Utility\TestMailer();
     \Email::set_mailer($this->mailer);
     \Config::inst()->update("Email", "send_all_emails_to", null);
 }
 public function testSetup()
 {
     Object::useCustomClass('Email', 'SMTPEmail');
     Email::set_mailer(new SmtpMailer());
     SMTPEmail::set_mailer(new SmtpMailer());
     $mailer = Email::mailer();
     $this->assertEquals('SmtpMailer', get_class($mailer));
     $mailer = SMTPEmail::mailer();
     $this->assertEquals('SmtpMailer', get_class($mailer));
 }
 /**
  * Helper method to initialize the mailer
  *
  * @return SparkPostMailer
  */
 public static function setAsMailer()
 {
     $mailer = self::getInstance();
     // On SilverStripe 3.1, injector is not used
     $version = self::getFrameworkVersion();
     if (version_compare($version, '3.2.0', '<')) {
         Email::set_mailer($mailer);
     }
     Injector::inst()->registerService($mailer, 'Mailer');
     return $mailer;
 }
 /**
  * Helper method to initialize the mailer
  *
  * @param string $apiKey
  * @throws Exception
  */
 public static function setAsMailer($apiKey = null)
 {
     if ($apiKey === null) {
         if (defined('MANDRILL_API_KEY')) {
             $apiKey = MANDRILL_API_KEY;
         }
     }
     if (empty($apiKey)) {
         throw new Exception('Api key is empty');
     }
     $mandrillMailer = new MandrillMailer($apiKey);
     Email::set_mailer($mandrillMailer);
 }
 /**
  * Helper method to initialize the mailer
  *
  * @param string $apiKey
  * @throws Exception
  */
 public static function setAsMailer()
 {
     $mandrillMailer = new MandrillMailer();
     Email::set_mailer($mandrillMailer);
     if (defined('MANDRILL_SENDING_DISABLED') && MANDRILL_SENDING_DISABLED) {
         self::setSendingDisabled();
     }
     if (defined('MANDRILL_ENABLE_LOGGING') && MANDRILL_ENABLE_LOGGING) {
         self::setEnableLogging();
     }
     // Use custom classes
     Object::useCustomClass('Member_ChangePasswordEmail', 'Mandrill_ChangePasswordEmail');
     Object::useCustomClass('Member_ForgotPasswordEmail', 'Mandrill_ForgotPasswordEmail');
 }
Ejemplo n.º 9
0
 public function testSendHTML()
 {
     // Set custom $project - used in email headers
     global $project;
     $oldProject = $project;
     $project = 'emailtest';
     Email::set_mailer(new EmailTest_Mailer());
     $email = new Email('*****@*****.**', '*****@*****.**', 'Test send plain', 'Testing Email->sendPlain()', null, '*****@*****.**', '*****@*****.**');
     $email->attachFile(__DIR__ . '/fixtures/attachment.txt', null, 'text/plain');
     $email->addCustomHeader('foo', 'bar');
     $sent = $email->send(123);
     // Restore old project name after sending
     $project = $oldProject;
     $this->assertEquals('*****@*****.**', $sent['to']);
     $this->assertEquals('*****@*****.**', $sent['from']);
     $this->assertEquals('Test send plain', $sent['subject']);
     $this->assertContains('Testing Email->sendPlain()', $sent['content']);
     $this->assertNull($sent['plaincontent']);
     $this->assertEquals(array(0 => array('contents' => 'Hello, I\'m a text document.', 'filename' => 'attachment.txt', 'mimetype' => 'text/plain')), $sent['files']);
     $this->assertEquals(array('foo' => 'bar', 'X-SilverStripeMessageID' => 'emailtest.123', 'X-SilverStripeSite' => 'emailtest', 'Cc' => '*****@*****.**', 'Bcc' => '*****@*****.**'), $sent['customheaders']);
 }
<?php

Object::useCustomClass('Email', 'SMTPEmail');
Email::set_mailer(new SmtpMailer());
SMTPEmail::set_mailer(new SmtpMailer());
 /**
  *@return Integer - number of carts destroyed
  **/
 public function run($request)
 {
     //IMPORTANT!
     if ($this->doNotSendEmails) {
         Config::inst()->update("Email", "send_all_emails_to", "no-one@localhost");
         Email::set_mailer(new EcommerceTaskTryToFinaliseOrders_Mailer());
     }
     $orderStatusLogClassName = "OrderStatusLog";
     $submittedOrderStatusLogClassName = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     if ($submittedOrderStatusLogClassName) {
         $submittedStatusLog = $submittedOrderStatusLogClassName::get()->First();
         if ($submittedStatusLog) {
             $orderSteps = OrderStep::get()->sort("Sort", "DESC")->limit(1);
             $lastOrderStep = $orderSteps->First();
             if ($lastOrderStep) {
                 $joinSQL = "INNER JOIN \"\" ON ";
                 $whereSQL = "\"StatusID\" <> " . $lastOrderStep->ID . "";
                 $count = null;
                 if (isset($_GET["count"])) {
                     $count = intval($_GET["count"]);
                 }
                 if (!intval($count)) {
                     $count = 50;
                 }
                 $last = null;
                 if (isset($_GET["last"])) {
                     $last = intval($_GET["last"]);
                 }
                 if (!intval($last)) {
                     $last = intval(Session::get("EcommerceTaskTryToFinaliseOrders"));
                     if (!$last) {
                         $last = 0;
                     }
                 }
                 $orders = Order::get()->where($whereSQL)->sort("ID", "ASC")->innerJoin($orderStatusLogClassName, "\"{$orderStatusLogClassName}\".\"OrderID\" = \"Order\".\"ID\"")->limit($count, $last);
                 if ($orders->count()) {
                     DB::alteration_message("<h1>Moving {$count} Orders (starting from {$last})</h1>");
                     foreach ($orders as $order) {
                         $last++;
                         Session::set("EcommerceTaskTryToFinaliseOrders", $last);
                         $stepBefore = OrderStep::get()->byID($order->StatusID);
                         try {
                             $order->tryToFinaliseOrder();
                         } catch (Exception $e) {
                             DB::alteration_message($e, "deleted");
                         }
                         $stepAfter = OrderStep::get()->byID($order->StatusID);
                         if ($stepBefore) {
                             if ($stepBefore->ID == $stepAfter->ID) {
                                 DB::alteration_message("could not move Order " . $order->getTitle() . ", remains at <strong>" . $stepBefore->Name . "</strong>");
                             } else {
                                 DB::alteration_message("Moving Order #" . $order->getTitle() . " from <strong>" . $stepBefore->Name . "</strong> to <strong>" . $stepAfter->Name . "</strong>", "created");
                             }
                         } else {
                             DB::alteration_message("Moving Order " . $order->getTitle() . " from <strong>unknown step</strong> to <strong>" . $stepAfter->Name . "</strong>", "created");
                         }
                     }
                 } else {
                     Session::clear("EcommerceTaskTryToFinaliseOrders");
                     DB::alteration_message("<br /><br /><br /><br /><h1>COMPLETED!</h1>All orders have been moved.", "created");
                 }
             } else {
                 DB::alteration_message("NO last order step.", "deleted");
             }
         } else {
             DB::alteration_message("NO submitted order status log.", "deleted");
         }
     } else {
         DB::alteration_message("NO EcommerceConfig::get(\"OrderStatusLog\", \"order_status_log_class_used_for_submitting_order\")", "deleted");
     }
     if (Session::get("EcommerceTaskTryToFinaliseOrders")) {
         DB::alteration_message("WAIT: we are still moving more orders ... this page will automatically load the next lot in 5 seconds.", "deleted");
         echo "<script type=\"text/javascript\">window.setTimeout(function() {location.reload();}, 5000);</script>";
     }
 }
<?php

/*
 * Uncomment lines below to configure username, password and/or "From" mail
 */
// define('SENDGRIDMAILER_USERNAME', '<username>');
// define('SENDGRIDMAILER_PASSWORD', '<password>');
// define('SENDGRIDMAILER_MAIL', 'Info Test <*****@*****.**>'); //
Email::set_mailer(new CustomMailer());
SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/info.log'), SS_Log::INFO);
Ejemplo n.º 13
0
<?php

/**
 * Copyright 2015 Openstack Foundation
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
if (defined("SENDGRID_REST_API")) {
    Email::set_mailer(new SendGridWebMailer());
}
<?php

if (class_exists('StyledHtmlEmail')) {
    $mailer = new PHPMailerMailer();
    Email::set_mailer($mailer);
}
Ejemplo n.º 15
0
<?php

/**
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 3.01 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @package   LoggingMailer
 * @author     Nathaniel McHugh <*****@*****.**>
 */
Email::set_mailer(new LoggingMailer());
SS_Report::register('ReportAdmin', 'SentMailReport', -10);
<?php

/**
 * Created by Nivanka Fonseka (nivanka@silverstripers.com).
 * User: nivankafonseka
 * Date: 9/6/15
 * Time: 8:52 AM
 * To change this template use File | Settings | File Templates.
 */
$clientClass = Config::inst()->get('PostmarkAdmin', 'member_class');
Config::inst()->update('CRMAdmin', 'managed_models', array($clientClass));
Object::add_extension($clientClass, 'CustomerExtension');
require_once BASE_PATH . '/vendor/autoload.php';
global $databaseConfig;
$databaseConfig['type'] = 'PostmarkMySQLDatabase';
define('POSTMARK_PATH', dirname(__FILE__));
define('POSTMARK_RELATIVE_PATH', str_replace(dirname(POSTMARK_PATH) . '/', '', POSTMARK_PATH));
Email::set_mailer(new PostmarkMailer());
Ejemplo n.º 17
0
	function tearDown() {
		// Restore email configuration
		Email::set_mailer($this->originalMailer);
		$this->originalMailer = null;
		$this->mailer = null;

		// Restore password validation
		Member::set_password_validator($this->originalMemberPasswordValidator);
		
		// Restore requirements
		Requirements::set_backend($this->originalRequirements);

		// Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
		self::$is_running_test = $this->originalIsRunningTest;
		$this->originalIsRunningTest = null;
	}
Ejemplo n.º 18
0
<?php

/**
 * @author nicolaas [at] www.sunnysideup.co.nz
 **/
if (defined("use_testmailer")) {
    Email::set_mailer(new TestMailerToFile());
}
Ejemplo n.º 19
0
<?php

// This module takes over mailer settings; to enable outbound sends, add the following
// CaptureMailer::$outbound_send = true
// to stop capturing emails, add
// CaptureMailer::$capture_emails = false
Email::set_mailer(new CaptureMailer());
 function tearDown()
 {
     // Preserve memory settings
     ini_set('memory_limit', $this->originalMemoryLimit ? $this->originalMemoryLimit : -1);
     // Restore email configuration
     Email::set_mailer($this->originalMailer);
     $this->originalMailer = null;
     $this->mailer = null;
     // Restore password validation
     Member::set_password_validator($this->originalMemberPasswordValidator);
     // Restore requirements
     Requirements::set_backend($this->originalRequirements);
     // Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls
     self::$is_running_test = $this->originalIsRunningTest;
     $this->originalIsRunningTest = null;
     // Reset theme setting
     SSViewer::set_theme($this->originalTheme);
     // Reset mocked datetime
     SS_Datetime::clear_mock_now();
     // Restore nested_urls state
     if ($this->originalNestedURLsState) {
         SiteTree::enable_nested_urls();
     } else {
         SiteTree::disable_nested_urls();
     }
     // Stop the redirection that might have been requested in the test.
     // Note: Ideally a clean Controller should be created for each test.
     // Now all tests executed in a batch share the same controller.
     $controller = Controller::has_curr() ? Controller::curr() : null;
     if ($controller && $controller->response && $controller->response->getHeader('Location')) {
         $controller->response->setStatusCode(200);
         $controller->response->removeHeader('Location');
     }
 }
<?php

Email::set_mailer(new EmogrifierMailer());
<?php

use Mrk\Mailgun\Mailer as MrkMailgunMailer;
define('MAILGUN_KEY', 'key-01zghfgcxo4ta4t4j7h8g9pyi4xfgmn0');
define('MAILGUN_DOMAIN', 'sandbox8297.mailgun.org');
define('MAILGUN_FROM', '*****@*****.**');
Email::set_mailer(new MrkMailgunMailer());