mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fixed: [budget] force budget kind and resource kind to have a unique kind
field in database
This commit is contained in:
parent
9e63480c70
commit
2d013e110a
@ -12,12 +12,17 @@ declare(strict_types=1);
|
||||
namespace Chill\BudgetBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Type of charge.
|
||||
*
|
||||
* @ORM\Table(name="chill_budget.charge_type")
|
||||
* @ORM\Table(name="chill_budget.charge_type",
|
||||
* uniqueConstraints={@ORM\UniqueConstraint(name="charge_kind_unique_type_idx", fields={"kind"})}
|
||||
* )
|
||||
* @ORM\Entity
|
||||
* @UniqueEntity(fields={"kind"})
|
||||
*/
|
||||
class ChargeKind
|
||||
{
|
||||
@ -35,6 +40,8 @@ class ChargeKind
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, options={"default": ""}, nullable=false)
|
||||
* @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric")
|
||||
* @Assert\Length(min=3)
|
||||
*/
|
||||
private string $kind = '';
|
||||
|
||||
|
@ -12,12 +12,17 @@ declare(strict_types=1);
|
||||
namespace Chill\BudgetBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Type of resource.
|
||||
*
|
||||
* @ORM\Table(name="chill_budget.resource_type")
|
||||
* @ORM\Table(name="chill_budget.resource_type", uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="resource_kind_unique_type_idx", fields={"kind"})
|
||||
* })
|
||||
* @ORM\Entity
|
||||
* @UniqueEntity(fields={"kind"})
|
||||
*/
|
||||
class ResourceKind
|
||||
{
|
||||
@ -35,6 +40,8 @@ class ResourceKind
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=false, options={"default": ""})
|
||||
* @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric")
|
||||
* @Assert\Length(min=3)
|
||||
*/
|
||||
private string $kind = '';
|
||||
|
||||
|
@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -25,7 +26,11 @@ class ChargeKindType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom',
|
||||
'label' => 'Title',
|
||||
])
|
||||
->add('kind', TextType::class, [
|
||||
'label' => 'budget.admin.form.Charge_kind_key',
|
||||
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document'
|
||||
])
|
||||
->add('ordering', NumberType::class)
|
||||
->add('isActive', CheckboxType::class, [
|
||||
|
@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -25,7 +26,11 @@ class ResourceKindType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom',
|
||||
'label' => 'Title',
|
||||
])
|
||||
->add('kind', TextType::class, [
|
||||
'label' => 'budget.admin.form.Resource_kind_key',
|
||||
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document'
|
||||
])
|
||||
->add('ordering', NumberType::class)
|
||||
->add('isActive', CheckboxType::class, [
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Budget;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20230209161546 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Budget: add unique constraint on kind for charge_kind and resource_kind';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql("UPDATE chill_budget.resource_type SET kind=md5(random()::text) WHERE kind = ''");
|
||||
$this->addSql("UPDATE chill_budget.charge_type SET kind=md5(random()::text) WHERE kind = ''");
|
||||
$this->addSql('CREATE UNIQUE INDEX resource_kind_unique_type_idx ON chill_budget.resource_type (kind);');
|
||||
$this->addSql('CREATE UNIQUE INDEX charge_kind_unique_type_idx ON chill_budget.charge_type (kind);');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX resource_kind_unique_type_idx');
|
||||
$this->addSql('DROP INDEX charge_kind_unique_type_idx');
|
||||
}
|
||||
}
|
@ -77,6 +77,13 @@ The balance: Différence entre ressources et charges
|
||||
Valid since %startDate% until %endDate%: Valide depuis le %startDate% jusqu'au %endDate%
|
||||
Valid since %startDate%: Valide depuis le %startDate%
|
||||
|
||||
budget:
|
||||
admin:
|
||||
form:
|
||||
Charge_kind_key: Clé d'identification
|
||||
Resource_kind_key: Clé d'identification
|
||||
This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document: Cette clé sert à identifier le type de charge ou de revenu lors de la génération de document. Seuls les caractères alpha-numériques sont autorisés. Modifier cette clé peut avoir un effet lors de la génération de nouveaux documents.
|
||||
|
||||
# ROLES
|
||||
Budget elements: Budget
|
||||
CHILL_BUDGET_ELEMENT_CREATE: Créer une ressource/charge
|
||||
|
@ -1,2 +1,8 @@
|
||||
The amount cannot be empty: Le montant ne peut pas être vide ou égal à zéro
|
||||
The budget element's end date must be after the start date: La date de fin doit être après la date de début
|
||||
|
||||
budget:
|
||||
admin:
|
||||
form:
|
||||
kind:
|
||||
only_alphanumeric
|
||||
|
Loading…
x
Reference in New Issue
Block a user