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,9 +802,13 @@ 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');
foreach($arraylistofkey as $key)
{
$sql ="SELECT DISTINCT name, value";
$sql.=" FROM ".MAIN_DB_PREFIX."const as c"; $sql.=" FROM ".MAIN_DB_PREFIX."const as c";
$sql.=" WHERE name LIKE 'MAIN_MODULE_%_HOOKS'"; $sql.=" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($key)."'";
$sql.=" ORDER BY name"; $sql.=" ORDER BY name";
$resql = $db->query($sql); $resql = $db->query($sql);
@ -817,27 +821,41 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha'))
while ($i < $num) while ($i < $num)
{ {
$obj=$db->fetch_object($resql); $obj=$db->fetch_object($resql);
$majname = $obj->name; $constantname = $obj->name; // Name of constant for hook or js or css declaration
print '<tr><td>'; print '<tr><td>';
print $majname; print $constantname;
$db->begin(); $db->begin();
if (preg_match('/MAIN_MODULE_(.*)_HOOKS/i', $majname, $reg)) if (preg_match('/MAIN_MODULE_(.*)_'.strtoupper($key).'/i', $constantname, $reg))
{ {
$name=strtolower($reg[1]); $name=strtolower($reg[1]);
if ($name) if ($name) // And entry for key $key and module $name was found in database.
{ {
$reloffile=$name.'/class/actions_'.$name.'.class.php'; 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]);
}
$result = dol_include_once($reloffile); $result = dol_include_once($reloffile);
if (! $result) if (! $result)
{ {
print ' - File of hooks ('.$reloffile.') NOT found, we disable the module.'; print ' - File of '.$key.' ('.$reloffile.') NOT found, we disable the module.';
if (GETPOST('force_disable_of_modules_not_found') == 'confirmed') if (GETPOST('force_disable_of_modules_not_found') == 'confirmed')
{ {
$sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."_HOOKS'"; $sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = 'MAIN_MODULE_".strtoupper($name)."_".strtoupper($key)."'";
$resql2=$db->query($sql2); $resql2=$db->query($sql2);
if (! $resql2) if (! $resql2)
{ {
@ -861,7 +879,7 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha'))
} }
else else
{ {
print ' - File of hooks ('.$reloffile.') found, we do nothing.'; print ' - File of '.$key.' ('.$reloffile.') found, we do nothing.';
} }
} }
@ -878,14 +896,14 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha'))
} }
else else
{ {
print '<tr><td>No active module with missing files found</td></tr>'; print '<tr><td>No active module with missing files found by searching on MAIN_MODULE_(.*)_'.strtoupper($key).'</td></tr>';
} }
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
}
} }