Skip to content

Commit

Permalink
Merge pull request #5 from NicolasBarbey/main
Browse files Browse the repository at this point in the history
Thelia 2.5 compatibility
  • Loading branch information
julescournut authored Oct 7, 2021
2 parents 14f6c80 + 1edbe00 commit 713369b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AdminIncludes/module_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

{form_error form=$form field="invoice"}
<br />
<span class="error">{$message}</span>
<span class="error">{$message|default:null}</span>
{/form_error}
<input type="text" {if $required}aria-required="true" required{/if} placeholder="{$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control" />
</label>
Expand Down
4 changes: 2 additions & 2 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
-->
</commands>

<services>
<!--<services>
<service id="invoiceRef.listener" class="InvoiceRef\EventListeners\OrderListener">
<tag name="kernel.event_subscriber"/>
</service>
</services>
</services>-->
</config>
4 changes: 2 additions & 2 deletions Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.1.1</version>
<version>2.0.0</version>
<author>
<name>Manuel Raynaud</name>
<email>[email protected]</email>
</author>
<type>classic</type>
<thelia>2.1.0</thelia>
<thelia>2.5.0</thelia>
<stability>prod</stability>
</module>
4 changes: 2 additions & 2 deletions Config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</route>
-->

<route id="invoiceRef.configuration" path="/admin/module/InvoiceRef/configure" methods="post">
<!--<route id="invoiceRef.configuration" path="/admin/module/InvoiceRef/configure" methods="post">
<default key="_controller">InvoiceRef\Controller\ConfigurationController::configureAction</default>
</route>
</route>-->

</routes>
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" namespace="InvoiceRef\Model">
<database defaultIdMethod="native" name="TheliaMain" namespace="InvoiceRef\Model">
<!--
See propel documentation on http://propelorm.org for all information about schema file
-->
Expand Down
2 changes: 1 addition & 1 deletion Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function configureAction()
return $response;
}

$form = new ConfigurationForm($this->getRequest());
$form = $this->createForm(ConfigurationForm::getName());

$response = $error_msg = $e = null;

Expand Down
6 changes: 4 additions & 2 deletions EventListeners/OrderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Lock\Factory;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\Store\FlockStore;
use Symfony\Component\Lock\Store\SemaphoreStore;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\ConfigQuery;
Expand All @@ -35,8 +37,8 @@ public function implementInvoice(OrderEvent $event)
$order = $event->getOrder();

if ($order->isPaid() && null === $order->getInvoiceRef()) {
// Protect genration against concurrent executions
$flockFactory = new Factory(new FlockStore());
$store = new SemaphoreStore();
$flockFactory = new LockFactory($store);

$lock = $flockFactory->createLock('invoice-ref-generation');

Expand Down
5 changes: 3 additions & 2 deletions Form/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace InvoiceRef\Form;

use InvoiceRef\InvoiceRef;
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 @@ -49,7 +50,7 @@ class ConfigurationForm extends BaseForm
protected function buildForm()
{
$this->formBuilder
->add('invoice', 'text', [
->add('invoice', TextType::class, [
'constraints' => [
new NotBlank()
],
Expand All @@ -64,7 +65,7 @@ protected function buildForm()
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
public static function getName()
{
return 'invoiceref_config';
}
Expand Down
11 changes: 10 additions & 1 deletion InvoiceRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Thelia\Model\ConfigQuery;
use Thelia\Model\OrderQuery;
use Thelia\Module\BaseModule;
Expand All @@ -22,7 +23,7 @@ class InvoiceRef extends BaseModule
{
const DOMAIN_NAME = "invoiceref";

public function postActivation(ConnectionInterface $con = null)
public function postActivation(ConnectionInterface $con = null): void
{
if (null === ConfigQuery::read('invoiceRef', null)) {
if (null !== $lastOderPaid = OrderQuery::create()
Expand All @@ -38,4 +39,12 @@ public function postActivation(ConnectionInterface $con = null)
}
}
}

public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR . ucfirst(self::getModuleCode()). "/I18n/*"])
->autowire(true)
->autoconfigure(true);
}
}

0 comments on commit 713369b

Please sign in to comment.