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