Skip to content

Commit

Permalink
CRM-19690 - Implement FlexMailer. Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Dec 17, 2016
1 parent 0a8e6fc commit fa4706e
Show file tree
Hide file tree
Showing 20 changed files with 1,960 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Civi/FlexMailer/Event/AlterBatchEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\Event;

/**
* Class AlterBatchEvent
* @package Civi\FlexMailer\Event
*/
class AlterBatchEvent extends BaseEvent {

/**
* @var array<FlexMailerTask>
*/
private $tasks;

public function __construct($context, $tasks) {
parent::__construct($context);
$this->tasks = $tasks;
}

/**
* @return array<FlexMailerTask>
*/
public function getTasks() {
return $this->tasks;
}

}
72 changes: 72 additions & 0 deletions Civi/FlexMailer/Event/BaseEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\Event;

/**
* Class BaseEvent
* @package Civi\FlexMailer\Event
*/
class BaseEvent extends \Symfony\Component\EventDispatcher\Event {
/**
* @var array
* An array which must define options:
* - mailing: \CRM_Mailing_BAO_Mailing
* - job: \CRM_Mailing_BAO_MailingJob
* - attachments: array
*/
public $context;

/**
* BaseEvent constructor.
* @param array $context
*/
public function __construct(array $context) {
$this->context = $context;
}

/**
* @return \CRM_Mailing_BAO_Mailing
*/
public function getMailing() {
return $this->context['mailing'];
}

/**
* @return \CRM_Mailing_BAO_MailingJob
*/
public function getJob() {
return $this->context['job'];
}

/**
* @return array|NULL
*/
public function getAttachments() {
return $this->context['attachments'];
}

}
52 changes: 52 additions & 0 deletions Civi/FlexMailer/Event/ComposeBatchEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\Event;

/**
* Class ComposeBatchEvent
* @package Civi\FlexMailer\Event
*/
class ComposeBatchEvent extends BaseEvent {

/**
* @var array<FlexMailerTask>
*/
private $tasks;

public function __construct($context, $tasks) {
parent::__construct($context);
$this->tasks = $tasks;
}

/**
* @return array<FlexMailerTask>
*/
public function getTasks() {
return $this->tasks;
}

}
64 changes: 64 additions & 0 deletions Civi/FlexMailer/Event/RunEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\Event;

/**
* Class RunEvent
* @package Civi\FlexMailer\Event
*
* The RunEvent fires at the start of mail delivery process.
*
* You may use this event to either:
* - Perform extra initialization at the start of the process.
* - Short-circuit the entire process. In this use-case, be
* sure to run `$event->stopPropagation()`
* and `$event->setCompleted($bool)`.
*/
class RunEvent extends BaseEvent {

/**
* @var bool|NULL
*/
private $isCompleted = NULL;

/**
* @return bool|NULL
*/
public function getCompleted() {
return $this->isCompleted;
}

/**
* @param bool|NULL $isCompleted
* @return RunEvent
*/
public function setCompleted($isCompleted) {
$this->isCompleted = $isCompleted;
return $this;
}

}
73 changes: 73 additions & 0 deletions Civi/FlexMailer/Event/SendBatchEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\Event;

/**
* Class SendBatchEvent
* @package Civi\FlexMailer\Event
*/
class SendBatchEvent extends BaseEvent {

/**
* @var array<FlexMailerTask>
*/
private $tasks;

/**
* @var bool|NULL
*/
private $isCompleted = NULL;

public function __construct($context, $tasks) {
parent::__construct($context);
$this->tasks = $tasks;
}

/**
* @return array<FlexMailerTask>
*/
public function getTasks() {
return $this->tasks;
}

/**
* @return bool|NULL
*/
public function getCompleted() {
return $this->isCompleted;
}

/**
* @param bool|NULL $isCompleted
* @return SendBatchEvent
*/
public function setCompleted($isCompleted) {
$this->isCompleted = $isCompleted;
return $this;
}

}
74 changes: 74 additions & 0 deletions Civi/FlexMailer/Event/WalkBatchesEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\Event;

/**
* Class WalkBatchesEvent
* @package Civi\FlexMailer\Event
*/
class WalkBatchesEvent extends BaseEvent {

/**
* @var callable
*/
protected $callback;

/**
* @var bool|NULL
*/
protected $isDelivered = NULL;

public function __construct($context, $callback) {
parent::__construct($context);
$this->callback = $callback;
}

/**
* @return bool|NULL
*/
public function getCompleted() {
return $this->isDelivered;
}

/**
* @param bool|NULL $isCompleted
* @return WalkBatchesEvent
*/
public function setCompleted($isCompleted) {
$this->isDelivered = $isCompleted;
return $this;
}

/**
* @param array <FlexMailerTask> $tasks
* @return mixed
*/
public function visit($tasks) {
return call_user_func($this->callback, $tasks);
}

}
Loading

0 comments on commit fa4706e

Please sign in to comment.