From 2e4f8ee49180c9543ddce37ade9863198095588d Mon Sep 17 00:00:00 2001 From: opensides Date: Wed, 25 Aug 2004 20:12:02 +0000 Subject: [PATCH] premiere version du programme d'installation pour mysql et postgresql --- htdocs/install/etape1.php | 56 +++++++++--- htdocs/install/etape2.php | 167 ++++++++++++++++++++++++------------ htdocs/install/etape4.php | 11 ++- htdocs/install/etape5.php | 10 ++- htdocs/install/fileconf.php | 31 +++++-- htdocs/install/inc.php | 2 + 6 files changed, 202 insertions(+), 75 deletions(-) diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php index dbeb6b4aa7b..1447f096266 100644 --- a/htdocs/install/etape1.php +++ b/htdocs/install/etape1.php @@ -1,6 +1,8 @@ * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien Di Cintio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +23,7 @@ * */ -include_once("../lib/mysql.lib.php"); + include_once("./inc.php"); pHeader("Fichier de configuration","etape2"); @@ -86,7 +88,7 @@ if ($_POST["action"] == "set") fputs($fp, '$dolibarr_main_db_type="'.$_POST["db_type"].'";'); fputs($fp,"\n"); - + fputs($fp, '?>'); fclose($fp); @@ -101,7 +103,19 @@ if ($_POST["action"] == "set") $error = 1; } } - + + if($dolibarr_main_db_type == "mysql") + { + include_once("../lib/mysql.lib.php"); + $choix=1; + } + else + { + include_once("../lib/pgsql.lib.php"); + $choix=2; + } + + /*************************************************************************** * * Creation des répertoires @@ -198,15 +212,19 @@ if ($_POST["action"] == "set") if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on") { dolibarr_syslog ("Creation de l'utilisateur : ".$dolibarr_main_db_user); - + $conf = new Conf(); $conf->db->host = $dolibarr_main_db_host; - $conf->db->name = "mysql"; - $conf->db->user = isset($_POST["db_user_root"])?$_POST["db_user_root"]:""; - $conf->db->pass = isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:""; + $conf->db->name = $dolibarr_main_db_name; + //$conf->db->name = "mysql"; + //$conf->db->user = isset($_POST["db_user_root"])?$_POST["db_user_root"]:""; + //$conf->db->pass = isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:""; + $conf->db->user = "postgres"; + $conf->db->pass = "postgres"; //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass; $db = new DoliDb(); - + if($choix==1) + { $sql = "INSERT INTO user "; $sql .= "(Host,User,password)"; $sql .= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass'))"; @@ -240,6 +258,21 @@ if ($_POST["action"] == "set") } $db->close(); + } //choix==1 + else + { + $nom = $dolibarr_main_db_user; + $con=pg_connect("host=localhost dbname=dolibarr user=postgres"); + $query_str = "create user \"$nom\" with password '".$dolibarr_main_db_pass."';"; + //print $query_str; + $ret = pg_query($con,$query_str); + if ($ret) + print "Création de l'utilisateur:\"$nom\"OK"; + else + print "Création de l'utilisateur:\"$nom\"ERREUR"; + + } + } // Tentative accès serveur et base par le user admin dolibarr @@ -250,7 +283,7 @@ if ($_POST["action"] == "set") $conf->db->user = $dolibarr_main_db_user; $conf->db->pass = $dolibarr_main_db_pass; //print $conf->db->host.",".$conf->db->name.",".$conf->db->user.",".$conf->db->pass; - $db = new DoliDb(); + $db = new DoliDb(); $ok = 1; if ($db->connected == 1) @@ -279,12 +312,15 @@ if ($_POST["action"] == "set") // // Création de la base // + print "Echec de connexion à la base : $dolibarr_main_db_nameWarning"; print 'Création de la base : '.$dolibarr_main_db_name.''; $conf = new Conf(); $conf->db->host = $dolibarr_main_db_host; - $conf->db->name = "mysql"; + //$conf->db->name = "mysql"; + $conf->db->name = $dolibarr_main_db_name; + //$conf->db->user = "seb"; $conf->db->user = isset($_POST["db_user_root"])?$_POST["db_user_root"]:""; $conf->db->pass = isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:""; diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php index 281683cf4c0..f4dedfffa81 100644 --- a/htdocs/install/etape2.php +++ b/htdocs/install/etape2.php @@ -1,6 +1,8 @@ * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien Di Cintio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +32,20 @@ if (file_exists($conf)) { include($conf); } -require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); -require ($dolibarr_main_document_root . "/conf/conf.class.php"); + +if($dolibarr_main_db_type == "mysql") +{ + require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); + $choix=1; +} +else +{ + require ($dolibarr_main_document_root . "/lib/pgsql.lib.php"); + require ($dolibarr_main_document_root . "/lib/grant.postgres.php"); + $choix=2; +} + +require ($dolibarr_main_document_root . "/conf/conf.class.php");// ne sert plus if ($HTTP_POST_VARS["action"] == "set") { @@ -42,7 +56,7 @@ if ($HTTP_POST_VARS["action"] == "set") print 'Test de connexion à la base de données'; - $conf = new Conf(); + $conf = new Conf();// on pourrait s'en passer $conf->db->host = $dolibarr_main_db_host; $conf->db->name = $dolibarr_main_db_name; $conf->db->user = $dolibarr_main_db_user; @@ -66,6 +80,7 @@ if ($HTTP_POST_VARS["action"] == "set") { if($db->database_selected == 1) { + dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); } else @@ -80,17 +95,14 @@ if ($HTTP_POST_VARS["action"] == "set") if ($ok) { $ok = 0; - //$result = $db->list_tables($dolibarr_main_db_name); - //if ($result) - //{ - // while ($row = $db->fetch_row()) - // { - // print "Table : $row[0]
\n"; - // } - //} - - // Création des tables - $dir = "../../mysql/tables/"; + if ($choix == 1) + { + $dir = "../../mysql/tables/"; + } + else + { + $dir = "../../pgsql/tables/"; + } $handle=opendir($dir); $table_exists = 0; @@ -101,7 +113,7 @@ if ($HTTP_POST_VARS["action"] == "set") $name = substr($file, 0, strlen($file) - 4); //print "Création de la table $name"; $buffer = ''; - $fp = fopen($dir.$file,"r"); + $fp = fopen($dir.$file,"r"); if ($fp) { while (!feof ($fp)) @@ -110,10 +122,10 @@ if ($HTTP_POST_VARS["action"] == "set") } fclose($fp); } - - if ($db->query($buffer)) + + if ($db->query($buffer)) { - //print "OK"; + //print "OK requete ==== $buffer"; } else { @@ -132,6 +144,12 @@ if ($HTTP_POST_VARS["action"] == "set") } } + + //droit sur les tables + if ($db->query($grant_query)) + { + print "Grant User '$nom' OK"; + } closedir($handle); if ($error == 0) @@ -151,19 +169,52 @@ if ($HTTP_POST_VARS["action"] == "set") // // Données // - $dir = "../../mysql/data/"; - $file = "data.sql"; - - $fp = fopen($dir.$file,"r"); + if ($choix==1) + { + $dir = "../../mysql/data/"; + $file = "data.sql"; + $fp = fopen($dir.$file,"r"); if ($fp) - { - while (!feof ($fp)) { - $buffer = fgets($fp, 4096); - - if (strlen(trim(ereg_replace("--","",$buffer)))) - { - if ($db->query($buffer)) + while (!feof ($fp)) + { + $buffer = fgets($fp, 4096); + + if (strlen(trim(ereg_replace("--","",$buffer)))) + { + if ($db->query($buffer)) + { + $ok = 1; + } + else + { + if ($db->errno() == 1062) + { + // print "Insertion ligne : $buffer + } + else + { + $ok = 0; + print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."
"; + } + } + } + } + fclose($fp); + } + }//choix==1 + else + { + $dir = "../../pgsql/data/"; + $file = "data.sql"; + $fp = fopen($dir.$file,"r"); + if ($fp) + { + while (!feof ($fp)) + { + $buffer = fgets($fp, 4096); + } + if ($db->query($buffer)) { $ok = 1; } @@ -179,10 +230,11 @@ if ($HTTP_POST_VARS["action"] == "set") print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."
"; } } - } - } - fclose($fp); - } + fclose($fp); + } + }//else + + print "Chargement des données de base"; if ($ok) @@ -205,27 +257,34 @@ if ($HTTP_POST_VARS["action"] == "set") ***************************************************************************************/ if ($ok == 1) { - /* - * - * - */ - $sql[0] = "REPLACE INTO llx_const SET name = 'FAC_OUTPUTDIR', value='".$dolibarr_main_data_root."/facture', visible=0, type='chaine'"; - - $sql[1] = "REPLACE INTO llx_const SET name = 'FAC_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/facture', visible=0, type='chaine'"; - - $sql[2] = "REPLACE INTO llx_const SET name = 'PROPALE_OUTPUTDIR', value='".$dolibarr_main_data_root."/propale', visible=0, type='chaine'"; - - $sql[3] = "REPLACE INTO llx_const SET name = 'PROPALE_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/propale', visible=0, type='chaine'"; - - $sql[4] = "REPLACE INTO llx_const SET name = 'FICHEINTER_OUTPUTDIR', value='".$dolibarr_main_data_root."/ficheinter', visible=0, type='chaine'"; - - $sql[5] = "REPLACE INTO llx_const SET name = 'FICHEINTER_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/ficheinter', visible=0, type='chaine'"; - - $sql[6] = "REPLACE INTO llx_const SET name = 'SOCIETE_OUTPUTDIR', value='".$dolibarr_main_data_root."/societe', visible=0, type='chaine'"; - - $sql[7] = "REPLACE INTO llx_const SET name = 'SOCIETE_OUTPUT_URL', value='".$dolibarr_main_url_root."/document/societe', visible=0, type='chaine'"; - $result = 0; - + + $chem1 = "/facture"; + $sql[0] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/facture' + where name ='FAC_OUTPUTDIR';" ; + + $sql[1] = "UPDATE llx_const SET value = '".$dolibarr_main_data_url."/document/facture' + where name = 'FAC_OUTPUT_URL';" ; + + $sql[2] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/propale' + where name = 'PROPALE_OUTPUTDIR';" ; + + $sql[3] = "UPDATE llx_const SET value = '".$dolibarr_main_url_root."/document/propale' + where name = 'PROPALE_OUTPUT_URL';" ; + + $sql[4] = "UPDATE llx_const SET value = '".$dolibarr_main_data_root."/ficheinter' + where name = 'FICHEINTER_OUTPUTDIR';" ; + + $sql[5] = "UPDATE llx_const SET value='".$dolibarr_main_url_root."/document/ficheinter' + where name = 'FICHEINTER_OUTPUT_URL';" ; + + $sql[6] = "UPDATE llx_const SET value='".$dolibarr_main_data_root."/societe' + where name = 'SOCIETE_OUTPUTDIR';" ; + + $sql[7] = "UPDATE llx_const SET value='".$dolibarr_main_url_root."/document/societe' + where name = 'SOCIETE_OUTPUT_URL';" ; + + $result = 0; + for ($i=0; $i < sizeof($sql);$i++) { if ($db->query($sql[$i])) diff --git a/htdocs/install/etape4.php b/htdocs/install/etape4.php index 7e99c52ba9a..20f4a1ccbb5 100644 --- a/htdocs/install/etape4.php +++ b/htdocs/install/etape4.php @@ -1,5 +1,7 @@ + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien DiCintio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +28,14 @@ if (file_exists($conf)) { include($conf); } -require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); + +if($dolibarr_main_db_type == "mysql") + require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); +else + require ($dolibarr_main_document_root . "/lib/pgsql.lib.php"); + + + require ($dolibarr_main_document_root . "/conf/conf.class.php"); print ''; diff --git a/htdocs/install/etape5.php b/htdocs/install/etape5.php index 4f7a14bd529..141da527e59 100644 --- a/htdocs/install/etape5.php +++ b/htdocs/install/etape5.php @@ -1,6 +1,8 @@ * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien DiCintio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,7 +30,13 @@ if (file_exists($conf)) { include($conf); } -require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); + + +if($dolibarr_main_db_type == "mysql") + require ($dolibarr_main_document_root . "/lib/mysql.lib.php"); +else + require ($dolibarr_main_document_root . "/lib/pgsql.lib.php"); + require ($dolibarr_main_document_root . "/conf/conf.class.php"); if ($HTTP_POST_VARS["action"] == "set") diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index 468e11b8a14..7c15e2195e1 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -2,6 +2,8 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2004 Éric Seigne * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien DiCintio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +28,7 @@ pHeader("Fichier de configuration","etape1"); $conf = "../conf/conf.php"; + if (is_readable($conf)) { include ($conf); @@ -82,8 +85,9 @@ if(! isset($dolibarr_main_url_root) || strlen($dolibarr_main_url_root) == 0) // ce n'est pas ce qu'on veut. Dans ce cas, on propose $_SERVER["DOCUMENT_ROOT"] if (eregi('php$',$_SERVER["SCRIPT_FILENAME"]) || eregi('php\.exe$',$_SERVER["SCRIPT_FILENAME"])) { $dolibarr_main_document_root=$_SERVER["DOCUMENT_ROOT"]; - if (! eregi('\/dolibarr\/htdocs$',$dolibarr_main_document_root)) { - $dolibarr_main_document_root.="/dolibarr/htdocs"; + //print $dolibarr_main_document_root; + if (! eregi('\/dolibarr/htdocs$',$dolibarr_main_document_root)) { + $dolibarr_main_document_root.="dolibarr/htdocs"; } } else { @@ -111,7 +115,8 @@ exemples :
+ + + @@ -178,8 +190,9 @@ $dolibarr_main_db_host = "localhost";
- + + diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 46cb6576418..d6b855038ce 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -1,5 +1,7 @@ + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien DiCintio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
" name="main_data_dir"> @@ -165,12 +170,19 @@ $dolibarr_main_db_host = "localhost"; Choix de la base de données +  - - Nom de la base de donnée qui est soit MySql par défaut ou alors PostgreSql. ServeurNom ou adresse ip du serveur de base de données, généralement 'localhost' quand le serveur est installé sur la même machine que le serveur web