Better mode to clean not corrctly removed modules.

This commit is contained in:
Laurent Destailleur 2017-08-20 19:27:12 +02:00
parent 188653a85d
commit b1121f9f61

View File

@ -802,90 +802,108 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha'))
{ {
print '<tr><td colspan="2"><br>*** Force modules not found to be disabled</td></tr>'; print '<tr><td colspan="2"><br>*** Force modules not found to be disabled</td></tr>';
$sql ="SELECT DISTINCT name"; $arraylistofkey=array('hooks','js','css');
$sql.=" FROM ".MAIN_DB_PREFIX."const as c";
$sql.=" WHERE name LIKE 'MAIN_MODULE_%_HOOKS'";
$sql.=" ORDER BY name";
$resql = $db->query($sql); foreach($arraylistofkey as $key)
if ($resql)
{ {
$num = $db->num_rows($resql); $sql ="SELECT DISTINCT name, value";
if ($num) $sql.=" FROM ".MAIN_DB_PREFIX."const as c";
{ $sql.=" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($key)."'";
$i = 0; $sql.=" ORDER BY name";
while ($i < $num)
{
$obj=$db->fetch_object($resql);
$majname = $obj->name;
print '<tr><td>'; $resql = $db->query($sql);
print $majname; if ($resql)
{
$num = $db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$obj=$db->fetch_object($resql);
$constantname = $obj->name; // Name of constant for hook or js or css declaration
$db->begin(); print '<tr><td>';
print $constantname;
if (preg_match('/MAIN_MODULE_(.*)_HOOKS/i', $majname, $reg)) $db->begin();
{
$name=strtolower($reg[1]);
if ($name) if (preg_match('/MAIN_MODULE_(.*)_'.strtoupper($key).'/i', $constantname, $reg))
{ {
$reloffile=$name.'/class/actions_'.$name.'.class.php'; $name=strtolower($reg[1]);
$result = dol_include_once($reloffile);
if (! $result)
{
print ' - File of hooks ('.$reloffile.') NOT found, we disable the module.';
if (GETPOST('force_disable_of_modules_not_found') == 'confirmed')
{
$sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."_HOOKS'";
$resql2=$db->query($sql2);
if (! $resql2)
{
$error++;
dol_print_error($db);
}
$sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."'";
$resql2=$db->query($sql2);
if (! $resql2)
{
$error++;
dol_print_error($db);
}
else
print " - Cleaned";
}
else
{
print ' - Canceled (test mode)';
}
}
else
{
print ' - File of hooks ('.$reloffile.') found, we do nothing.';
}
}
if (!$error) $db->commit(); if ($name) // And entry for key $key and module $name was found in database.
else $db->rollback(); {
} if ($key == 'hooks') $reloffile=$name.'/class/actions_'.$name.'.class.php';
if ($key == 'js')
{
$value=$obj->value;
$valuearray=json_decode($value);
$reloffile=$valuearray[0];
$reloffile=preg_replace('/^\//','',$valuearray[0]);
}
if ($key == 'css')
{
$value=$obj->value;
$valuearray=json_decode($value);
$reloffile=preg_replace('/^\//','',$valuearray[0]);
}
print'</td></tr>'; $result = dol_include_once($reloffile);
if (! $result)
{
print ' - File of '.$key.' ('.$reloffile.') NOT found, we disable the module.';
if (GETPOST('force_disable_of_modules_not_found') == 'confirmed')
{
$sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."_".strtoupper($key)."'";
$resql2=$db->query($sql2);
if (! $resql2)
{
$error++;
dol_print_error($db);
}
$sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."'";
$resql2=$db->query($sql2);
if (! $resql2)
{
$error++;
dol_print_error($db);
}
else
print " - Cleaned";
}
else
{
print ' - Canceled (test mode)';
}
}
else
{
print ' - File of '.$key.' ('.$reloffile.') found, we do nothing.';
}
}
if ($error) break; if (!$error) $db->commit();
else $db->rollback();
}
$i++; print'</td></tr>';
}
} if ($error) break;
else
{ $i++;
print '<tr><td>No active module with missing files found</td></tr>'; }
} }
else
{
print '<tr><td>No active module with missing files found by searching on MAIN_MODULE_(.*)_'.strtoupper($key).'</td></tr>';
}
}
else
{
dol_print_error($db);
}
} }
else
{
dol_print_error($db);
}
} }