-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMailjet.php
130 lines (110 loc) · 4.68 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?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 Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Symfony\Component\Filesystem\Filesystem;
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): void
{
$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();
}
/**
* @param string $currentVersion
* @param string $newVersion
* @param ConnectionInterface $con
*/
public function update($currentVersion, $newVersion, ConnectionInterface $con = null): void
{
if ($newVersion === '1.3.2') {
$db = new Database($con);
$tableExists = $db->execute("SHOW TABLES LIKE 'mailjet_newsletter'")->rowCount();
if ($tableExists) {
// Le champ relation ID change de format.
$db->execute("ALTER TABLE `mailjet_newsletter` CHANGE `relation_id` `relation_id` varchar(255) NOT NULL AFTER `email`");
}
}
}
public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR.ucfirst(self::getModuleCode()).'/I18n/*'])
->autowire(true)
->autoconfigure(true);
}
}