Fix: optimize code

New: add update sql files treatment
This commit is contained in:
Regis Houssin 2011-06-08 13:40:44 +00:00
parent 27f19fd577
commit 67a1212d77

View File

@ -502,48 +502,40 @@ class DolibarrModules
$dir = $dirroot.$reldir; $dir = $dirroot.$reldir;
$ok = 0; $ok = 0;
// Run llx_mytable.sql files
$handle=@opendir($dir); // Dir may not exists $handle=@opendir($dir); // Dir may not exists
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
// Run llx_mytable.sql files
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data')
{ {
$result=run_sql($dir.$file,1,'',1); $result=run_sql($dir.$file,1,'',1);
if ($result <= 0) $error++; if ($result <= 0) $error++;
} }
}
closedir($handle); // Run llx_mytable.key.sql files
} else if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data')
{
// Run llx_mytable.key.sql files $result=run_sql($dir.$file,1,'',1);
$handle=@opendir($dir); // Dir may not exist if ($result <= 0) $error++;
if (is_resource($handle)) }
{
while (($file = readdir($handle))!==false) // Run data_xxx.sql files
{ else if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data')
if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') {
{ $result=run_sql($dir.$file,1,'',1);
$result=run_sql($dir.$file,1,'',1); if ($result <= 0) $error++;
if ($result <= 0) $error++; }
}
} // Run update_xxx.sql files
closedir($handle); else if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,6) == 'update')
}
// Run data_xxx.sql files
$handle=@opendir($dir); // Dir may not exist
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data')
{ {
$result=run_sql($dir.$file,1,'',1); $result=run_sql($dir.$file,1,'',1);
if ($result <= 0) $error++; if ($result <= 0) $error++;
} }
} }
closedir($handle); closedir($handle);
} }