Création des bases lors de l'activation du module

This commit is contained in:
Laurent Destailleur 2008-01-29 20:09:34 +00:00
parent fed065dd7f
commit e169c1fc81
5 changed files with 106 additions and 66 deletions

View File

@ -130,6 +130,8 @@ class modMyModule extends DolibarrModules
{ {
$sql = array(); $sql = array();
$result=$this->load_tables();
return $this->_init($sql); return $this->_init($sql);
} }
@ -145,6 +147,53 @@ class modMyModule extends DolibarrModules
return $this->_remove($sql); return $this->_remove($sql);
} }
/**
* \brief Create tables and keys (called by this->init)
* \return int <=0 if KO, >0 if OK
*/
function load_tables()
{
include_once(DOL_DOCUMENT_ROOT ."/lib/admin.lib.php");
global $db;
$ok = 1;
if ($ok)
{
$dir = DOL_DOCUMENT_ROOT.'/mysql/tables/mymodule/';
$ok = 0;
// Run llx_mytable.sql files
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{
if (eregi('\.sql$',$file) && substr($file,0,4) == 'llx_' && substr($file, -8) <> '.key.sql')
{
$result=run_sql($file,1);
}
}
closedir($handle);
// Run llx_mytable.key.sql files
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{
if (eregi('\.sql$',$file) && substr($file,0,4) == 'llx_' && substr($file, -8) == '.key.sql')
{
$result=run_sql($file,1);
}
}
closedir($handle);
if ($error == 0)
{
$ok = 1;
}
}
return $ok;
}
} }
?> ?>

View File

@ -18,15 +18,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/categories/categorie.php \file htdocs/categories/categorie.php
\ingroup category \ingroup category
\brief Page de l'onglet categories \brief Page de l'onglet categories
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -34,8 +32,6 @@ require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
$langs->load("categories"); $langs->load("categories");
$user->getrights();
$mesg=isset($_GET["mesg"])?'<div class="ok">'.$_GET["mesg"].'</div>':''; $mesg=isset($_GET["mesg"])?'<div class="ok">'.$_GET["mesg"].'</div>':'';
if ($_REQUEST["socid"]) if ($_REQUEST["socid"])

View File

@ -15,24 +15,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/comm/mailing/cibles.php \file htdocs/comm/mailing/cibles.php
\ingroup mailing \ingroup mailing
\brief Page des cibles de mailing \brief Page des cibles de mailing
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
$langs->load("mails"); $langs->load("mails");
$user->getrights("mailing");
if (! $user->rights->mailing->lire || $user->societe_id > 0) if (! $user->rights->mailing->lire || $user->societe_id > 0)
accessforbidden(); accessforbidden();

View File

@ -83,7 +83,7 @@ function versiondolibarrarray()
/** /**
* \brief Launch a sql file * \brief Launch a sql file
* \param sqlfile Full path to sql file * \param sqlfile Full path to sql file
* \return int <0 if ko, >0 if ok * \return int <=0 if KO, >0 if OK
*/ */
function run_sql($sqlfile,$silent=1) function run_sql($sqlfile,$silent=1)
{ {