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>';
$sql ="SELECT DISTINCT name";
$sql.=" FROM ".MAIN_DB_PREFIX."const as c";
$sql.=" WHERE name LIKE 'MAIN_MODULE_%_HOOKS'";
$sql.=" ORDER BY name";
$arraylistofkey=array('hooks','js','css');
$resql = $db->query($sql);
if ($resql)
foreach($arraylistofkey as $key)
{
$num = $db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$obj=$db->fetch_object($resql);
$majname = $obj->name;
$sql ="SELECT DISTINCT name, value";
$sql.=" FROM ".MAIN_DB_PREFIX."const as c";
$sql.=" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($key)."'";
$sql.=" ORDER BY name";
print '<tr><td>';
print $majname;
$resql = $db->query($sql);
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))
{
$name=strtolower($reg[1]);
$db->begin();
if ($name)
{
$reloffile=$name.'/class/actions_'.$name.'.class.php';
$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 (preg_match('/MAIN_MODULE_(.*)_'.strtoupper($key).'/i', $constantname, $reg))
{
$name=strtolower($reg[1]);
if (!$error) $db->commit();
else $db->rollback();
}
if ($name) // And entry for key $key and module $name was found in database.
{
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++;
}
}
else
{
print '<tr><td>No active module with missing files found</td></tr>';
}
print'</td></tr>';
if ($error) break;
$i++;
}
}
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);
}
}