From 295b4483d49b1e730d59330776f642f187cec819 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 23 Nov 2017 13:23:16 +0100 Subject: [PATCH] Enhance the repair.php tool --- htdocs/core/modules/DolibarrModules.class.php | 8 +- htdocs/install/repair.php | 157 +++++++++++++++--- htdocs/langs/en_US/install.lang | 3 +- 3 files changed, 145 insertions(+), 23 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 32240f778d2..0155634ed25 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1815,7 +1815,10 @@ class DolibarrModules // Can not be abstract, because we need to insta { $menu = new Menubase($this->db); $menu->menu_handler='all'; + + //$menu->module=strtolower($this->name); TODO When right_class will be same than module name $menu->module=$this->rights_class; + if (! $this->menu[$key]['fk_menu']) { $menu->fk_menu=0; @@ -1909,8 +1912,11 @@ class DolibarrModules // Can not be abstract, because we need to insta $err=0; + //$module=strtolower($this->name); TODO When right_class will be same than module name + $module=$this->rights_class; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; - $sql.= " WHERE module = '".$this->db->escape($this->rights_class)."'"; + $sql.= " WHERE module = '".$this->db->escape($module)."'"; $sql.= " AND entity = ".$conf->entity; dol_syslog(get_class($this)."::delete_menus", LOG_DEBUG); diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 321e1dc335b..e05fdec0beb 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -47,9 +47,7 @@ $langs->setDefaultLang($setuplang); $versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($argv[1])?'':$argv[1]); $versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]); -$langs->load("admin"); -$langs->load("install"); -$langs->load("other"); +$langs->loadLangs(array("admin","install","other")); if ($dolibarr_main_db_type == "mysqli") $choix=1; if ($dolibarr_main_db_type == "pgsql") $choix=2; @@ -71,8 +69,10 @@ $actiondone=1; print '

'.$langs->trans("Repair").'

'; -print 'Option restore_thirdparties_logos is '.(GETPOST('restore_thirdparties_logos','alpha')?GETPOST('restore_thirdparties_logos','alpha'):'0').'
'."\n"; -print 'Option clean_linked_elements is '.(GETPOST('clean_linked_elements','alpha')?GETPOST('clean_linked_elements','alpha'):'0').'
'."\n"; +print 'Option standard (0 or \'confirmed\') is '.(GETPOST('standard','alpha')?GETPOST('standard','alpha'):'0').'
'."\n"; +print 'Option restore_thirdparties_logos (0 or \'confirmed\') is '.(GETPOST('restore_thirdparties_logos','alpha')?GETPOST('restore_thirdparties_logos','alpha'):'0').'
'."\n"; +print 'Option clean_linked_elements (0 or \'confirmed\') is '.(GETPOST('clean_linked_elements','alpha')?GETPOST('clean_linked_elements','alpha'):'0').'
'."\n"; +print 'Option clean_menus (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_menus','alpha')?GETPOST('clean_menus','alpha'):'0').'
'."\n"; print 'Option clean_orphelin_dir (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir','alpha')?GETPOST('clean_orphelin_dir','alpha'):'0').'
'."\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').'
'."\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').'
'."\n"; @@ -153,18 +153,28 @@ if ($ok) //print ''.join('.',$versionarray).''; } -// Show wait message -print ''.$langs->trans("PleaseBePatient").'

'; -flush(); +$conf->setValues($db); + /* Start action here */ +$oneoptionset=0; +$oneoptionset=(GETPOST('standard', 'alpha') || GETPOST('restore_thirdparties_logos','alpha') || GETPOST('clean_linked_elements','alpha') || GETPOST('clean_menus','alpha') + || GETPOST('clean_orphelin_dir','alpha') || GETPOST('clean_product_stock_batch','alpha') || GETPOST('set_empty_time_spent_amount','alpha') || GETPOST('rebuild_product_thumbs','alpha') + || GETPOST('force_disable_of_modules_not_found','alpha') || GETPOST('force_utf8_on_tables','alpha')); + +if ($ok && $oneoptionset) +{ + // Show wait message + print ''.$langs->trans("PleaseBePatient").'

'; + flush(); +} // run_sql: Run repair SQL file -if ($ok) +if ($ok && GETPOST('standard', 'alpha')) { - $dir = "mysql/migration/"; + $dir = "mysql/migration/"; $filelist=array(); $i = 0; @@ -206,7 +216,7 @@ if ($ok) // sync_extrafields: Search list of fields declared and list of fields created into databases, then create fields missing -if ($ok) +if ($ok && GETPOST('standard', 'alpha')) { $extrafields=new ExtraFields($db); $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', @@ -314,7 +324,7 @@ if ($ok) // clean_data_ecm_dir: Clean data into ecm_directories table -if ($ok) +if ($ok && GETPOST('standard', 'alpha')) { clean_data_ecm_directories(); } @@ -483,6 +493,96 @@ if ($ok && GETPOST('clean_linked_elements','alpha')) } +// clean_menus: Check orphelins menus +if ($ok && GETPOST('clean_menus','alpha')) +{ + print '
*** Clean menu entries coming from disabled modules'; + + $sql ="SELECT rowid, module"; + $sql.=" FROM ".MAIN_DB_PREFIX."menu as c"; + $sql.=" WHERE module IS NOT NULL AND module <> ''"; + $sql.=" ORDER BY module"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + $i = 0; + while ($i < $num) + { + $obj=$db->fetch_object($resql); + + $modulecond=$obj->module; + $modulecondarray = explode('|',$obj->module); // Name of module + + print ''; + print $modulecond; + + $db->begin(); + + if ($modulecond) // And menu entry for module $modulecond was found in database. + { + $moduleok=0; + foreach($modulecondarray as $tmpname) + { + if ($tmpname == 'margins') $tmpname='margin'; // TODO Remove this when normalized + + $result = 0; + if (! empty($conf->$tmpname)) $result = $conf->$tmpname->enabled; + if ($result) $moduleok++; + } + + if (! $moduleok && $modulecond) + { + print ' - Module condition '.$modulecond.' seems ko, we delete menu entry.'; + if (GETPOST('clean_menus') == 'confirmed') + { + $sql2 ="DELETE FROM ".MAIN_DB_PREFIX."menu WHERE module = '".$modulecond."'"; + $resql2=$db->query($sql2); + if (! $resql2) + { + $error++; + dol_print_error($db); + } + else + print ' - Cleaned'; + } + else + { + print ' - Canceled (test mode)'; + } + } + else + { + print ' - Module condition '.$modulecond.' is ok, we do nothing.'; + } + } + + if (!$error) $db->commit(); + else $db->rollback(); + + print''; + + if ($error) break; + + $i++; + } + } + else + { + print 'No menu entries of disabled menus found'; + } + } + else + { + dol_print_error($db); + } +} + + + // clean_orphelin_dir: Run purge of directory if ($ok && GETPOST('clean_orphelin_dir','alpha')) { @@ -802,7 +902,6 @@ if ($ok && GETPOST('set_empty_time_spent_amount','alpha')) // clean_old_module_entries: Clean data into const when files of module were removed without being -// clean_linked_elements: Check and clean linked elements if ($ok && GETPOST('force_disable_of_modules_not_found','alpha')) { print '
*** Force modules not found to be disabled'; @@ -851,10 +950,19 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha')) { $value=$obj->value; $valuearray=json_decode($value); + if ($value && count($valuearray)==0) $valuearray[0]=$value; // If value was not a json array but a string $reloffile=preg_replace('/^\//','',$valuearray[0]); } - $result = dol_include_once($reloffile); + //var_dump($key.' - '.$value.' - '.$reloffile); + try { + $result = dol_buildpath($reloffile, 0, 2); + } + catch(Exception $e) + { + + } + if (! $result) { print ' - File of '.$key.' ('.$reloffile.') NOT found, we disable the module.'; @@ -875,11 +983,11 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha')) dol_print_error($db); } else - print " - Cleaned"; + print ' - Cleaned'; } else { - print ' - Canceled (test mode)'; + print ' - Canceled (test mode)'; } } else @@ -914,7 +1022,6 @@ if ($ok && GETPOST('force_disable_of_modules_not_found','alpha')) -// clean_old_module_entries: Clean data into const when files of module were removed without being // clean_linked_elements: Check and clean linked elements if ($ok && GETPOST('force_utf8_on_tables','alpha')) { @@ -952,10 +1059,18 @@ if (empty($actiondone)) print '
'.$langs->trans("ErrorWrongParameters").'
'; } - -print '
'; -print $langs->trans("GoToDolibarr"); -print '
'; +if ($oneoptionset) +{ + print '
'; + print $langs->trans("GoToDolibarr"); + print '
'; +} +else +{ + print '
'; + print $langs->trans("SetAtLeastOneOptionAsUrlParameter"); + print '
'; +} dolibarr_install_syslog("--- repair: end"); pFooter(1,$setuplang); diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 4ff99df5269..7204938098b 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -139,7 +139,8 @@ KeepDefaultValuesDeb=You use the Dolibarr setup wizard from a Linux package (Ubu KeepDefaultValuesMamp=You use the Dolibarr setup wizard from DoliMamp, so values proposed here are already optimized. Change them only if you know what you do. KeepDefaultValuesProxmox=You use the Dolibarr setup wizard from a Proxmox virtual appliance, so values proposed here are already optimized. Change them only if you know what you do. UpgradeExternalModule=Run dedicated upgrade process of external modules - +SetAtLeastOneOptionAsUrlParameter=Set at least one option as a parameter in URL. For example: '...repair.php?standard=confirmed' +NothingToDelete=Nothing to clean/delete ######### # upgrade MigrationFixData=Fix for denormalized data