Cration des bases lors de l'activation du module
This commit is contained in:
parent
fed065dd7f
commit
e169c1fc81
@ -130,6 +130,8 @@ class modMyModule extends DolibarrModules
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
$result=$this->load_tables();
|
||||
|
||||
return $this->_init($sql);
|
||||
}
|
||||
|
||||
@ -145,6 +147,53 @@ class modMyModule extends DolibarrModules
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -18,15 +18,13 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/categories/categorie.php
|
||||
\ingroup category
|
||||
\brief Page de l'onglet categories
|
||||
\version $Revision$
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
@ -34,8 +32,6 @@ require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
|
||||
|
||||
$langs->load("categories");
|
||||
|
||||
$user->getrights();
|
||||
|
||||
$mesg=isset($_GET["mesg"])?'<div class="ok">'.$_GET["mesg"].'</div>':'';
|
||||
|
||||
if ($_REQUEST["socid"])
|
||||
|
||||
@ -15,24 +15,19 @@
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/comm/mailing/cibles.php
|
||||
\ingroup mailing
|
||||
\brief Page des cibles de mailing
|
||||
\version $Revision$
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
|
||||
$langs->load("mails");
|
||||
|
||||
$user->getrights("mailing");
|
||||
|
||||
if (! $user->rights->mailing->lire || $user->societe_id > 0)
|
||||
accessforbidden();
|
||||
|
||||
|
||||
@ -313,62 +313,62 @@ class modTelephonie extends DolibarrModules
|
||||
* A faire avant les fichiers *.key.sql
|
||||
*
|
||||
***************************************************************************************/
|
||||
$ok = 1;
|
||||
if ($ok)
|
||||
{
|
||||
$dir = DOL_DOCUMENT_ROOT.'/telephonie/sql/';
|
||||
$ok = 1;
|
||||
if ($ok)
|
||||
{
|
||||
$dir = DOL_DOCUMENT_ROOT.'/telephonie/sql/';
|
||||
|
||||
$ok = 0;
|
||||
$handle=opendir($dir);
|
||||
$table_exists = 0;
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, -8) <> '.key.sql')
|
||||
{
|
||||
$name = substr($file, 0, strlen($file) - 4);
|
||||
$buffer = '';
|
||||
$fp = fopen($dir.$file,"r");
|
||||
if ($fp)
|
||||
{
|
||||
while (!feof ($fp))
|
||||
{
|
||||
$buf = fgets($fp, 4096);
|
||||
if (substr($buf, 0, 2) <> '--')
|
||||
{
|
||||
$buffer .= $buf;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
//print "<tr><td>Creation de la table $name/td>";
|
||||
$requestnb++;
|
||||
if (@$this->db->query($buffer))
|
||||
{
|
||||
//print "<td>OK requete ==== $buffer</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS')
|
||||
{
|
||||
//print "<td>Deje existante</td></tr>";
|
||||
$table_exists = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
closedir($handle);
|
||||
$ok = 0;
|
||||
$handle=opendir($dir);
|
||||
$table_exists = 0;
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (substr($file, strlen($file) - 4) == '.sql' && substr($file,0,4) == 'llx_' && substr($file, -8) <> '.key.sql')
|
||||
{
|
||||
$name = substr($file, 0, strlen($file) - 4);
|
||||
$buffer = '';
|
||||
$fp = fopen($dir.$file,"r");
|
||||
if ($fp)
|
||||
{
|
||||
while (!feof ($fp))
|
||||
{
|
||||
$buf = fgets($fp, 4096);
|
||||
if (substr($buf, 0, 2) <> '--')
|
||||
{
|
||||
$buffer .= $buf;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
//print "<tr><td>Creation de la table $name/td>";
|
||||
$requestnb++;
|
||||
if (@$this->db->query($buffer))
|
||||
{
|
||||
//print "<td>OK requete ==== $buffer</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS')
|
||||
{
|
||||
//print "<td>Deje existante</td></tr>";
|
||||
$table_exists = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
if ($error == 0)
|
||||
{
|
||||
$ok = 1;
|
||||
}
|
||||
}
|
||||
if ($error == 0)
|
||||
{
|
||||
$ok = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
@ -83,7 +83,7 @@ function versiondolibarrarray()
|
||||
/**
|
||||
* \brief Launch a 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)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user