mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-15 05:51:28 +01:00
Fix: On cre les fonctions si le fichier functions.sql existe
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
@@ -20,6 +20,7 @@
|
||||
* $Source$
|
||||
*
|
||||
*/
|
||||
|
||||
include_once("./inc.php");
|
||||
|
||||
$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:$langcode);
|
||||
@@ -74,10 +75,7 @@ if ($_POST["action"] == "set")
|
||||
{
|
||||
print "<tr><td>Erreur lors de la cr<63>ation de : $dolibarr_main_db_name</td><td>".$langs->trans("Error")."</td></tr>";
|
||||
}
|
||||
/***************************************************************************************
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
if($db->database_selected == 1)
|
||||
@@ -90,27 +88,93 @@ if ($_POST["action"] == "set")
|
||||
$ok = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
*
|
||||
* Chargement fichiers tables/*.sql (non *.key.sql)
|
||||
* A faire avant les fichiers *.key.sql
|
||||
*
|
||||
*/
|
||||
***************************************************************************************/
|
||||
if ($ok)
|
||||
{
|
||||
$ok = 0;
|
||||
if ($choix == 1)
|
||||
{
|
||||
$dir = "../../mysql/tables/";
|
||||
}
|
||||
else
|
||||
{
|
||||
$dir = "../../pgsql/tables/";
|
||||
}
|
||||
if ($choix==1) $dir = "../../mysql/tables/";
|
||||
else $dir = "../../pgsql/tables/";
|
||||
|
||||
$ok = 0;
|
||||
$handle=opendir($dir);
|
||||
$table_exists = 0;
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, - 8) <> '.key.sql')
|
||||
if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, -8) <> '.key.sql')
|
||||
{
|
||||
$name = substr($file, 0, strlen($file) - 4);
|
||||
$buffer = '';
|
||||
$fp = fopen($dir.$file,"r");
|
||||
if ($fp)
|
||||
{
|
||||
while (!feof ($fp))
|
||||
{
|
||||
$buf = fgets($fp, 4096);
|
||||
if (substr($buf, 0, 2) <> '--')
|
||||
{
|
||||
$buffer .= $buf;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
//print "<tr><td>Cr<43>ation de la table $name/td>";
|
||||
|
||||
if ($db->query($buffer))
|
||||
{
|
||||
//print "<td>OK requete ==== $buffer</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($db->errno() == DB_ERROR_TABLE_ALREADY_EXISTS)
|
||||
{
|
||||
//print "<td>D<>j<EFBFBD> existante</td></tr>";
|
||||
$table_exists = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey",$name)."</td>";
|
||||
print "<td>".$langs->trans("Error")." ".$db->errno()." ".$db->error()."</td></tr>";
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
if ($error == 0)
|
||||
{
|
||||
print '<tr><td>';
|
||||
print $langs->trans("TablesAndPrimaryKeysCreation").'</td><td>'.$langs->trans("OK").'</td></tr>';
|
||||
$ok = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
*
|
||||
* Chargement fichiers tables/*.key.sql
|
||||
* A faire apr<70>s les fichiers *.sql
|
||||
*
|
||||
***************************************************************************************/
|
||||
if ($ok)
|
||||
{
|
||||
if ($choix==1) $dir = "../../mysql/tables/";
|
||||
else $dir = "../../pgsql/tables/";
|
||||
|
||||
$okkeys = 0;
|
||||
$handle=opendir($dir);
|
||||
$table_exists = 0;
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, -8) == '.key.sql')
|
||||
{
|
||||
$name = substr($file, 0, strlen($file) - 4);
|
||||
//print "<tr><td>Cr<43>ation de la table $name</td>";
|
||||
@@ -129,56 +193,139 @@ if ($_POST["action"] == "set")
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
if ($db->query($buffer))
|
||||
// Si plusieurs requetes, on boucle sur chaque
|
||||
$listesql=split(';',$buffer);
|
||||
foreach ($listesql as $buffer) {
|
||||
if (trim($buffer)) {
|
||||
//print "<tr><td>Cr<43>ation des cl<63>s et index de la table $name: '$buffer'</td>";
|
||||
if ($db->query(trim($buffer)))
|
||||
{
|
||||
//print "<td>OK requete ==== $buffer</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($db->errno() == DB_ERROR_TABLE_ALREADY_EXISTS)
|
||||
if ($db->errno() == DB_ERROR_CANNOT_CREATE || eregi('duplicate key name',$db->error()))
|
||||
{
|
||||
//print "<td>D<>j<EFBFBD> existante</td></tr>";
|
||||
$table_exists = 1;
|
||||
$key_exists = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>Cr<43>ation de la table $name</td>";
|
||||
print "<tr><td>".$langs->trans("CreateOtherKeysForTable",$name)."</td>";
|
||||
print "<td>".$langs->trans("Error")." ".$db->errno()." ".$db->error()."</td></tr>";
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//droit sur les tables
|
||||
if ($db->query($grant_query))
|
||||
{
|
||||
print "<tr><td>Grant User '$nom' </td><td>".$langs->trans("OK")."</td></tr>";
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
if ($error == 0)
|
||||
{
|
||||
print '<tr><td>';
|
||||
print $langs->trans("TablesAndPrimaryKeyCreation").'</td><td>'.$langs->trans("OK").'</td></tr>';
|
||||
print $langs->trans("OtherKeysCreation").'</td><td>'.$langs->trans("OK").'</td></tr>';
|
||||
$okkeys = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
*
|
||||
* Positionnement des droits
|
||||
*
|
||||
***************************************************************************************/
|
||||
if ($ok)
|
||||
{
|
||||
// Droits sur les tables
|
||||
if ($grant_query) {
|
||||
if ($db->query($grant_query))
|
||||
{
|
||||
print "<tr><td>Grant User</td><td>".$langs->trans("OK")."</td></tr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
*
|
||||
* Chargement fichier functions.sql
|
||||
*
|
||||
***************************************************************************************/
|
||||
if ($ok)
|
||||
{
|
||||
if ($choix==1) $dir = "../../mysql/functions/";
|
||||
else $dir = "../../pgsql/functions/";
|
||||
|
||||
// Cr<43>ation donn<6E>es
|
||||
$file = "functions.sql";
|
||||
if (file_exists($dir.$file)) {
|
||||
$fp = fopen($dir.$file,"r");
|
||||
if ($fp)
|
||||
{
|
||||
while (!feof ($fp))
|
||||
{
|
||||
$buffer = fgets($fp, 4096);
|
||||
if (substr($buf, 0, 2) <> '--')
|
||||
{
|
||||
$buffer .= $buf;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
// Si plusieurs requetes, on boucle sur chaque
|
||||
$listesql=split('<27>',eregi_replace(";';",";'<27>",$buffer));
|
||||
foreach ($listesql as $buffer) {
|
||||
if (trim($buffer)) {
|
||||
|
||||
if ($db->query(trim($buffer)))
|
||||
{
|
||||
$ok = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||
{
|
||||
// print "<tr><td>Insertion ligne : $buffer</td><td>
|
||||
}
|
||||
else
|
||||
{
|
||||
$ok = 0;
|
||||
print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "<tr><td>".$langs->trans("FunctionsCreation")."</td>";
|
||||
if ($ok)
|
||||
{
|
||||
print "<td>".$langs->trans("OK")."</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<td>".$langs->trans("Error")."</td></tr>";
|
||||
$ok = 1 ;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
*
|
||||
* Chargement fichier data.sql
|
||||
*
|
||||
***************************************************************************************/
|
||||
if ($ok == 1)
|
||||
if ($ok)
|
||||
{
|
||||
//
|
||||
// Donn<6E>es
|
||||
//
|
||||
if ($choix==1)
|
||||
{
|
||||
$dir = "../../mysql/data/";
|
||||
if ($choix==1) $dir = "../../mysql/data/";
|
||||
else $dir = "../../pgsql/data/";
|
||||
|
||||
// Cr<43>ation donn<6E>es
|
||||
$file = "data.sql";
|
||||
$fp = fopen($dir.$file,"r");
|
||||
if ($fp)
|
||||
@@ -209,40 +356,6 @@ if ($_POST["action"] == "set")
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}//choix==1
|
||||
else
|
||||
{
|
||||
$dir = "../../pgsql/data/";
|
||||
$file = "data.sql";
|
||||
$fp = fopen($dir.$file,"r");
|
||||
$buffer='';
|
||||
if ($fp)
|
||||
{
|
||||
while (!feof ($fp))
|
||||
{
|
||||
$buffer .= fgets($fp, 4096);
|
||||
}
|
||||
if ($db->query($buffer))
|
||||
{
|
||||
$ok = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||
{
|
||||
// print "<tr><td>Insertion ligne : $buffer</td><td>D<>ja existante</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$ok = 0;
|
||||
print "Erreur SQL ".$db->errno()." sur requete '$buffer': ".$db->error()."<br>";
|
||||
}
|
||||
}
|
||||
//}//while
|
||||
fclose($fp);
|
||||
}
|
||||
}//else
|
||||
|
||||
|
||||
print "<tr><td>".$langs->trans("ReferenceDataLoading")."</td>";
|
||||
if ($ok)
|
||||
|
||||
@@ -36,4 +36,4 @@ CREATE OR REPLACE FUNCTION FROM_UNIXTIME(BIGINT, VARCHAR)
|
||||
RETURNS TIMESTAMP WITH TIME ZONE
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE STRICT
|
||||
AS 'SELECT TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * interval \'1 second\';';
|
||||
AS 'SELECT TIMESTAMP WITH TIME ZONE \'epoch\' + $1 * interval \'1 second\' ;';
|
||||
Reference in New Issue
Block a user