Skip to content

Commit

Permalink
afup#1416 bdd
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Jan 10, 2024
1 parent 070bc40 commit 07cae4a
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 52 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions configs/application/config-test.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?php
$configuration['bdd']['hote']='dbtest';
$configuration['bdd']['base']='web';
$configuration['bdd']['utilisateur']='afup';
$configuration['bdd']['mot_de_passe']='afup';
$configuration['web']['path']='/';

$configuration['divers']['niveau_erreur']='32767';
Expand Down
4 changes: 0 additions & 4 deletions configs/application/config.php.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?php
$configuration['bdd']['hote']='127.0.0.1';
$configuration['bdd']['base']='afup_dev';
$configuration['bdd']['utilisateur']='afup_dev';
$configuration['bdd']['mot_de_passe']='p455w0rd';
$configuration['web']['path']='http://.dev/';

$configuration['divers']['niveau_erreur']='6143';
Expand Down
4 changes: 0 additions & 4 deletions configs/application/config.php.dist-docker
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?php
$configuration['bdd']['hote']='db';
$configuration['bdd']['base']='web';
$configuration['bdd']['utilisateur']='afup';
$configuration['bdd']['mot_de_passe']='afup';
$configuration['web']['path']='/';

$configuration['divers']['niveau_erreur']='6143';
Expand Down
5 changes: 1 addition & 4 deletions htdocs/include/prepend.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
$smarty->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');
10 changes: 0 additions & 10 deletions htdocs/pages/administration/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions sources/Afup/Bootstrap/_Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__) . '/../../..');
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions sources/Afup/Bootstrap/commonStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
]
Expand All @@ -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(){
Expand Down
6 changes: 6 additions & 0 deletions sources/Afup/Comptabilite/Facture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));
}
Expand Down
8 changes: 4 additions & 4 deletions sources/Afup/Corporate/_Site_Base_De_Donnees.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

}
}
35 changes: 35 additions & 0 deletions sources/Afup/Utils/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace Afup\Site\Utils;

use Symfony\Component\Yaml\Yaml;

define('EURO', '');

/**
Expand Down Expand Up @@ -33,6 +36,38 @@ public function __construct($chemin_fichier)
{
$this->_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']);
}
}
}

/**
Expand Down
10 changes: 1 addition & 9 deletions sources/Afup/Utils/SymfonyKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down

0 comments on commit 07cae4a

Please sign in to comment.