From 97f91d0ef962ce82d035dcb2306f73546997c12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Mon, 31 Aug 2015 17:42:08 +0200 Subject: [PATCH 1/2] Fix #3440 Only search core modules in main path Removed duplicated code and used common dolGetModulesDirs() function --- htdocs/admin/modules.php | 39 ++++----------- htdocs/core/lib/admin.lib.php | 79 +++--------------------------- htdocs/core/lib/functions2.lib.php | 11 +++-- htdocs/public/demo/index.php | 31 +++--------- 4 files changed, 31 insertions(+), 129 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 398dd8036fb..cf974990f01 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -1,11 +1,12 @@ - * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2013 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2015 Jean-François Ferry +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; $langs->load("errors"); $langs->load("admin"); @@ -76,28 +78,7 @@ llxHeader('',$langs->trans("Setup"),$help_url); // Search modules dirs -$modulesdir = array(); -foreach ($conf->file->dol_document_root as $type => $dirroot) -{ - $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; - - $handle=@opendir($dirroot); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } -} -//var_dump($modulesdir); +$modulesdir = dolGetModulesDirs(); $filename = array(); diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 7469777fa89..b24fce76582 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1,7 +1,8 @@ - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2012 J. Fernando Lagrange +/* Copyright (C) 2008-2011 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2012 J. Fernando Lagrange + * Copyright (C) 2015 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +24,7 @@ * \brief Library of admin functions */ +require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; /** * Renvoi une version en chaine depuis une version en tableau @@ -676,29 +678,7 @@ function activateModule($value,$withdeps=1) $ret=''; $modName = $value; $modFile = $modName . ".class.php"; - - // Loop on each directory to fill $modulesdir - $modulesdir = array(); - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[] = $dirroot."/core/modules/"; - - $handle=@opendir(dol_osencode($dirroot)); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } + $modulesdir = dolGetModulesDirs(); // Loop on each directory $found=false; @@ -795,29 +775,7 @@ function unActivateModule($value, $requiredby=1) $ret=''; $modName = $value; $modFile = $modName . ".class.php"; - - // Loop on each directory to fill $modulesdir - $modulesdir = array(); - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[] = $dirroot."/core/modules/"; - - $handle=@opendir(dol_osencode($dirroot)); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } + $modulesdir = dolGetModulesDirs(); // Loop on each directory $found=false; @@ -889,31 +847,10 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql $orders = array(); $categ = array(); $dirmod = array(); - $modulesdir = array(); + $modulesdir = dolGetModulesDirs(); $i = 0; // is a sequencer of modules found $j = 0; // j is module number. Automatically affected if module number not defined. - foreach ($conf->file->dol_document_root as $type => $dirroot) - { - $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; - - $handle=@opendir($dirroot); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } - } - foreach ($modulesdir as $dir) { // Load modules attributes in arrays (name, numero, orders) from dir directory diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 9c77729ac5a..651e4ea54ac 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1,9 +1,10 @@ - * Copyright (C) 2008-2012 Regis Houssin - * Copyright (C) 2008 Raphael Bertrand (Resultic) +/* Copyright (C) 2008-2011 Laurent Destailleur + * Copyright (C) 2008-2012 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2014 Marcos García * Copyright (C) 2015 Ferran Marcet + * Copyright (C) 2015 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -104,7 +105,9 @@ function dolGetModulesDirs($subdir='') foreach ($conf->file->dol_document_root as $type => $dirroot) { // Default core/modules dir - $modulesdir[$dirroot . '/core/modules'.$subdir.'/'] = $dirroot . '/core/modules'.$subdir.'/'; + if ($type === 'main') { + $modulesdir[$dirroot . '/core/modules' . $subdir . '/'] = $dirroot . '/core/modules' . $subdir . '/'; + } // Scan dir from external modules $handle=@opendir($dirroot); diff --git a/htdocs/public/demo/index.php b/htdocs/public/demo/index.php index 4b0c0526174..8fc59b818ae 100644 --- a/htdocs/public/demo/index.php +++ b/htdocs/public/demo/index.php @@ -1,7 +1,8 @@ - * Copyright (C) 2006-2013 Laurent Destailleur - * Copyright (C) 2010 Regis Houssin +/* Copyright (C) 2001-2002 Rodolphe Quiedeville + * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2010 Regis Houssin + * Copyright (C) 2015 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,7 @@ define("NOLOGIN",1); // This means this output page does not require to be logge define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require '../../main.inc.php'; +require_once '../../core/lib/functions2.lib.php'; $langs->load("main"); $langs->load("install"); @@ -99,28 +101,7 @@ $dirlist=$conf->file->dol_document_root; // Search modules dirs -$modulesdir = array(); -foreach ($conf->file->dol_document_root as $type => $dirroot) -{ - $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; - - $handle=@opendir($dirroot); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') - { - if (is_dir($dirroot . '/' . $file . '/core/modules/')) - { - $modulesdir[$dirroot . '/' . $file . '/core/modules/'] = $dirroot . '/' . $file . '/core/modules/'; - } - } - } - closedir($handle); - } -} -//var_dump($modulesdir); +$modulesdir = dolGetModulesDirs(); $filename = array(); From 0a9f4a41f30e913811ae2a45379f73d1d5250ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Sat, 5 Sep 2015 12:23:49 +0200 Subject: [PATCH 2/2] Qual: Removed dead code --- htdocs/core/lib/admin.lib.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index b24fce76582..4e49041e861 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -842,11 +842,6 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql global $db, $modules, $conf, $langs; // Search modules - $filename = array(); - $modules = array(); - $orders = array(); - $categ = array(); - $dirmod = array(); $modulesdir = dolGetModulesDirs(); $i = 0; // is a sequencer of modules found $j = 0; // j is module number. Automatically affected if module number not defined. @@ -900,14 +895,6 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql } } - $modules[$i] = $objMod; - $filename[$i]= $modName; - $orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module - //print "x".$modName." ".$orders[$i]."\n
"; - if (isset($categ[$objMod->special])) $categ[$objMod->special]++; // Array of all different modules categories - else $categ[$objMod->special]=1; - $dirmod[$i] = $dirroot; - // Complete arrays //&$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond if (empty($objMod->dictionaries) && ! empty($objMod->dictionnaries)) $objMod->dictionaries=$objMod->dictionnaries; // For backward compatibility