Fix: Better error management in module activation

This commit is contained in:
Laurent Destailleur 2008-12-02 14:16:18 +00:00
parent 18369b0aa5
commit da2a195e5c
4 changed files with 289 additions and 48 deletions

View File

@ -195,55 +195,59 @@ foreach ($dirlist as $dirroot)
{
$dir = $dirroot . "/includes/modules/";
// Charge tableaux modules, nom, numero, orders depuis r<>pertoire dir
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
if ($handle)
{
//print "$i ".$file."\n<br>";
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, strlen($file) - 10) == '.class.php')
{
$modName = substr($file, 0, strlen($file) - 10);
if ($modName)
{
include_once($dir.$file);
$objMod = new $modName($db);
if ($objMod->numero > 0)
{
$j = $objMod->numero;
}
else
{
$j = 1000 + $i;
}
$modulequalified=1;
// We discard modules that does not respect constraint on menu handlers
if ($objMod->needleftmenu && sizeof($objMod->needleftmenu) && ! in_array($conf->left_menu,$objMod->needleftmenu)) $modulequalified=0;
if ($objMod->needtopmenu && sizeof($objMod->needtopmenu) && ! in_array($conf->top_menu,$objMod->needtopmenu)) $modulequalified=0;
// We discard modules according to features level (PS: if module is activated we always show it)
$const_name = 'MAIN_MODULE_'.strtoupper(eregi_replace('^mod','',get_class($objMod)));
if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
if ($modulequalified)
{
$modules[$i] = $objMod;
$filename[$i]= $modName;
$orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module
//print "x".$modName." ".$orders[$i]."\n<br>";
$categ[$objMod->special]++; // Array of all different modules categories
$dirmod[$i] = $dirroot;
$j++;
$i++;
}
}
}
while (($file = readdir($handle))!==false)
{
//print "$i ".$file."\n<br>";
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, strlen($file) - 10) == '.class.php')
{
$modName = substr($file, 0, strlen($file) - 10);
if ($modName)
{
include_once($dir.$file);
$objMod = new $modName($db);
if ($objMod->numero > 0)
{
$j = $objMod->numero;
}
else
{
$j = 1000 + $i;
}
$modulequalified=1;
// We discard modules that does not respect constraint on menu handlers
if ($objMod->needleftmenu && sizeof($objMod->needleftmenu) && ! in_array($conf->left_menu,$objMod->needleftmenu)) $modulequalified=0;
if ($objMod->needtopmenu && sizeof($objMod->needtopmenu) && ! in_array($conf->top_menu,$objMod->needtopmenu)) $modulequalified=0;
// We discard modules according to features level (PS: if module is activated we always show it)
$const_name = 'MAIN_MODULE_'.strtoupper(eregi_replace('^mod','',get_class($objMod)));
if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
if ($modulequalified)
{
$modules[$i] = $objMod;
$filename[$i]= $modName;
$orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module
//print "x".$modName." ".$orders[$i]."\n<br>";
$categ[$objMod->special]++; // Array of all different modules categories
$dirmod[$i] = $dirroot;
$j++;
$i++;
}
}
}
}
closedir($handle);
}
}
asort($orders);

View File

@ -728,8 +728,8 @@ class DolibarrModules
/**
\brief Insere les menus dans llx_menu*
\return int Nombre d'erreurs (0 si ok)
* \brief Insere les menus dans llx_menu*
* \return int Nombre d'erreurs (0 si ok)
*/
function insert_menus()
{
@ -741,6 +741,7 @@ class DolibarrModules
$this->db->begin();
//var_dump($this->menu); exit;
foreach ($this->menu as $key => $value)
{
$menu = new Menubase($this->db);
@ -749,9 +750,11 @@ class DolibarrModules
if (! $this->menu[$key]['fk_menu'])
{
$menu->fk_menu=0;
//print 'aaa'.$this->menu[$key]['fk_menu'];
}
else
{
//print 'xxx'.$this->menu[$key]['fk_menu'];exit;
$numparent=$this->menu[$key]['fk_menu'];
$numparent=eregi_replace('r=','',$numparent);
if (isset($this->menu[$numparent]['rowid']))
@ -761,6 +764,7 @@ class DolibarrModules
else
{
$this->error="BadDefinitionOfMenuArrayInModuleDescriptor";
dolibarr_syslog("DolibarrModules::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR);
$err++;
}
}
@ -784,7 +788,9 @@ class DolibarrModules
else
{
$this->error=$menu->error;
dolibarr_syslog('DolibarrModules::insert_menus result='.$result." ".$this->error, LOG_ERR);
$err++;
break;
}
}
}

View File

@ -38,6 +38,15 @@ PredefinedMailContentSendInvoice=Veuillez trouver ci-joint la facture __FACREF__
PredefinedMailContentSendInvoiceReminder=Nous apportons à votre connaissance que la facture __FACREF__ ne semble pas avoir été réglée. La voici donc, pour rappel, en pièce jointe.\n\nCordialement\n\n
PredefinedMailContentSendProposal=Veuillez trouver ci-joint la proposition commerciale __PROPREF__\n\nCordialement\n\n
PredefinedMailContentSendOrder=Veuillez trouver ci-joint la commande __ORDERREF__\n\nCordialement\n\n
DemoDesc=Dolibarr n'est pas un ERP monolithique mais composé de modules fonctionnelles simples et optionnels. Une démonstration qui inclut tous ces modules n'a pas de sens car jamais tous les modules sont utilisés. Aussi, plusieurs profils type de démo sont disponibles.
ChooseYourDemoProfil=Veuillez choisir le profil de démo qui correspond le mieux à votre activité...
DemoFundation=Gestion des adhérents d'une association
DemoFundation2=Gestion des adhérents et trésorerie d'une association
DemoCompanyServiceOnly=Gestion d'une activité d'indépendant faisant du service
DemoCompanyShopWithCashDesk=Gestion d'un magasin avec caisse
DemoCompanyProductAndStocks=Gestion d'une PME revendeuse de produits
DemoCompanyAll=Gestion d'une PME aux activités multiples (tous les modules principaux)
GoToDemo=Accéder à la démo
##### Bookmark #####
Bookmark=Marque page
Bookmarks=Marque pages

View File

@ -0,0 +1,222 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
\file htdocs/public/demo/index.php
\ingroup core
\brief File to access demo
\author Laurent Destailleur
\version $Id$
*/
require("../../master.inc.php");
$langs->load("main");
$langs->load("other");
$demoprofiles=array(
array('default'=>'-1', 'key'=>'profdemofun','label'=>'DemoFundation',
'disablemodules'=>'banque,barcode,bookmark,boutique,cashdesk,commercial,commande,comptabilite,contrat,expedition,facture,fournisseur,prelevement,produit,projet,service,societe,stock,tax'),
array('default'=>'0', 'key'=>'profdemofun2','label'=>'DemoFundation2',
'disablemodules'=>'barcode,boutique,bookmark,cashdesk,commercial,contrat,facture,commande,fournisseur,prelevement,produit,projet,service,societe,stock'),
array('default'=>'1', 'key'=>'profdemoservonly','label'=>'DemoCompanyServiceOnly',
'disablemodules'=>'adherent,barcode,boutique,bookmark,cashdesk,don,prelevement,produit,projet,stock'),
array('default'=>'-1','key'=>'profdemoshopwithdesk','label'=>'DemoCompanyShopWithCashDesk',
'disablemodules'=>'adherent,boutique,bookmark,don,prelevement,produit,stock'),
array('default'=>'0', 'key'=>'profdemoprodstock','label'=>'DemoCompanyProductAndStocks',
'disablemodules'=>'adherent,boutique,bookmark,cashdesk,don,prelevement,produit,stock'),
array('default'=>'0', 'key'=>'profdemoall','label'=>'DemoCompanyAll',
'disablemodules'=>'adherent,boutique,bookmark,cashdesk,don'),
);
function llxHeaderVierge($title, $head = "")
{
global $user, $conf, $langs;
print "<html>\n";
print "<head>\n";
print "<title>".$title."</title>\n";
print '<meta name="robots" content="noindex,nofollow">'."\n";
print '<link rel="stylesheet" type="text/css" href="/theme/eldy/eldy.css.php">'."\n";
if ($head) print $head."\n";
print "</head>\n";
print '<body style="margin: 20px;">'."\n";
}
function llxFooter()
{
print "</body>\n";
print "</html>\n";
}
/*
* Actions
*/
if ($_POST["action"] == 'gotodemo')
{
//print 'ee'.$_POST["demochoice"];
$disablestring='';
foreach ($demoprofiles as $profilearray)
{
if ($profilearray['key'] == $_POST["demochoice"])
{
$disablestring=$profilearray['disablemodules'];
break;
}
}
if ($disablestring)
{
header("Location: ".DOL_URL_ROOT.'/index.php?disablemodules='.$disablestring);
exit;
}
}
/*
* View
*/
llxHeaderVierge($langs->trans("DolibarrDemo"));
// Search modules
$dirlist=array();
$dirlist[]=DOL_DOCUMENT_ROOT;
if (defined('DOL_DOCUMENT_ROOT_BIS')) $dirlist[]=DOL_DOCUMENT_ROOT_BIS;
$filename = array();
$modules = array();
$orders = array();
$categ = array();
$dirmod = array();
$i = 0; // is a sequencer of modules found
$j = 0; // j is module number. Automatically affeted if module number not defined.
foreach ($dirlist as $dirroot)
{
$dir = $dirroot . "/includes/modules/";
// Charge tableaux modules, nom, numero, orders depuis r<>pertoire dir
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{
//print "$i ".$file."\n<br>";
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, strlen($file) - 10) == '.class.php')
{
$modName = substr($file, 0, strlen($file) - 10);
if ($modName)
{
include_once($dir.$file);
$objMod = new $modName($db);
if ($objMod->numero > 0)
{
$j = $objMod->numero;
}
else
{
$j = 1000 + $i;
}
$modulequalified=1;
// We discard modules that does not respect constraint on menu handlers
if ($objMod->needleftmenu && sizeof($objMod->needleftmenu) && ! in_array($conf->left_menu,$objMod->needleftmenu)) $modulequalified=0;
if ($objMod->needtopmenu && sizeof($objMod->needtopmenu) && ! in_array($conf->top_menu,$objMod->needtopmenu)) $modulequalified=0;
// We discard modules according to features level (PS: if module is activated we always show it)
$const_name = 'MAIN_MODULE_'.strtoupper(eregi_replace('^mod','',get_class($objMod)));
if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
if ($modulequalified)
{
$modules[$i] = $objMod;
$filename[$i]= $modName;
$orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module
//print "x".$modName." ".$orders[$i]."\n<br>";
$categ[$objMod->special]++; // Array of all different modules categories
$dirmod[$i] = $dirroot;
$j++;
$i++;
}
}
}
}
}
asort($orders);
//var_dump($orders);
print '<form name="choosedemo" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<table style="font-size:14px;">';
print '<tr><td>';
print '<center><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo_2.png" alt="Dolibarr logo"></center><br>';
print '<br>';
print $langs->trans("DemoDesc").'<br>';
print '<br>';
print '<b>'.$langs->trans("ChooseYourDemoProfil").'</b>';
print '</td></tr>';
print '<tr><td width="50%">';
print '<table style="font-size:14px;">'."\n";
foreach ($demoprofiles as $profilarray)
{
if ($profilarray['default'] >= 0)
{
print '<tr><td><input type="radio" name="demochoice"';
if ($profilarray['default']) print ' checked="true"';
print ' value="'.$profilarray['key'].'"></td>';
print '<td>'.$langs->trans($profilarray['label']).'</td></tr>'."\n";
}
}
print '</table>';
print '</td>';
print '</tr>';
// Description
print '<tr><td>';
print '</td></tr>';
// Button
print '<tr><td align="center">';
print '<input type="hidden" name="action" value="gotodemo">';
print '<input class="button" type="submit" value=" < '.$langs->trans("GoToDemo").' > ">';
print '</td></tr>';
print '</table>';
print '</form>';
$db->close();
llxFooter('$Date$ - $Revision$');
?>