Skip to content
Snippets Groups Projects
Commit d6a4d5ef authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: avoid errors if install directory is deleted before module

activation
parent 2dcb1589
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
......@@ -201,22 +201,27 @@ class modCommande extends DolibarrModules
$this->remove($options);
//ODT template
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt';
$dirodt=DOL_DATA_ROOT.'/doctemplates/orders';
dol_mkdir($dirodt);
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt'; $dest=$dirodt.'/template_order.odt';
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
$dest=$dirodt.'/template_order.odt';
if (file_exists($src) && ! file_exists($dest))
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
dol_mkdir($dirodt);
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
}
$sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','order',".$conf->entity.")"
);
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','order',".$conf->entity.")"
);
return $this->_init($sql,$options);
}
......
......@@ -3,7 +3,7 @@
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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
......@@ -223,21 +223,27 @@ class modFacture extends DolibarrModules
// Remove permissions and default values
$this->remove($options);
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
//ODT template
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
$dirodt=DOL_DATA_ROOT.'/doctemplates/invoices';
dol_mkdir($dirodt);
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt'; $dest=$dirodt.'/template_invoice.odt';
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
$dest=$dirodt.'/template_invoice.odt';
if (file_exists($src) && ! file_exists($dest))
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
dol_mkdir($dirodt);
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
}
$sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','invoice',".$conf->entity.")"
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','invoice',".$conf->entity.")"
);
return $this->_init($sql,$options);
......
......@@ -3,7 +3,7 @@
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2012 Juanjo Menentr <jmenent@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
......@@ -199,21 +199,26 @@ class modPropale extends DolibarrModules
$this->remove($options);
//ODT template
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
$dirodt=DOL_DATA_ROOT.'/doctemplates/proposals';
dol_mkdir($dirodt);
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt'; $dest=$dirodt.'/template_proposal.odt';
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
$dest=$dirodt.'/template_proposal.odt';
if (file_exists($src) && ! file_exists($dest))
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
dol_mkdir($dirodt);
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
}
$sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','propal',".$conf->entity.")",
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','propal',".$conf->entity.")",
);
return $this->_init($sql,$options);
......
......@@ -368,16 +368,22 @@ class modSociete extends DolibarrModules
// We disable this to prevent pb of modules not correctly disabled
//$this->remove($options);
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
//ODT template
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
$dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
dol_mkdir($dirodt);
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt'; $dest=$dirodt.'/template_thirdparty.odt';
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
$dest=$dirodt.'/template_thirdparty.odt';
if (file_exists($src) && ! file_exists($dest))
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
dol_mkdir($dirodt);
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
}
$sql = array();
......
......@@ -337,6 +337,7 @@ if (! $error && $db->connected && $action == "set")
$dir[4] = $main_data_dir."/propale";
$dir[5] = $main_data_dir."/ficheinter";
$dir[6] = $main_data_dir."/produit";
$dir[7] = $main_data_dir."/doctemplates";
// Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas
$num=count($dir);
......@@ -372,6 +373,27 @@ if (! $error && $db->connected && $action == "set")
print "</td></tr>";
print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
}
else
{
//ODT templates
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$srcroot='./doctemplates';
$destroot=$main_data_dir.'/doctemplates';
$docs=array('thirdparties' => 'thirdparty', 'proposals' => 'proposal', 'orders' => 'order', 'invoices' => 'invoice');
foreach($docs as $dir => $file)
{
$src=$srcroot.'/thirdparties/template_'.$file.'.odt';
$dirodt=$destroot.'/'.$dir;
$dest=$dirodt.'/template_'.$file.'.odt';
dol_mkdir($dirodt);
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile',$src,$dest).'</td></tr>';
}
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment