Skip to content

Commit

Permalink
Thelia 2.5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Oct 26, 2022
1 parent 4061cc0 commit de3bb24
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 2,132 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.3.2</version>
<version>2.0.0</version>
<author>
<name>Benjamin Perche, Franck Allimant</name>
<email>bperche@openstudio.fr, thelia@cqfdev.fr</email>
Expand Down
2 changes: 1 addition & 1 deletion Config/schema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia">
<database defaultIdMethod="native" name="TheliaMain">
<table name="mailjet_newsletter" namespace="Mailjet\Model">
<column name="id" autoIncrement="true" type="INTEGER" required="true" primaryKey="true" />
<column name="mailjet_id" type="VARCHAR" size="255" required="true" />
Expand Down
14 changes: 8 additions & 6 deletions Controller/MailjetConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use Mailjet\Form\MailjetConfigurationForm;
use Mailjet\Mailjet;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Template\ParserContext;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;

Expand All @@ -26,9 +28,9 @@
*/
class MailjetConfigController extends BaseAdminController
{
public function saveAction()
public function saveAction(Request $request, ParserContext $parserContext)
{
$baseForm = new MailjetConfigurationForm($this->getRequest());
$baseForm = $this->createForm(MailjetConfigurationForm::getName());

try {
$form = $this->validateForm($baseForm);
Expand All @@ -38,15 +40,15 @@ public function saveAction()
ConfigQuery::write(Mailjet::CONFIG_API_SECRET, $data["api_secret"]);
ConfigQuery::write(Mailjet::CONFIG_API_WS_ADDRESS, $data["ws_address"]);
ConfigQuery::write(Mailjet::CONFIG_NEWSLETTER_LIST, $data["newsletter_list"]);
ConfigQuery::write(Mailjet::CONFIG_THROW_EXCEPTION_ON_ERROR, $data["exception_on_errors"] ? true : false);
ConfigQuery::write(Mailjet::CONFIG_THROW_EXCEPTION_ON_ERROR, (bool)$data["exception_on_errors"]);

$this->getParserContext()->set("success", true);
$parserContext->set("success", true);

if ("close" === $this->getRequest()->request->get("save_mode")) {
if ("close" === $request->request->get("save_mode")) {
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/modules"));
}
} catch (\Exception $e) {
$this->getParserContext()
$parserContext
->setGeneralError($e->getMessage())
->addForm($baseForm)
;
Expand Down
12 changes: 6 additions & 6 deletions EventListeners/NewsletterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

namespace Mailjet\EventListeners;

use Mailjet\Api\MailjetClient;
use Mailjet\Mailjet;
use Mailjet\Mailjet as MailjetModule;
use Mailjet\Model\MailjetNewsletter;
use Mailjet\Model\MailjetNewsletterQuery;
use Mailjet\Api\MailjetClient;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Mailjet\Mailjet as MailjetModule;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
use Thelia\Model\NewsletterQuery;
Expand All @@ -33,7 +33,7 @@
class NewsletterListener implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
* @var Translator
*/
protected $translator;

Expand All @@ -42,7 +42,7 @@ class NewsletterListener implements EventSubscriberInterface
*/
protected $api;

public function __construct(TranslatorInterface $translator)
public function __construct(Translator $translator)
{
$this->translator = $translator;

Expand Down
18 changes: 9 additions & 9 deletions Form/MailjetConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namespace Mailjet\Form;

use Mailjet\Mailjet;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
Expand Down Expand Up @@ -42,15 +44,13 @@ class MailjetConfigurationForm extends BaseForm
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$translator = Translator::getInstance();

$this->formBuilder
->add("api_key", "text", array(
->add("api_key", TextType::class, array(
"label" => $translator->trans("Api key", [], Mailjet::MESSAGE_DOMAIN),
"label_attr" => ["for" => "api_key"],
"required" => true,
Expand All @@ -59,7 +59,7 @@ protected function buildForm()
),
"data" => ConfigQuery::read(Mailjet::CONFIG_API_KEY)
))
->add("api_secret", "text", array(
->add("api_secret", TextType::class, array(
"label" => $translator->trans("Api secret", [], Mailjet::MESSAGE_DOMAIN),
"label_attr" => ["for" => "api_secret"],
"required" => true,
Expand All @@ -68,7 +68,7 @@ protected function buildForm()
),
"data" => ConfigQuery::read(Mailjet::CONFIG_API_SECRET)
))
->add("newsletter_list", "text", array(
->add("newsletter_list", TextType::class, array(
"label" => $translator->trans("Newsletter list address name", [], Mailjet::MESSAGE_DOMAIN),
"required" => true,
"constraints" => array(
Expand All @@ -83,7 +83,7 @@ protected function buildForm()
)
]
))
->add("ws_address", "text", array(
->add("ws_address", TextType::class, array(
"label" => $translator->trans("Webservice address", [], Mailjet::MESSAGE_DOMAIN),
"label_attr" => ["for" => "ws_address"],
"required" => true,
Expand All @@ -92,9 +92,9 @@ protected function buildForm()
),
"data" => ConfigQuery::read(Mailjet::CONFIG_API_WS_ADDRESS)
))
->add("exception_on_errors", "checkbox", array(
->add("exception_on_errors", CheckboxType::class, array(
"label" => $translator->trans("Throw exception on Mailjet error", [], Mailjet::MESSAGE_DOMAIN),
"data" => ConfigQuery::read(Mailjet::CONFIG_THROW_EXCEPTION_ON_ERROR, false) ? true : false,
"data" => (bool)ConfigQuery::read(Mailjet::CONFIG_THROW_EXCEPTION_ON_ERROR, false),
'required' => false,
"label_attr" => [
'help' => $translator->trans(
Expand All @@ -110,7 +110,7 @@ protected function buildForm()
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
public static function getName()
{
return "mailjet_configuration";
}
Expand Down
4 changes: 2 additions & 2 deletions Mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Mailjet extends BaseModule
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)
public function postActivation(ConnectionInterface $con = null): void
{
$con->beginTransaction();

Expand Down Expand Up @@ -105,7 +105,7 @@ protected function createConfigValue($name, array $translation, $value = '')
* @param string $newVersion
* @param ConnectionInterface $con
*/
public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
public function update($currentVersion, $newVersion, ConnectionInterface $con = null): void
{
if ($newVersion === '1.3.2') {
$db = new Database($con);
Expand Down
Loading

0 comments on commit de3bb24

Please sign in to comment.