Skip to content

Commit e298e33

Browse files
noglitchyolorenzo
authored andcommitted
Added: alter template column so it can accept longer template path (#36)
* Added: alter template column so it can accept longer template path * Changed: limit maximum length to 100, and added documentation about it * Added: throw exception if `template` length is greater than maximum allowed
1 parent 73cbf55 commit e298e33

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ and queue a new one by storing the correct data:
6363
- Third arguments is an array of options, possible options are
6464
* `subject`: Email's subject
6565
* `send_at`: date time sting representing the time this email should be sent at (in UTC)
66-
* `template`: the name of the element to use as template for the email message
66+
* `template`: the name of the element to use as template for the email message. (maximum supported length is 100 chars)
6767
* `layout`: the name of the layout to be used to wrap email message
6868
* `format`: Type of template to use (html, text or both)
6969
* `headers`: A key-value list of headers to send in the email
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
use Migrations\AbstractMigration;
3+
use Phinx\Db\Adapter\MysqlAdapter;
4+
5+
class AlterTemplateToEmailQueue extends AbstractMigration
6+
{
7+
/**
8+
* Up Method
9+
*
10+
* More information on this method is available here:
11+
* http://docs.phinx.org/en/latest/migrations.html#the-up-method
12+
*
13+
* @return void
14+
*/
15+
public function up()
16+
{
17+
$this->table('email_queue')
18+
->changeColumn('template', 'string', [
19+
'limit' => 100,
20+
])
21+
->update();
22+
}
23+
24+
/**
25+
* Down Method
26+
*
27+
* More information on this method is available here:
28+
* http://docs.phinx.org/en/latest/migrations.html#the-down-method
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
$this->table('email_queue')
35+
->changeColumn('template', 'string', [
36+
'limit' => 50,
37+
])
38+
->update();
39+
}
40+
}

src/Model/Table/EmailQueueTable.php

+8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
use Cake\ORM\Table;
1010
use EmailQueue\Database\Type\JsonType;
1111
use EmailQueue\Database\Type\SerializeType;
12+
use LengthException;
1213

1314
/**
1415
* EmailQueue Table.
1516
*/
1617
class EmailQueueTable extends Table
1718
{
19+
const MAX_TEMPLATE_LENGTH = 100;
20+
1821
/**
1922
* {@inheritdoc}
2023
*/
@@ -50,10 +53,15 @@ public function initialize(array $config = [])
5053
* - config : the name of the email config to be used for sending
5154
*
5255
* @throws \Exception any exception raised in transactional callback
56+
* @throws LengthException If `template` option length is greater than maximum allowed length
5357
* @return bool
5458
*/
5559
public function enqueue($to, array $data, array $options = [])
5660
{
61+
if (strlen($options['template']) > self::MAX_TEMPLATE_LENGTH) {
62+
throw new LengthException('`template` length must be less or equal to ' . self::MAX_TEMPLATE_LENGTH);
63+
}
64+
5765
$defaults = [
5866
'subject' => '',
5967
'send_at' => new FrozenTime('now'),

0 commit comments

Comments
 (0)