Simplify config

This commit is contained in:
Michael RICOIS 2016-11-23 15:53:15 +01:00
parent 1ae25f9a5f
commit a3369f5191
3 changed files with 59 additions and 77 deletions

View File

View File

@ -1,3 +0,0 @@
<?php
require_once realpath(dirname(__FILE__)).'/mysql.php';
require_once realpath(dirname(__FILE__)).'/stockage.php';

View File

@ -264,28 +264,43 @@ $tabDico = array(
),
);
//MetadataCache pour la base de données
if (ini_get('apc.enable_cli')) {
$frontendOptions = array(
'lifetime' => 14400,
'automatic_serialization' => true
);
$backendOptions = array();
$cache = Zend_Cache::factory('Core','Apc', $frontendOptions, $backendOptions);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
}
//Définition bdd local
$config = new Zend_Config($application->getOptions());
Zend_Registry::set('config', $config);
try {
$db = Zend_Db::factory($config->resources->db);
$dbJo = Zend_Db::factory($config->profil->db->jo);
Zend_Db_Table::setDefaultAdapter($dbJo);
$dbMetier = Zend_Db::factory($config->profil->db->metier);
Zend_Db_Table::setDefaultAdapter($dbMetier);
} catch ( Exception $e ) {
exit ( $e->getMessage() );
}
// Doctrine conn
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => $c->profil->db->metier->params->dbname,
'user' => $c->profil->db->metier->params->username,
'password' => $c->profil->db->metier->params->password,
'host' => $c->profil->db->metier->params->host,
'charset' => 'utf8',
'driver' => 'pdo_mysql',
);
try {
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
} catch (\Doctrine\DBAL\DBALException $e) {
if (APPLICATION_ENV == 'development') {
echo '<pre>'; print_r($e); echo '</pre>';
} else {
echo "Le service rencontre actuellement un problème technique.";
}
exit;
}
Zend_Registry::set('doctrine', $conn);
//Chargement des classes metier
require_once APPLICATION_PATH.'/configs/config.php';
if ($opts->id) {
$commandesM = new Application_Model_Commandes($db);
$commande = $commandesM->find(intval($opts->id))->current();
@ -310,32 +325,14 @@ if ($opts->id) {
if ($profil->doublon!='') {
$profilDoublon = json_decode($profil->doublon, true);
}
} else {
}
else {
$profilDoublon = null;
if ($opts->doublon && $opts->doublon!='') {
$profilDoublon = explode(' ', $opts->doublon);
}
}
//Chargement des classes metier
require_once APPLICATION_PATH.'/configs/config.php';
//Définition bdd metier
$dbConfig = array(
'host' => MYSQL_HOST,
'port' => MYSQL_PORT,
'username' => MYSQL_USER,
'password' => MYSQL_PASS,
'dbname' => MYSQL_DEFAULT_DB,
'persistent' => true,
'driver_options' => array(MYSQLI_INIT_COMMAND => 'SET NAMES UTF8;'),
);
try {
$dbMetier = Zend_Db::factory('Mysqli', $dbConfig);
} catch ( Exception $e ) {
exit ( $e->getMessage() );
}
$tabExtract = array();
$tabEntete = array();
$tabIdentifiant = array();
@ -457,81 +454,69 @@ $rowTotal = $nbIdentifiant;
$dico = new Scores_Extract_Dict();
//Liste des champs SQL
foreach($tabExtract as $i => $key)
{
foreach($tabExtract as $i => $key) {
$strKey = false;
//Détection element(VAL1,VAL2)
$values = false;
if (preg_match('/(.*)\((.*)\)/', $key, $matches))
{
if (preg_match('/(.*)\((.*)\)/', $key, $matches)) {
$key = $matches[1];
$values = $matches[2];
}
//Traitement spécial pour le champs, ajout et remplacement sur entete
if (function_exists($key.'Entete')){
if (function_exists($key.'Entete')) {
$keys = call_user_func($key.'Entete', $values);
foreach($keys as $item){
$tabEntete[] = $item;
}
}
//Traitement pour les clé BDD
} else {
else {
//Add original key
$tabEntete[] = $key;
}
//Ajout à la requete SQL
foreach($tabDico as $element => $select)
{
if ( array_key_exists('db', $select) && array_key_exists($key, $select['cle']) )
{
foreach($tabDico as $element => $select) {
if ( array_key_exists('db', $select) && array_key_exists($key, $select['cle']) ) {
$elementsup = $select['cle'][$key];
if ( is_array($elementsup) && array_key_exists('table', $elementsup) ) {
//Specify supplemental head
$tabEntete[] = $key.'Lib';
//Load generic table - always return array('code', 'label')
if ( is_array($elementsup['table']) ) {
${'tab'.ucfirst($key)} = $elementsup['table'];
} else {
}
else {
$stmt = $dbMetier->query($elementsup['table']);
${'tab'.ucfirst($key)} = $stmt->fetchAll();
}
if( array_key_exists('sql', $select['cle'][$key]) && $select['cle'][$key]['sql']!='' ) {
$strKey = $select['cle'][$key]['sql'];
}
} elseif ( $select['cle'][$key]!='' ) {
}
elseif ( $select['cle'][$key]!='' ) {
$strKey = $select['cle'][$key];
}
//If string exist add supplemental fields for the sql request
if (isset(${$element.'Fields'})){ ${$element.'Fields'}.= ', '; }
if (isset(${$element.'Fields'})) {
${$element.'Fields'}.= ', ';
}
if ($strKey!==false){
${$element.'Fields'}.= $strKey;
} else {
}
else {
${$element.'Fields'}.= $key;
}
break;
}
if ( in_array($element, array('data', 'multiple')) && in_array($key, $select) )
{
if ( in_array($element, array('data', 'multiple')) && in_array($key, $select) ) {
${$key.'Data'} = $values;
if ( $values ) {
$tabExtract[$i] = $key;
@ -1603,8 +1588,8 @@ function LienHeadEntete()
function LienHeadData($siren, $nic, $values)
{
global $dbJo;
$c = new Metier_Liens_Base($siren, 'siren', $dbJo);
global $dbMetier;
$c = new Metier_Liens_Base($siren, 'siren', $dbMetier);
$c->stopAtFirstIsin = true;
$id = $c->getHead();
$result = $c->getIdentity($id);
@ -1643,8 +1628,8 @@ function LienHeadUltimateEntete()
function LienHeadUltimateData($siren, $nic, $values)
{
global $dbJo;
$c = new Metier_Liens_Base($siren, 'siren', $dbJo);
global $dbMetier;
$c = new Metier_Liens_Base($siren, 'siren', $dbMetier);
$c->stopAtPP = false;
$id = $c->getHead();
$result = $c->getIdentity($id);
@ -1791,8 +1776,8 @@ function actionnairesEntete()
function actionnairesMultiple($siren, $nic)
{
global $dbJo;
$liensM = new Metier_Liens_Base($siren, 'siren', $dbJo);
global $dbMetier;
$liensM = new Metier_Liens_Base($siren, 'siren', $dbMetier);
$result = $liensM->getActionnaires(null, true);
$tabData = array();
if (count($result)>0) {
@ -1879,8 +1864,8 @@ function participationsEntete()
function participationsMultiple($siren, $nic)
{
global $dbJo;
$liensM = new Metier_Liens_Base($siren, 'siren', $dbJo);
global $dbMetier;
$liensM = new Metier_Liens_Base($siren, 'siren', $dbMetier);
$result = $liensM->getParticipations(null,true);
$tabData = array();
if (count($result)>0) {
@ -1982,9 +1967,9 @@ function groupesEntete()
}
function groupesMultiple($siren, $nic, $values = false)
{
global $dbJo;
global $dbMetier;
$tabData = array();
$c = new Metier_Liens_Base($siren, 'siren', $dbJo);
$c = new Metier_Liens_Base($siren, 'siren', $dbMetier);
$identity = $c->getIdentity();
$level = 0;
@ -2016,10 +2001,10 @@ function groupesMultiple($siren, $nic, $values = false)
}
function groupesMultipleById($id, $values = false)
{
global $dbJo;
global $dbMetier;
$tabData = array();
$c = new Metier_Liens_Base($id, 'ref', $dbJo);
$c = new Metier_Liens_Base($id, 'ref', $dbMetier);
$identity = $c->getIdentity();
$level = 0;