suppression d'un fichier de migration obsolete
la variable $arraysql n'était pas vidée ce qui lancait 2 fois le script 2.0.0-2.1.0.sql lors d'une migration 2.0.0 vers 2.2.0
This commit is contained in:
parent
bf08ab3175
commit
83f548cd18
@ -139,130 +139,132 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
|
|||||||
***************************************************************************************/
|
***************************************************************************************/
|
||||||
if ($ok)
|
if ($ok)
|
||||||
{
|
{
|
||||||
if ($choix==1) $dir = "../../mysql/migration/";
|
if ($choix==1) $dir = "../../mysql/migration/";
|
||||||
else $dir = "../../pgsql/migration/";
|
else $dir = "../../pgsql/migration/";
|
||||||
|
|
||||||
|
$filelist=array();
|
||||||
|
$i = 0;
|
||||||
|
$ok = 0;
|
||||||
|
$from='^'.$versionfrom;
|
||||||
|
$to=$versionto.'\.sql$';
|
||||||
|
|
||||||
$filelist=array();
|
# Recupere list fichier
|
||||||
$i = 0;
|
$filesindir=array();
|
||||||
$ok = 0;
|
$handle=opendir($dir);
|
||||||
$from='^'.$versionfrom;
|
while (($file = readdir($handle))!==false)
|
||||||
$to=$versionto.'\.sql$';
|
{
|
||||||
|
if (eregi('\.sql$',$file)) $filesindir[]=$file;
|
||||||
|
}
|
||||||
|
sort($filesindir);
|
||||||
|
|
||||||
# Recupere list fichier
|
# Determine les fichiers sql a passer
|
||||||
$filesindir=array();
|
foreach($filesindir as $file)
|
||||||
$handle=opendir($dir);
|
|
||||||
while (($file = readdir($handle))!==false)
|
|
||||||
{
|
|
||||||
if (eregi('\.sql$',$file)) $filesindir[]=$file;
|
|
||||||
}
|
|
||||||
sort($filesindir);
|
|
||||||
|
|
||||||
# Determine les fichiers sql a passer
|
|
||||||
foreach($filesindir as $file)
|
|
||||||
{
|
|
||||||
if (eregi($from,$file))
|
|
||||||
{
|
|
||||||
$filelist[]=$file;
|
|
||||||
|
|
||||||
// Mettre from avec valeur fin de $file
|
|
||||||
}
|
|
||||||
else if (eregi($to,$file))
|
|
||||||
{
|
{
|
||||||
$filelist[]=$file;
|
if (eregi($from,$file))
|
||||||
|
{
|
||||||
|
$filelist[]=$file;
|
||||||
|
|
||||||
|
// Mettre from avec valeur fin de $file
|
||||||
|
}
|
||||||
|
else if (eregi($to,$file))
|
||||||
|
{
|
||||||
|
$filelist[]=$file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# Boucle sur chaque fichier
|
# Boucle sur chaque fichier
|
||||||
foreach($filelist as $file)
|
foreach($filelist as $file)
|
||||||
{
|
{
|
||||||
print '<tr><td nowrap>';
|
print '<tr><td nowrap>';
|
||||||
print $langs->trans("ChoosedMigrateScript").'</td><td align="right">'.$file.'</td></tr>';
|
print $langs->trans("ChoosedMigrateScript").'</td><td align="right">'.$file.'</td></tr>';
|
||||||
|
|
||||||
$name = substr($file, 0, strlen($file) - 4);
|
$name = substr($file, 0, strlen($file) - 4);
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
$fp = fopen($dir.$file,"r");
|
$arraysql = Array();
|
||||||
if ($fp)
|
$fp = fopen($dir.$file,"r");
|
||||||
{
|
if ($fp)
|
||||||
while (!feof ($fp))
|
{
|
||||||
{
|
while (!feof ($fp))
|
||||||
$buf = fgets($fp, 4096);
|
{
|
||||||
|
$buf = fgets($fp, 4096);
|
||||||
// Cas special de lignes autorisees pour certaines versions uniquement
|
|
||||||
if (eregi('^-- V([0-9\.]+)',$buf,$reg))
|
// Cas special de lignes autorisees pour certaines versions uniquement
|
||||||
{
|
if (eregi('^-- V([0-9\.]+)',$buf,$reg))
|
||||||
$versioncommande=split('\.',$reg[1]);
|
{
|
||||||
|
$versioncommande=split('\.',$reg[1]);
|
||||||
//print var_dump($versioncommande);
|
//print var_dump($versioncommande);
|
||||||
//print var_dump($versionarray);
|
//print var_dump($versionarray);
|
||||||
if (sizeof($versioncommande) && sizeof($versionarray)
|
if (sizeof($versioncommande) && sizeof($versionarray)
|
||||||
&& versioncompare($versioncommande,$versionarray) <= 0)
|
&& versioncompare($versioncommande,$versionarray) <= 0)
|
||||||
{
|
{
|
||||||
// Version qualified, delete SQL comments
|
// Version qualified, delete SQL comments
|
||||||
$buf=eregi_replace('^-- V([0-9\.]+)','',$buf);
|
$buf=eregi_replace('^-- V([0-9\.]+)','',$buf);
|
||||||
//print "Ligne $i qualifiée par version: ".$buf.'<br>';
|
//print "Ligne $i qualifiée par version: ".$buf.'<br>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajout ligne si non commentaire
|
||||||
|
if (! eregi('^--',$buf)) $buffer .= $buf;
|
||||||
|
|
||||||
// Ajout ligne si non commentaire
|
// print $buf.'<br>';
|
||||||
if (! eregi('^--',$buf)) $buffer .= $buf;
|
|
||||||
|
|
||||||
// print $buf.'<br>';
|
if (eregi(';',$buffer))
|
||||||
|
{
|
||||||
if (eregi(';',$buffer))
|
// Found new request
|
||||||
{
|
$arraysql[$i]=trim($buffer);
|
||||||
// Found new request
|
$i++;
|
||||||
$arraysql[$i]=trim($buffer);
|
$buffer='';
|
||||||
$i++;
|
}
|
||||||
$buffer='';
|
}
|
||||||
}
|
|
||||||
}
|
if ($buffer) $arraysql[$i]=trim($buffer);
|
||||||
if ($buffer) $arraysql[$i]=trim($buffer);
|
fclose($fp);
|
||||||
fclose($fp);
|
}
|
||||||
}
|
|
||||||
|
// Loop on each request
|
||||||
// Loop on each request
|
foreach($arraysql as $i=>$sql)
|
||||||
foreach($arraysql as $i=>$sql)
|
{
|
||||||
{
|
if ($sql)
|
||||||
if ($sql)
|
|
||||||
{
|
{
|
||||||
// Ajout trace sur requete (eventuellement à commenter si beaucoup de requetes)
|
// Ajout trace sur requete (eventuellement à commenter si beaucoup de requetes)
|
||||||
print('<tr><td valign="top">'.$langs->trans("Request").' '.($i+1)." sql='".$sql."'</td></tr>\n");
|
print('<tr><td valign="top">'.$langs->trans("Request").' '.($i+1)." sql='".$sql."'</td></tr>\n");
|
||||||
dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." sql='".$sql);
|
dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." sql='".$sql);
|
||||||
|
|
||||||
if ($db->query($sql))
|
if ($db->query($sql))
|
||||||
{
|
{
|
||||||
// print '<td align="right">OK</td>';
|
// print '<td align="right">OK</td>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$errno=$db->errno();
|
$errno=$db->errno();
|
||||||
$okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
|
$okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
|
||||||
'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
||||||
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
||||||
'DB_ERROR_RECORD_ALREADY_EXISTS',
|
'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
'DB_ERROR_NOSUCHTABLE',
|
'DB_ERROR_NOSUCHTABLE',
|
||||||
'DB_ERROR_NOSUCHFIELD',
|
'DB_ERROR_NOSUCHFIELD',
|
||||||
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
|
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
|
||||||
'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
|
'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
|
||||||
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
||||||
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS'
|
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS'
|
||||||
);
|
);
|
||||||
if (in_array($errno,$okerror))
|
if (in_array($errno,$okerror))
|
||||||
{
|
{
|
||||||
// print '<td align="right">'.$langs->trans("OK").'</td>';
|
//print '<td align="right">'.$langs->trans("OK").'</td>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<tr><td valign="top" colspan="2">';
|
print '<tr><td valign="top" colspan="2">';
|
||||||
print '<div class="error">'.$langs->trans("Error")." ".$db->errno().": ".$sql."<br>".$db->error()."</font></td>";
|
print '<div class="error">'.$langs->trans("Error")." ".$db->errno().": ".$sql."<br>".$db->error()."</font></td>";
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." ".$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error());
|
dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." ".$langs->trans("Error")." ".$db->errno()." ".$sql."<br>".$db->error());
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// print '</tr>';
|
// print '</tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error == 0)
|
if ($error == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user