Skip to content

Commit

Permalink
sysvmsg extension is no longer required + modernized module
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Aug 6, 2024
1 parent 713369b commit 9f56542
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 97 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "Auto Release"
on:
push:
branches: [ master, main ]
jobs:
release:
uses: thelia-modules/ReusableWorkflow/.github/workflows/auto_release.yml@main
29 changes: 5 additions & 24 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">

<loops>
<!-- sample definition
<loop name="MySuperLoop" class="InvoiceRef\Loop\MySuperLoop" />
-->
</loops>

<forms>
<form name="invoiceref_configuration" class="InvoiceRef\Form\ConfigurationForm" />
<!--
<form name="MyFormName" class="InvoiceRef\Form\MySuperForm" />
-->
</forms>

<commands>
<!--
<command class="InvoiceRef\Command\MySuperCommand" />
-->
</commands>

<!--<services>
<service id="invoiceRef.listener" class="InvoiceRef\EventListeners\OrderListener">
<tag name="kernel.event_subscriber"/>
</service>
</services>-->
<hooks>
<hook id="invoiceref.back.hook" class="InvoiceRef\Hook\BackHook">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfiguration"/>
</hook>
</hooks>
</config>
4 changes: 2 additions & 2 deletions Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
<fullnamespace>InvoiceRef\InvoiceRef</fullnamespace>
<descriptive locale="en_US">
<title>Manage invoive ref</title>
<title>Invoice references management</title>
</descriptive>
<descriptive locale="fr_FR">
<title>Gestion des numéros de facture</title>
Expand All @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.0.0</version>
<version>2.0.1</version>
<author>
<name>Manuel Raynaud</name>
<email>[email protected]</email>
Expand Down
60 changes: 36 additions & 24 deletions EventListeners/OrderListener.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* 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. */
/*************************************************************************************/

/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* 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 InvoiceRef\EventListeners;

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\Log\Tlog;
use Thelia\Model\ConfigQuery;

/**
* Class OrderListener
* @package InvoiceRef\EventListeners
* Class OrderListener.
*
* @author manuel raynaud <[email protected]>
*/
class OrderListener implements EventSubscriberInterface
{
/**
* @param OrderEvent $event
* @throws \Propel\Runtime\Exception\PropelException
*/
public function implementInvoice(OrderEvent $event)
public function implementInvoice(OrderEvent $event): void
{
$order = $event->getOrder();

if ($order->isPaid() && null === $order->getInvoiceRef()) {
$store = new SemaphoreStore();
$flockFactory = new LockFactory($store);
$lock = null;

$lock = $flockFactory->createLock('invoice-ref-generation');
// Try to acquire lock, being fault-tolerant if it can't be acquired
// for whatever reason.
try {
$flockFactory = new LockFactory(new FlockStore());

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

// Acquire a blocking lock
$lock->acquire(true);
// Acquire a blocking lock
$lock->acquire(true);
} catch (\Exception $ex) {
Tlog::getInstance()->error('Failed to acquire lock : '.$ex->getMessage());
}

try {
$invoiceRef = ConfigQuery::create()
->findOneByName('invoiceRef');

if (null === $invoiceRef) {
throw new \RuntimeException("you must set an invoice ref in your admin panel");
throw new \RuntimeException('you must set an invoice ref in your admin panel');
}

$value = $invoiceRef->getValue();
Expand All @@ -62,7 +74,7 @@ public function implementInvoice(OrderEvent $event)
->save();
} finally {
// Always release lock !
$lock->release();
$lock?->release();
}
}
}
Expand Down Expand Up @@ -90,7 +102,7 @@ public function implementInvoice(OrderEvent $event)
public static function getSubscribedEvents()
{
return [
TheliaEvents::ORDER_UPDATE_STATUS => ['implementInvoice', 100]
TheliaEvents::ORDER_UPDATE_STATUS => ['implementInvoice', 100],
];
}
}
36 changes: 17 additions & 19 deletions Form/ConfigurationForm.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* 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. */
/*************************************************************************************/

/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace InvoiceRef\Form;

Expand All @@ -20,17 +20,15 @@
use Thelia\Model\ConfigQuery;

/**
* Class ConfigurationForm
* @package InvoiceRef\Form
* Class ConfigurationForm.
*
* @author manuel raynaud <[email protected]>
*/
class ConfigurationForm extends BaseForm
{

/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
* Form this you have to call add method on $this->formBuilder attribute :.
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
Expand All @@ -52,13 +50,13 @@ protected function buildForm()
$this->formBuilder
->add('invoice', TextType::class, [
'constraints' => [
new NotBlank()
new NotBlank(),
],
'label' => Translator::getInstance()->trans('invoice ref', [], InvoiceRef::DOMAIN_NAME),
'label_attr' => [
'for' => 'invoice-ref'
'for' => 'invoice-ref',
],
'data' => ConfigQuery::read('invoiceRef', 0)
'data' => ConfigQuery::read('invoiceRef', 0),
]);
}

Expand All @@ -67,6 +65,6 @@ protected function buildForm()
*/
public static function getName()
{
return 'invoiceref_config';
return 'invoiceref_configuration';
}
}
24 changes: 24 additions & 0 deletions Hook/BackHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace InvoiceRef\Hook;

use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;

class BackHook extends BaseHook
{
public function onModuleConfiguration(HookRenderEvent $event): void
{
$event->add($this->render('module_configuration.html'));
}
}
2 changes: 1 addition & 1 deletion I18n/en_US.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return array(
'invoice ref' => 'invoice ref',
'invoice ref' => 'Nex invoice reference number',
);
2 changes: 1 addition & 1 deletion I18n/fr_FR.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return array(
'invoice ref' => 'Numéro de facture',
'invoice ref' => 'Prochain numéro de facture',
);
19 changes: 9 additions & 10 deletions InvoiceRef.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* 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. */
/*************************************************************************************/
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace InvoiceRef;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
{intl d='invoiceref.ai' l="Invoice ref Configuration"}
</div>
</div>

<div class="form-container">
<div class="row">
<div class="col-md-12">
{form name="invoiceref_configuration"}

<form action="{url path="/admin/module/InvoiceRef/configure"}" method="post">
{form_hidden_fields form=$form}

Expand All @@ -30,23 +28,13 @@

<div class="row">
<div class="col-md-4">
{form_field form=$form field="invoice"}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} {if $required} <span class="required">*</span>{/if}

{form_error form=$form field="invoice"}
<br />
<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>
{/form_field}
</div>
{render_form_field field="invoice"}
</div>
</div>
</form>
{/form}
</div>
</div>
</div>
</div>
</div>
</div>

0 comments on commit 9f56542

Please sign in to comment.