forked from thelia-modules/Mailjet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailjet.php
100 lines (85 loc) · 3.58 KB
/
Mailjet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Mailjet;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Install\Database;
use Thelia\Model\Config;
use Thelia\Model\ConfigQuery;
use Thelia\Module\BaseModule;
/**
* Class Mailjet
* @package Mailjet
* @author Benjamin Perche <bperche@openstudio.com>
*/
class Mailjet extends BaseModule
{
const MESSAGE_DOMAIN = "mailjet";
const CONFIG_NEWSLETTER_LIST = "mailjet.newsletter_list";
const CONFIG_API_KEY = "mailjet.api.key";
const CONFIG_API_SECRET = "mailjet.api.secret";
const CONFIG_API_WS_ADDRESS = "mail.api.webservice_address";
const CONFIG_THROW_EXCEPTION_ON_ERROR = "mailjet.throw_exception_on_error";
public function postActivation(ConnectionInterface $con = null)
{
$con->beginTransaction();
try {
if (null === ConfigQuery::read(static::CONFIG_API_KEY)) {
$this->createConfigValue(static::CONFIG_API_KEY, [
"fr_FR" => "Clé d'API pour mailjet",
"en_US" => "Api key for mailjet",
]);
}
if (null === ConfigQuery::read(static::CONFIG_API_SECRET)) {
$this->createConfigValue(static::CONFIG_API_SECRET, [
"fr_FR" => "Secret d'API pour mailjet",
"en_US" => "Api secret for mailjet",
]);
}
if (null === ConfigQuery::read(static::CONFIG_NEWSLETTER_LIST)) {
$this->createConfigValue(static::CONFIG_NEWSLETTER_LIST, [
"fr_FR" => "ALT de la liste de diffusion mailjet",
"en_US" => "Diffusion list ALT of mailjet",
]);
}
if (null === ConfigQuery::read(static::CONFIG_API_WS_ADDRESS)) {
$this->createConfigValue(
static::CONFIG_API_WS_ADDRESS,
[
"fr_FR" => "Adresse du webservice mailjet",
"en_US" => "Address of the mailjet webservice",
],
"https://api.mailjet.com/v3/REST"
);
}
$database = new Database($con);
$database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]);
$con->commit();
} catch (\Exception $e) {
$con->rollBack();
throw $e;
}
}
protected function createConfigValue($name, array $translation, $value = '')
{
$config = new Config();
$config
->setName($name)
->setValue($value)
;
foreach ($translation as $locale => $title) {
$config->getTranslation($locale)
->setTitle($title)
;
}
$config->save();
}
}