diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d73d14e6..9182729d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,9 +66,12 @@ jobs: restore-keys: | ${{ runner.os }}-composer- - - name: CS fixer prerequisites + - name: Config file run: make configs/application/config.php + - name: Parameters file + run: make app/config/parameters.yml + - name: Composer install run: composer install --no-scripts diff --git a/Makefile b/Makefile index 46616855c..6695dd115 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ hooks: .git/hooks/pre-commit .git/hooks/post-checkout reset-db: echo 'DROP DATABASE IF EXISTS web' | $(DOCKER_COMPOSE_BIN) run -T --rm db /opt/mysql_no_db - echo 'CREATE DATABASE web' | $(DOCKER_COMPOSE_BIN) -T --rm db /opt/mysql_no_db + echo 'CREATE DATABASE web' | $(DOCKER_COMPOSE_BIN) run -T --rm db /opt/mysql_no_db db-migrations: php bin/phinx migrate diff --git a/configs/application/config-test.php b/configs/application/config-test.php index ca509720e..8d8fc04cc 100644 --- a/configs/application/config-test.php +++ b/configs/application/config-test.php @@ -1,8 +1,4 @@ assign('chemin_javascript', $serveur.$conf->obtenir('web|path').'javascript/'); // Initialisation de la couche d'abstraction de la base de données -$bdd = new \Afup\Site\Utils\Base_De_Donnees($conf->obtenir('bdd|hote'), - $conf->obtenir('bdd|base'), - $conf->obtenir('bdd|utilisateur'), - $conf->obtenir('bdd|mot_de_passe')); +$bdd = new \Afup\Site\Corporate\_Site_Base_De_Donnees(); $bdd->executer("SET NAMES 'utf8'"); require_once(dirname(__FILE__) . '/../../sources/Afup/Bootstrap/commonStart.php'); diff --git a/htdocs/pages/administration/configuration.php b/htdocs/pages/administration/configuration.php index d42d5cce3..726a83402 100644 --- a/htdocs/pages/administration/configuration.php +++ b/htdocs/pages/administration/configuration.php @@ -14,12 +14,6 @@ $formulaire->setDefaults($defaults); -$formulaire->addElement('header', '' , 'Base de données'); -$formulaire->addElement('text' , 'bdd|hote' , 'Hote' , array('size' => 30)); -$formulaire->addElement('text' , 'bdd|base' , 'Base' , array('size' => 30)); -$formulaire->addElement('text' , 'bdd|utilisateur' , 'Utilisateur' , array('size' => 30)); -$formulaire->addElement('text' , 'bdd|mot_de_passe', 'Mot de passe' , array('size' => 30)); - $formulaire->addElement('header' , '' , 'Mails'); $formulaire->addElement('text' , 'mails|email_expediteur' , 'Email expediteur' , array('size' => 30)); $formulaire->addElement('text' , 'mails|nom_expediteur' , 'Nom expediteur' , array('size' => 30)); @@ -55,10 +49,6 @@ $formulaire->addElement('header', 'boutons' , ''); $formulaire->addElement('submit', 'soumettre', 'Enregistrer'); -$formulaire->addRule('bdd|hote' , 'Hote manquant' , 'required'); -$formulaire->addRule('bdd|base' , 'Base manquante' , 'required'); -$formulaire->addRule('bdd|utilisateur', 'Utilisateur manquant', 'required'); - if ($formulaire->validate()) { $valeurs = $formulaire->exportValues(); $conf->importer($valeurs); diff --git a/sources/Afup/Bootstrap/_Common.php b/sources/Afup/Bootstrap/_Common.php index 3e9c15255..42d6926c7 100644 --- a/sources/Afup/Bootstrap/_Common.php +++ b/sources/Afup/Bootstrap/_Common.php @@ -18,7 +18,7 @@ // racine de l'application (pas du document root !) -use Afup\Site\Utils\Base_De_Donnees; +use Afup\Site\Corporate\_Site_Base_De_Donnees; use Afup\Site\Utils\Configuration; $root = realpath(dirname(__FILE__) . '/../../..'); @@ -67,12 +67,7 @@ // initialisation de la couche d'abstraction de la base de données -$bdd = new Base_De_Donnees( - $conf->obtenir('bdd|hote'), - $conf->obtenir('bdd|base'), - $conf->obtenir('bdd|utilisateur'), - $conf->obtenir('bdd|mot_de_passe') -); +$bdd = new _Site_Base_De_Donnees(); // mets la connexion db dans une 'clé de registre' accessible à tout moment diff --git a/sources/Afup/Bootstrap/commonStart.php b/sources/Afup/Bootstrap/commonStart.php index 645fc96b3..f628be61b 100644 --- a/sources/Afup/Bootstrap/commonStart.php +++ b/sources/Afup/Bootstrap/commonStart.php @@ -150,9 +150,9 @@ 'main' => [ 'namespace' => '\CCMBenchmark\Ting\Driver\Mysqli', 'master' => [ - 'host' => $GLOBALS['AFUP_CONF']->obtenir('bdd|hote'), - 'user' => $GLOBALS['AFUP_CONF']->obtenir('bdd|utilisateur'), - 'password' => $GLOBALS['AFUP_CONF']->obtenir('bdd|mot_de_passe'), + 'host' => $GLOBALS['AFUP_CONF']->obtenir('database_host'), + 'user' => $GLOBALS['AFUP_CONF']->obtenir('database_user'), + 'password' => $GLOBALS['AFUP_CONF']->obtenir('database_password'), 'port' => 3306, ] ] @@ -163,7 +163,7 @@ ->batchLoadMetadata( 'AppBundle\Event\Model\Repository', __DIR__ . '/../Event/Model/Repository/*.php', - ['default' => ['database' => $GLOBALS['AFUP_CONF']->obtenir('bdd|base')]] + ['default' => ['database' => $GLOBALS['AFUP_CONF']->obtenir('database_name')]] ) ; $services->set('security.csrf.token_manager', function(){ diff --git a/sources/Afup/Comptabilite/Facture.php b/sources/Afup/Comptabilite/Facture.php index 451f11297..74e8b2123 100644 --- a/sources/Afup/Comptabilite/Facture.php +++ b/sources/Afup/Comptabilite/Facture.php @@ -438,6 +438,9 @@ function genererDevis($reference, $chemin = null) $x += 20; $pdf->SetXY($x, $y); $pdf->MultiCell(20, 5, utf8_decode($detail['tva'] . '%'), 'T', 'C', "C"); + if (!isset($vatAmounts[$detail['tva']])) { + $vatAmounts[$detail['tva']] = 0; + } $vatAmounts[$detail['tva']] += ($detail['tva'] / 100) * $montantTtc; $montantTtc = $montantTtc * (1 + ($detail['tva'] / 100)); @@ -636,6 +639,9 @@ function genererFacture($reference, $chemin = null) $x += 20; $pdf->SetXY($x, $y); $pdf->MultiCell(20, 5, utf8_decode($detail['tva'] . '%'), 'T', 'C', "C"); + if (!isset($vatAmounts[$detail['tva']])) { + $vatAmounts[$detail['tva']] = 0; + } $vatAmounts[$detail['tva']] += ($detail['tva'] / 100) * $montantTtc; $montantTtc = $montantTtc * (1 + ($detail['tva'] / 100)); } diff --git a/sources/Afup/Corporate/_Site_Base_De_Donnees.php b/sources/Afup/Corporate/_Site_Base_De_Donnees.php index 032d504c3..a97547802 100644 --- a/sources/Afup/Corporate/_Site_Base_De_Donnees.php +++ b/sources/Afup/Corporate/_Site_Base_De_Donnees.php @@ -12,10 +12,10 @@ function __construct() * @var Configuration $conf */ $conf = $GLOBALS['AFUP_CONF']; - parent::__construct($conf->obtenir('bdd|hote'), - $conf->obtenir('bdd|base'), - $conf->obtenir('bdd|utilisateur'), - $conf->obtenir('bdd|mot_de_passe')); + parent::__construct($conf->obtenir('database_host'), + $conf->obtenir('database_name'), + $conf->obtenir('database_user'), + $conf->obtenir('database_password')); } } diff --git a/sources/Afup/Utils/Configuration.php b/sources/Afup/Utils/Configuration.php index 47fe94b57..9a896a557 100644 --- a/sources/Afup/Utils/Configuration.php +++ b/sources/Afup/Utils/Configuration.php @@ -1,6 +1,9 @@ _chemin_fichier = $chemin_fichier; $this->_valeurs = include($this->_chemin_fichier); + + $sfParameters = $this->loadSymfonyParameters(); + if ([] !== $sfParameters) { + $this->_valeurs['database_host'] = $sfParameters['database_host']; + $this->_valeurs['database_name'] = $sfParameters['database_name']; + $this->_valeurs['database_user'] = $sfParameters['database_user']; + $this->_valeurs['database_password'] = $sfParameters['database_password']; + } + } + + private function loadSymfonyParameters() + { + $basePath = dirname(__FILE__) . '/../../../app/config'; + + $parameters = []; + $this->mergeSymfonyParametersFromFile($basePath . '/parameters.yml', $parameters); + $this->mergeSymfonyParametersFromFile($basePath . '/config.yml', $parameters); + if (isset($_ENV['SYMFONY_ENV'])) { + $this->mergeSymfonyParametersFromFile($basePath . '/config_' . $_ENV['SYMFONY_ENV'] . '.yml', $parameters); + } + + return $parameters; + } + + private function mergeSymfonyParametersFromFile($file, &$parameters) + { + if (is_file($file)) { + $values = Yaml::parseFile($file); + if (isset($values['parameters'])) { + $parameters = array_merge($parameters, $values['parameters']); + } + } } /** diff --git a/sources/Afup/Utils/SymfonyKernel.php b/sources/Afup/Utils/SymfonyKernel.php index ef958771d..ff30b605b 100644 --- a/sources/Afup/Utils/SymfonyKernel.php +++ b/sources/Afup/Utils/SymfonyKernel.php @@ -21,9 +21,7 @@ public function __construct(Request $request = null) $env = 'prod'; $debug = false; - $configuration = $this->getLegacyConfig(); - - if ($configuration['divers']['afficher_erreurs']) { + if (isset($_ENV['SYMFONY_ENV']) && $_ENV['SYMFONY_ENV'] == 'dev') { Debug::enable(E_WARNING); $debug = true; $env = 'dev'; @@ -41,12 +39,6 @@ public function __construct(Request $request = null) $this->request = $request; } - private function getLegacyConfig() - { - // $configuration comes from this file - return include(__DIR__ . '/../../../configs/application/config.php'); - } - /** * @param string $uri * @return void