Skip to content

Commit 69bb283

Browse files
committed
Added setting to store html
1 parent bf5ba98 commit 69bb283

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 1.2.6
4+
5+
* Added: Setting to enable storage of HTML instead of Text
6+
37
### 1.2.5
48

59
* Fixed: Added no search HTML for performance reasons.

src/Processors/CommunicationProcessor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
use Rhubarb\Scaffolds\Communications\Models\Communication;
1414
use Rhubarb\Scaffolds\Communications\Models\CommunicationItem;
1515
use Rhubarb\Scaffolds\Communications\Models\CommunicationItemSendAttempt;
16-
use Rhubarb\Scaffolds\Communications\Tests\Models\CommunicationItemTest;
17-
use Rhubarb\Stem\Filters\Equals;
16+
use Rhubarb\Scaffolds\Communications\Settings\CommunicationProcessorSettings;
1817
use Rhubarb\Stem\Schema\SolutionSchema;
1918

2019
final class CommunicationProcessor
@@ -182,6 +181,8 @@ public static function draftPackage(CommunicationPackage $package)
182181
}
183182
$communication->save();
184183

184+
$storeHtml = CommunicationProcessorSettings::singleton()->storeHtml;
185+
185186
foreach ($package->getSendables() as $sendable) {
186187
foreach ($sendable->getRecipients() as $recipient) {
187188
$clone = clone $sendable;
@@ -190,7 +191,7 @@ public static function draftPackage(CommunicationPackage $package)
190191

191192
$item = SolutionSchema::getModel("CommunicationItem");
192193
$item->Recipient = (string)$recipient;
193-
$item->Text = $clone->getText();
194+
$item->Text = $storeHtml ? $clone->getHtml() : $clone->getText();
194195
$item->Type = $clone->getSendableType();
195196
$item->SendableClassName = get_class($clone);
196197
$data = $clone->toArray();

src/Settings/CommunicationProcessorSettings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ class CommunicationProcessorSettings extends Settings
1010
* @var int Number of emails to send max per second.
1111
*/
1212
public $throttle = 20;
13-
}
13+
14+
public $storeHtml = false;
15+
}

tests/unit/Processors/CommunicationProcessorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Rhubarb\Scaffolds\Communications\Models\CommunicationItem;
1212
use Rhubarb\Scaffolds\Communications\Models\CommunicationItemSendAttempt;
1313
use Rhubarb\Scaffolds\Communications\Processors\CommunicationProcessor;
14+
use Rhubarb\Scaffolds\Communications\Settings\CommunicationProcessorSettings;
1415
use Rhubarb\Scaffolds\Communications\Tests\Fixtures\CommunicationTestCase;
1516

1617
class CommunicationProcessorTest extends CommunicationTestCase
@@ -122,6 +123,7 @@ private function createCommunication($dateToSend)
122123
{
123124
$email = new SimpleEmail();
124125
$email->setText("Test Message Body");
126+
$email->setHtml('<p>Test Message Body</p>');
125127
$email->setSender("sender@gcdtech.com");
126128
$email->addRecipientByEmail("test@test.com");
127129

@@ -157,4 +159,15 @@ private function createCommunicationWithMultipleRecipients($dateToSend, $noOfRec
157159

158160
return $communication;
159161
}
162+
163+
public function testStoreHtmlUponRequest()
164+
{
165+
$this->createCommunication(null);
166+
self::assertNotContains('<p>', CommunicationItem::findLast()->Text);
167+
168+
CommunicationProcessorSettings::singleton()->storeHtml = true;
169+
170+
$this->createCommunication(null);
171+
self::assertContains('<p>', CommunicationItem::findLast()->Text);
172+
}
160173
}

0 commit comments

Comments
 (0)