Fix: avoid errors if install directory is deleted before module

activation
This commit is contained in:
Regis Houssin 2012-08-01 14:42:24 +02:00
parent 2dcb158915
commit d6a4d5ef41
5 changed files with 86 additions and 42 deletions

View File

@ -4,7 +4,7 @@
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * 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> * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -201,22 +201,27 @@ class modCommande extends DolibarrModules
$this->remove($options); $this->remove($options);
//ODT template //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'; $dirodt=DOL_DATA_ROOT.'/doctemplates/orders';
dol_mkdir($dirodt); $dest=$dirodt.'/template_order.odt';
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt'; $dest=$dirodt.'/template_order.odt';
$result=dol_copy($src,$dest,0,0); if (file_exists($src) && ! file_exists($dest))
if ($result < 0)
{ {
$langs->load("errors"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest); dol_mkdir($dirodt);
return 0; $result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
} }
$sql = array( $sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$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.")" "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','order',".$conf->entity.")"
); );
return $this->_init($sql,$options); return $this->_init($sql,$options);
} }

View File

@ -3,7 +3,7 @@
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * 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 * 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 * 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 // Remove permissions and default values
$this->remove($options); $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'; $dirodt=DOL_DATA_ROOT.'/doctemplates/invoices';
dol_mkdir($dirodt); $dest=$dirodt.'/template_invoice.odt';
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt'; $dest=$dirodt.'/template_invoice.odt';
$result=dol_copy($src,$dest,0,0); if (file_exists($src) && ! file_exists($dest))
if ($result < 0)
{ {
$langs->load("errors"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest); dol_mkdir($dirodt);
return 0; $result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
} }
$sql = array( $sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$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.")" "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','invoice',".$conf->entity.")"
); );
return $this->_init($sql,$options); return $this->_init($sql,$options);

View File

@ -3,7 +3,7 @@
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * 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> * Copyright (C) 2012 Juanjo Menentr <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -199,21 +199,26 @@ class modPropale extends DolibarrModules
$this->remove($options); $this->remove($options);
//ODT template //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'; $dirodt=DOL_DATA_ROOT.'/doctemplates/proposals';
dol_mkdir($dirodt); $dest=$dirodt.'/template_proposal.odt';
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt'; $dest=$dirodt.'/template_proposal.odt';
$result=dol_copy($src,$dest,0,0); if (file_exists($src) && ! file_exists($dest))
if ($result < 0)
{ {
$langs->load("errors"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest); dol_mkdir($dirodt);
return 0; $result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
} }
$sql = array( $sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$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.")", "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','propal',".$conf->entity.")",
); );
return $this->_init($sql,$options); return $this->_init($sql,$options);

View File

@ -368,16 +368,22 @@ class modSociete extends DolibarrModules
// We disable this to prevent pb of modules not correctly disabled // We disable this to prevent pb of modules not correctly disabled
//$this->remove($options); //$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'; $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
dol_mkdir($dirodt); $dest=$dirodt.'/template_thirdparty.odt';
$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt'; $dest=$dirodt.'/template_thirdparty.odt';
$result=dol_copy($src,$dest,0,0); if (file_exists($src) && ! file_exists($dest))
if ($result < 0)
{ {
$langs->load("errors"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest); dol_mkdir($dirodt);
return 0; $result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
return 0;
}
} }
$sql = array(); $sql = array();

View File

@ -337,6 +337,7 @@ if (! $error && $db->connected && $action == "set")
$dir[4] = $main_data_dir."/propale"; $dir[4] = $main_data_dir."/propale";
$dir[5] = $main_data_dir."/ficheinter"; $dir[5] = $main_data_dir."/ficheinter";
$dir[6] = $main_data_dir."/produit"; $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 // Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas
$num=count($dir); $num=count($dir);
@ -372,6 +373,27 @@ if (! $error && $db->connected && $action == "set")
print "</td></tr>"; print "</td></tr>";
print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</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>';
}
}
}
} }
} }