diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 12449d201f6..f70d0b58c5c 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -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)
{
diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php
index fa1b070cc40..c52e840d11e 100644
--- a/htdocs/install/repair.php
+++ b/htdocs/install/repair.php
@@ -67,17 +67,17 @@ $actiondone=1;
print '
'.$langs->trans("Repair").'
';
-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";
-print 'Option rebuild_product_thumbs (0 or \'test\' or \'confirmed\') is '.(GETPOST('rebuild_product_thumbs', 'alpha')?GETPOST('rebuild_product_thumbs', 'alpha'):'0').'
'."\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').'
'."\n";
-print 'Option clean_perm_table (0 or \'test\' or \'confirmed\') is '.(GETPOST('clean_perm_table', 'alpha')?GETPOST('clean_perm_table', 'alpha'):'0').'
'."\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').'
'."\n";
+print 'Option standard (\'test\' or \'confirmed\') is '.(GETPOST('standard', 'alpha')?GETPOST('standard', 'alpha'):'undefined').'
'."\n";
+print 'Option restore_thirdparties_logos (\'test\' or \'confirmed\') is '.(GETPOST('restore_thirdparties_logos', 'alpha')?GETPOST('restore_thirdparties_logos', 'alpha'):'undefined').'
'."\n";
+print 'Option clean_linked_elements (\'test\' or \'confirmed\') is '.(GETPOST('clean_linked_elements', 'alpha')?GETPOST('clean_linked_elements', 'alpha'):'undefined').'
'."\n";
+print 'Option clean_menus (\'test\' or \'confirmed\') is '.(GETPOST('clean_menus', 'alpha')?GETPOST('clean_menus', 'alpha'):'undefined').'
'."\n";
+print 'Option clean_orphelin_dir (\'test\' or \'confirmed\') is '.(GETPOST('clean_orphelin_dir', 'alpha')?GETPOST('clean_orphelin_dir', 'alpha'):'undefined').'
'."\n";
+print 'Option clean_product_stock_batch (\'test\' or \'confirmed\') is '.(GETPOST('clean_product_stock_batch', 'alpha')?GETPOST('clean_product_stock_batch', 'alpha'):'undefined').'
'."\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').'
'."\n";
+print 'Option rebuild_product_thumbs (\'test\' or \'confirmed\') is '.(GETPOST('rebuild_product_thumbs', 'alpha')?GETPOST('rebuild_product_thumbs', 'alpha'):'undefined').'
'."\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').'
'."\n";
+print 'Option clean_perm_table (\'test\' or \'confirmed\') is '.(GETPOST('clean_perm_table', 'alpha')?GETPOST('clean_perm_table', 'alpha'):'undefined').'
'."\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').'
'."\n";
print '
';
print '';
@@ -302,14 +302,23 @@ if ($ok && GETPOST('standard', 'alpha'))
);
//var_dump($field_desc);exit;
- $result=$db->DDLAddField($tableextra, $code, $field_desc, "");
- if ($result < 0)
+ $result = 0;
+ if (GETPOST('standard', 'alpha') == 'confirmed')
{
- print "KO ".$db->lasterror."
\n";
+ $result=$db->DDLAddField($tableextra, $code, $field_desc, "");
+
+ if ($result < 0)
+ {
+ print "KO ".$db->lasterror."
\n";
+ }
+ else
+ {
+ print "OK
\n";
+ }
}
else
{
- print "OK
\n";
+ print ' - Mode test, no column added.';
}
}
}
@@ -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 ' *** Clean module_parts entries of modules not enabled |
';
+ $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 '| Constant '.$obj->name.' set in entity '.$obj->entity.' with value '.$obj->value.' -> Module not enabled in entity '.$obj->entity.', we delete record |
';
+ }
+ else
+ {
+ print '| 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) |
';
+ }
+ }
+ else
+ {
+ //print '| Constant '.$obj->name.' set in entity '.$obj->entity.' with value '.$obj->value.' -> Module found in entity '.$obj->entity.', we keep record |
';
+ }
+ }
+ }
+
+ $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 ' *** Force modules not found to be disabled (only modules adding js, css or hooks can be detected as removed) |
';
+ print ' *** Force modules not found physicaly to be disabled (only modules adding js, css or hooks can be detected as removed physicaly) |
';
$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,13 +1037,17 @@ if ($ok && GETPOST('force_disable_of_modules_not_found', 'alpha'))
$reloffile=preg_replace('/^\//', '', $valuearray[0]);
}
- //var_dump($key.' - '.$value.' - '.$reloffile);
- try {
- $result = dol_buildpath($reloffile, 0, 2);
- }
- catch(Exception $e)
+ if ($reloffile)
{
- // No catch yet
+ //var_dump($key.' - '.$value.' - '.$reloffile);
+ try {
+ $result = dol_buildpath($reloffile, 0, 2);
+ }
+ 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)
{