2
0
forked from Wavyzz/dolibarr

FIX #11244 Enhance repair tool

This commit is contained in:
Laurent Destailleur
2019-05-29 12:21:51 +02:00
parent cf70b26db7
commit 05063016e8
2 changed files with 114 additions and 26 deletions

View File

@@ -649,7 +649,7 @@ function dol_include_once($relpath, $classname = '')
* @param int $returnemptyifnotfound 0:If $type==0 and if file was not found into alternate dir, return default path into main dir (no test on it)
* 1:If $type==0 and if file was not found into alternate dir, return empty string
* 2:If $type==0 and if file was not found into alternate dir, test into main dir, return default path if found, empty string if not found
* @return string Full filesystem path (if path=0), Full url path (if mode=1)
* @return string Full filesystem path (if path=0) or '' if file not found, Full url path (if mode=1)
*/
function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
{

View File

@@ -67,17 +67,17 @@ $actiondone=1;
print '<h3>'.$langs->trans("Repair").'</h3>';
print 'Option standard (0 or \'confirmed\') is '.(GETPOST('standard', 'alpha')?GETPOST('standard', 'alpha'):'0').'<br>'."\n";
print 'Option restore_thirdparties_logos (0 or \'confirmed\') is '.(GETPOST('restore_thirdparties_logos', 'alpha')?GETPOST('restore_thirdparties_logos', 'alpha'):'0').'<br>'."\n";
print 'Option clean_linked_elements (0 or \'confirmed\') is '.(GETPOST('clean_linked_elements', 'alpha')?GETPOST('clean_linked_elements', 'alpha'):'0').'<br>'."\n";
print 'Option clean_menus (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_menus', 'alpha')?GETPOST('clean_menus', 'alpha'):'0').'<br>'."\n";
print 'Option clean_orphelin_dir (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir', 'alpha')?GETPOST('clean_orphelin_dir', 'alpha'):'0').'<br>'."\n";
print 'Option clean_product_stock_batch (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_product_stock_batch', 'alpha')?GETPOST('clean_product_stock_batch', 'alpha'):'0').'<br>'."\n";
print 'Option set_empty_time_spent_amount (0 or \'test\' or \'confirmed\') is '.(GETPOST('set_empty_time_spent_amount', 'alpha')?GETPOST('set_empty_time_spent_amount', 'alpha'):'0').'<br>'."\n";
print 'Option rebuild_product_thumbs (0 or \'test\' or \'confirmed\') is '.(GETPOST('rebuild_product_thumbs', 'alpha')?GETPOST('rebuild_product_thumbs', 'alpha'):'0').'<br>'."\n";
print 'Option force_disable_of_modules_not_found (0 or \'test\' or \'confirmed\') is '.(GETPOST('force_disable_of_modules_not_found', 'alpha')?GETPOST('force_disable_of_modules_not_found', 'alpha'):'0').'<br>'."\n";
print 'Option clean_perm_table (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_perm_table', 'alpha')?GETPOST('clean_perm_table', 'alpha'):'0').'<br>'."\n";
print 'Option force_utf8_on_tables, for mysql/mariadb only (0 or \'test\' or \'confirmed\') is '.(GETPOST('force_utf8_on_tables', 'alpha')?GETPOST('force_utf8_on_tables', 'alpha'):'0').'<br>'."\n";
print 'Option standard (\'test\' or \'confirmed\') is '.(GETPOST('standard', 'alpha')?GETPOST('standard', 'alpha'):'undefined').'<br>'."\n";
print 'Option restore_thirdparties_logos (\'test\' or \'confirmed\') is '.(GETPOST('restore_thirdparties_logos', 'alpha')?GETPOST('restore_thirdparties_logos', 'alpha'):'undefined').'<br>'."\n";
print 'Option clean_linked_elements (\'test\' or \'confirmed\') is '.(GETPOST('clean_linked_elements', 'alpha')?GETPOST('clean_linked_elements', 'alpha'):'undefined').'<br>'."\n";
print 'Option clean_menus (\'test\' or \'confirmed\') is '.(GETPOST('clean_menus', 'alpha')?GETPOST('clean_menus', 'alpha'):'undefined').'<br>'."\n";
print 'Option clean_orphelin_dir (\'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir', 'alpha')?GETPOST('clean_orphelin_dir', 'alpha'):'undefined').'<br>'."\n";
print 'Option clean_product_stock_batch (\'test\' or \'confirmed\') is '.(GETPOST('clean_product_stock_batch', 'alpha')?GETPOST('clean_product_stock_batch', 'alpha'):'undefined').'<br>'."\n";
print 'Option set_empty_time_spent_amount (\'test\' or \'confirmed\') is '.(GETPOST('set_empty_time_spent_amount', 'alpha')?GETPOST('set_empty_time_spent_amount', 'alpha'):'undefined').'<br>'."\n";
print 'Option rebuild_product_thumbs (\'test\' or \'confirmed\') is '.(GETPOST('rebuild_product_thumbs', 'alpha')?GETPOST('rebuild_product_thumbs', 'alpha'):'undefined').'<br>'."\n";
print 'Option force_disable_of_modules_not_found (\'test\' or \'confirmed\') is '.(GETPOST('force_disable_of_modules_not_found', 'alpha')?GETPOST('force_disable_of_modules_not_found', 'alpha'):'undefined').'<br>'."\n";
print 'Option clean_perm_table (\'test\' or \'confirmed\') is '.(GETPOST('clean_perm_table', 'alpha')?GETPOST('clean_perm_table', 'alpha'):'undefined').'<br>'."\n";
print 'Option force_utf8_on_tables, for mysql/mariadb only (\'test\' or \'confirmed\') is '.(GETPOST('force_utf8_on_tables', 'alpha')?GETPOST('force_utf8_on_tables', 'alpha'):'undefined').'<br>'."\n";
print '<br>';
print '<table cellspacing="0" cellpadding="1" border="0" width="100%">';
@@ -302,7 +302,11 @@ if ($ok && GETPOST('standard', 'alpha'))
);
//var_dump($field_desc);exit;
$result = 0;
if (GETPOST('standard', 'alpha') == 'confirmed')
{
$result=$db->DDLAddField($tableextra, $code, $field_desc, "");
if ($result < 0)
{
print "KO ".$db->lasterror."<br>\n";
@@ -312,6 +316,11 @@ if ($ok && GETPOST('standard', 'alpha'))
print "OK<br>\n";
}
}
else
{
print ' - Mode test, no column added.';
}
}
}
print "</td><td>&nbsp;</td></tr>\n";
@@ -324,7 +333,6 @@ if ($ok && GETPOST('standard', 'alpha'))
}
// clean_data_ecm_dir: Clean data into ecm_directories table
if ($ok && GETPOST('standard', 'alpha'))
{
@@ -332,7 +340,79 @@ if ($ok && GETPOST('standard', 'alpha'))
}
// clean declaration constants
if ($ok && GETPOST('standard', 'alpha'))
{
print '<tr><td colspan="2"><br>*** Clean module_parts entries of modules not enabled</td></tr>';
$sql ="SELECT name, entity, value";
$sql.=" FROM ".MAIN_DB_PREFIX."const as c";
$sql.=" WHERE name LIKE 'MAIN_MODULE_%_TPL' OR name LIKE 'MAIN_MODULE_%_CSS' OR name LIKE 'MAIN_MODULE_%_JS' OR name LIKE 'MAIN_MODULE_%_HOOKS'";
$sql.=" OR name LIKE 'MAIN_MODULE_%_TRIGGERS' OR name LIKE 'MAIN_MODULE_%_THEME' OR name LIKE 'MAIN_MODULE_%_SUBSTITUTIONS' OR name LIKE 'MAIN_MODULE_%_MODELS'";
$sql.=" OR name LIKE 'MAIN_MODULE_%_MENUS' OR name LIKE 'MAIN_MODULE_%_LOGIN' OR name LIKE 'MAIN_MODULE_%_BARCODE'";
$sql.=" ORDER BY name, entity";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($num)
{
$db->begin();
$i = 0;
while ($i < $num)
{
$obj=$db->fetch_object($resql);
$reg = array();
if (preg_match('/MAIN_MODULE_(.*)_(.*)/i', $obj->name, $reg))
{
$name=$reg[1];
$type=$reg[2];
$sql2 ="SELECT COUNT(*) as nb";
$sql2.=" FROM ".MAIN_DB_PREFIX."const as c";
$sql2.=" WHERE name LIKE 'MAIN_MODULE_".$name."'";
$sql2.=" AND entity = ".$obj->entity;
$resql2 = $db->query($sql2);
if ($resql2)
{
$obj2 = $db->fetch_object($resql2);
if ($obj2 && $obj2->nb == 0)
{
// Module not found, so we canremove entry
$sqldelete = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$db->escape($obj->name)."' AND entity = ".$obj->entity;
if (GETPOST('standard', 'alpha') == 'confirmed')
{
$db->query($sqldelete);
print '<tr><td>Constant '.$obj->name.' set in entity '.$obj->entity.' with value '.$obj->value.' -> Module not enabled in entity '.$obj->entity.', we delete record</td></tr>';
}
else
{
print '<tr><td>Constant '.$obj->name.' set in entity '.$obj->entity.' with value '.$obj->value.' -> Module not enabled in entity '.$obj->entity.', we should delete record (not done, mode test)</td></tr>';
}
}
else
{
//print '<tr><td>Constant '.$obj->name.' set in entity '.$obj->entity.' with value '.$obj->value.' -> Module found in entity '.$obj->entity.', we keep record</td></tr>';
}
}
}
$i++;
}
$db->commit();
}
}
}
/* From here, actions need a parameter */
@@ -903,7 +983,7 @@ if ($ok && GETPOST('set_empty_time_spent_amount', 'alpha'))
// force_disable_of_modules_not_found
if ($ok && GETPOST('force_disable_of_modules_not_found', 'alpha'))
{
print '<tr><td colspan="2"><br>*** Force modules not found to be disabled (only modules adding js, css or hooks can be detected as removed)</td></tr>';
print '<tr><td colspan="2"><br>*** Force modules not found physicaly to be disabled (only modules adding js, css or hooks can be detected as removed physicaly)</td></tr>';
$arraylistofkey=array('hooks','js','css');
@@ -931,12 +1011,16 @@ if ($ok && GETPOST('force_disable_of_modules_not_found', 'alpha'))
$db->begin();
$reg = array();
if (preg_match('/MAIN_MODULE_(.*)_'.strtoupper($key).'/i', $constantname, $reg))
{
$name=strtolower($reg[1]);
if ($name) // And entry for key $key and module $name was found in database.
if ($name) // An entry for key $key and module $name was found in database.
{
$reloffile = '';
$result = 'found';
if ($key == 'hooks') $reloffile=$name.'/class/actions_'.$name.'.class.php';
if ($key == 'js')
{
@@ -953,6 +1037,8 @@ if ($ok && GETPOST('force_disable_of_modules_not_found', 'alpha'))
$reloffile=preg_replace('/^\//', '', $valuearray[0]);
}
if ($reloffile)
{
//var_dump($key.' - '.$value.' - '.$reloffile);
try {
$result = dol_buildpath($reloffile, 0, 2);
@@ -960,6 +1046,8 @@ if ($ok && GETPOST('force_disable_of_modules_not_found', 'alpha'))
catch(Exception $e)
{
// No catch yet
$result = 'found'; // If error, we force lke if we found to avoid any deletion
}
}
if (! $result)
@@ -967,7 +1055,7 @@ if ($ok && GETPOST('force_disable_of_modules_not_found', 'alpha'))
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)."'";
$sql2 ="DELETE FROM ".MAIN_DB_PREFIX."const WHERE name 'MAIN_MODULE_".strtoupper($name)."_".strtoupper($key)."'";
$resql2=$db->query($sql2);
if (! $resql2)
{