From 88ae0a79453915a69c033883399673a0d78e2385 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 28 Nov 2013 12:58:02 +0100 Subject: [PATCH] Fix: the rename function is bugged with some windows. I add a workaround. Fix: Add also a workaround for [ bug 1064 ] Date/Time in ICS incorrect. --- htdocs/admin/agenda_xcal.php | 25 ++++++++++++++++--- htdocs/comm/action/class/actioncomm.class.php | 16 ++++++------ htdocs/core/lib/files.lib.php | 15 +++++++++-- htdocs/langs/en_US/admin.lang | 2 ++ htdocs/langs/fr_FR/admin.lang | 2 ++ 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/htdocs/admin/agenda_xcal.php b/htdocs/admin/agenda_xcal.php index beb7960e4a0..135429e15d3 100644 --- a/htdocs/admin/agenda_xcal.php +++ b/htdocs/admin/agenda_xcal.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008-2013 Laurent Destailleur * Copyright (C) 2012-2013 Juanjo Menent * Copyright (C) 2012 Regis Houssin * @@ -48,8 +48,9 @@ if ($actionsave) $i+=dolibarr_set_const($db,'MAIN_AGENDA_XCAL_EXPORTKEY',trim(GETPOST('MAIN_AGENDA_XCAL_EXPORTKEY','alpha')),'chaine',0,'',$conf->entity); $i+=dolibarr_set_const($db,'MAIN_AGENDA_EXPORT_PAST_DELAY',trim(GETPOST('MAIN_AGENDA_EXPORT_PAST_DELAY','alpha')),'chaine',0,'',$conf->entity); $i+=dolibarr_set_const($db,'MAIN_AGENDA_EXPORT_CACHE',trim(GETPOST('MAIN_AGENDA_EXPORT_CACHE','alpha')),'chaine',0,'',$conf->entity); - - if ($i >= 3) + $i+=dolibarr_set_const($db,'AGENDA_EXPORT_FIX_TZ',trim(GETPOST('AGENDA_EXPORT_FIX_TZ','alpha')),'chaine',0,'',$conf->entity); + + if ($i >= 4) { $db->commit(); setEventMessage($langs->trans("SetupSaved")); @@ -117,6 +118,24 @@ print ""; print ''; +print '
'; + +print ""; + +print ""; +print '"; +print ""; +print ""; +print ""; +print '"; +print ""; +print ""; + +print '
'.$langs->trans("Parameter")."".$langs->trans("Value")."
'.$langs->trans("FixTZ").""; +print ''; +print '   '.$langs->trans("FillThisOnlyIfRequired"); +print "
'; + print '
'; print "trans("Save")."\">"; print "
"; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index b10bb5f90a3..2f2b65cb6ac 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -824,7 +824,8 @@ class ActionComm extends CommonObject require_once (DOL_DOCUMENT_ROOT ."/core/lib/xcal.lib.php"); require_once (DOL_DOCUMENT_ROOT ."/core/lib/date.lib.php"); - + require_once (DOL_DOCUMENT_ROOT ."/core/lib/files.lib.php"); + dol_syslog(get_class($this)."::build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".count($filters), LOG_DEBUG); // Check parameters @@ -943,8 +944,8 @@ class ActionComm extends CommonObject $event=array(); $event['uid']='dolibarragenda-'.$this->db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"]; $event['type']=$type; - $datestart=$this->db->jdate($obj->datep); - $dateend=$this->db->jdate($obj->datep2); + $datestart=$this->db->jdate($obj->datep)-(empty($conf->global->AGENDA_EXPORT_FIX_TZ)?0:($conf->global->AGENDA_EXPORT_FIX_TZ*3600)); + $dateend=$this->db->jdate($obj->datep2)-(empty($conf->global->AGENDA_EXPORT_FIX_TZ)?0:($conf->global->AGENDA_EXPORT_FIX_TZ*3600)); $duration=$obj->durationp; $event['summary']=$obj->label.($obj->socname?" (".$obj->socname.")":""); $event['desc']=$obj->note; @@ -963,8 +964,8 @@ class ActionComm extends CommonObject //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current $url=$urlwithroot.'/comm/action/fiche.php?id='.$obj->id; $event['url']=$url; - $event['created']=$this->db->jdate($obj->datec); - $event['modified']=$this->db->jdate($obj->datem); + $event['created']=$this->db->jdate($obj->datec)-(empty($conf->global->AGENDA_EXPORT_FIX_TZ)?0:($conf->global->AGENDA_EXPORT_FIX_TZ*3600)); + $event['modified']=$this->db->jdate($obj->datem)-(empty($conf->global->AGENDA_EXPORT_FIX_TZ)?0:($conf->global->AGENDA_EXPORT_FIX_TZ*3600)); if ($qualified && $datestart) { @@ -1011,10 +1012,11 @@ class ActionComm extends CommonObject if ($result >= 0) { - if (rename($outputfiletmp,$outputfile)) $result=1; + if (dol_move($outputfiletmp,$outputfile,0,1)) $result=1; else { - dol_syslog(get_class($this)."::build_exportfile failed to rename ".$outputfiletmp." to ".$outputfile, LOG_ERR); + $this->error='Failed to rename '.$outputfiletmp.' into '.$outputfile; + dol_syslog(get_class($this)."::build_exportfile ".$this->error, LOG_ERR); dol_delete_file($outputfiletmp,0,1); $result=-1; } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index ae1cf90a393..3df77ec722a 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -531,13 +531,24 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1) $result=false; dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists); - if ($overwriteifexists || ! dol_is_file($destfile)) + $destexists=dol_is_file($destfile); + if ($overwriteifexists || ! $destexists) { $newpathofsrcfile=dol_osencode($srcfile); $newpathofdestfile=dol_osencode($destfile); $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ - if (! $result) dol_syslog("files.lib.php::dol_move failed", LOG_WARNING); + if (! $result) + { + if ($destexists) + { + dol_syslog("files.lib.php::dol_move failed. We try to delete first and move after.", LOG_WARNING); + // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. + dol_delete_file($destfile); + $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ + } + else dol_syslog("files.lib.php::dol_move failed", LOG_WARNING); + } if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; @chmod($newpathofsrcfile, octdec($newmask)); } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 396bbaf4cb5..a5b23edf0d8 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1008,6 +1008,8 @@ XDebugInstalled=XDebug est chargé. XCacheInstalled=XCache is loaded. AddRefInList=Display customer/supplier ref into list (select list or combobox) and most of hyperlink FieldEdition=Edition of field %s +FixTZ=TimeZone fix +FillThisOnlyIfRequired=Example: +2 (fill only if timezone offset problems are experienced) ##### Module password generation PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase. PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually. diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 557c907ed3c..dddabbcfed9 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1050,6 +1050,8 @@ XDebugInstalled=XDebug est chargé. XCacheInstalled=XCache est chargé. AddRefInList=Afficher le code client/fournisseur dans les liste (déroulante ou autocomplétion) et dans la pluspart des hyperliens FieldEdition=Édition du champ %s +FixTZ=Correction du Timezone +FillThisOnlyIfRequired=Exemple: +2 (ne remplir que si un décalage d'heure est constaté dans l'export) ##### Module password generation PasswordGenerationStandard=Renvoie un mot de passe généré selon l'algorithme interne de Dolibarr : 8 caractères, chiffres et caractères en minuscules mélangés. PasswordGenerationNone=Ne propose pas de mots de passe générés. Le mot de passe est à saisir manuellement.