From aabd9232482648832e25b4e293f64358e54c0879 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 21 Mar 2014 09:49:10 +0100 Subject: [PATCH 1/3] Try to remove warning --- htdocs/core/lib/functions.lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b6df6ff335c..ae1b91ef712 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1015,7 +1015,11 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) if (method_exists('DateTime','getTimestamp') && empty($conf->global->MAIN_OLD_DATE)) { - if (empty($gm)) $localtz = new DateTimeZone(date_default_timezone_get()); + if (empty($gm)) + { + $default_timezone=@date_default_timezone_get(); + $localtz = new DateTimeZone($default_timezone); + } else $localtz = new DateTimeZone('UTC'); $dt = new DateTime(null,$localtz); $dt->setDate($year,$month,$day); From c1411e65b77af791e2e4a795a0c1e9beac63a41e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 21 Mar 2014 10:13:29 +0100 Subject: [PATCH 2/3] Fix: Try to add code to provide easy way to fix warning on timezone not defined. --- htdocs/core/lib/functions.lib.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ae1b91ef712..bf398c389c0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -987,9 +987,9 @@ function dol_getdate($timestamp,$fast=false) * @param int $month Month (1 to 12) * @param int $day Day (1 to 31) * @param int $year Year - * @param int $gm 1=Input informations are GMT values, otherwise local to server TZ + * @param int $gm true or 1=Input informations are GMT values, false or 0 or 'server' = local to server TZ, 'user' = local to user TZ * @param int $check 0=No check on parameters (Can use day 32, etc...) - * @return int Date as a timestamp, '' if error + * @return int Date as a timestamp, '' if error * @see dol_print_date, dol_stringtotime, dol_getdate */ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) @@ -1015,9 +1015,21 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) if (method_exists('DateTime','getTimestamp') && empty($conf->global->MAIN_OLD_DATE)) { - if (empty($gm)) + if (empty($gm) || $gm === 'server') { - $default_timezone=@date_default_timezone_get(); + // If you can't set timezone of your PHP, set this constant. Better is to set it to UTC. + // In future, this constant will be forced to 'UTC' so PHP server timezone will not have effect anymore. + if (! empty($conf->global->MAIN_SERVER_TZ)) + { + if ($conf->global->MAIN_SERVER_TZ != 'auto') $default_timezone=$conf->global->MAIN_SERVER_TZ; + else $default_timezone=@date_default_timezone_get(); + } + else $default_timezone=@date_default_timezone_get(); + $localtz = new DateTimeZone($default_timezone); + } + else if ($gm === 'user') + { + $default_timezone=(empty($_SESSION["dol_tz_string"])?'UTC':$_SESSION["dol_tz_string"]); $localtz = new DateTimeZone($default_timezone); } else $localtz = new DateTimeZone('UTC'); From a884673637b6183af194f1631c260bd694399c4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 21 Mar 2014 13:29:13 +0100 Subject: [PATCH 3/3] Fix: A better to fix to manage automatic creation of code for import. --- .../modules/import/import_csv.modules.php | 23 ++++++++++--------- htdocs/core/modules/modSociete.class.php | 10 ++++---- test/phpunit/Example_import_company_1.csv | 3 ++- test/phpunit/FilesLibTest.php | 2 +- test/phpunit/ImportTest.php | 5 +++- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 62967076cb0..667d13a0f88 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -441,45 +441,46 @@ class ImportCsv extends ModeleImports { if (empty($newval)) $newval='0'; } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codeclient(0,0); $newval=$this->thirpartyobject->code_client; - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_client='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $newval=$this->thirpartyobject->get_codefournisseur(0,1); $newval=$this->thirpartyobject->code_fournisseur; - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_fournisseur='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codecompta('customer'); $newval=$this->thirpartyobject->code_compta; - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_compta='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifnull') + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') { - if (empty($newval) || strtolower($newval) == 'auto') + if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codecompta('supplier'); $newval=$this->thirpartyobject->code_compta_fournisseur; if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" //print 'code_compta_fournisseur='.$newval; } + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" } //print 'Val to use as insert is '.$newval.'
'; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index ea3be87aaee..96a3ee4d31b 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -401,14 +401,14 @@ class modSociete extends DolibarrModules 's.fk_typent'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionnaryCompanyType'), 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cpays.class.php','class'=>'Cpays','method'=>'fetch','dict'=>'DictionnaryCountry'), 's.fk_stcomm'=>array('rule'=>'zeroifnull'), - 's.code_client'=>array('rule'=>'getcustomercodeifnull'), - 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifnull'), - 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifnull'), - 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifnull') + 's.code_client'=>array('rule'=>'getcustomercodeifauto'), + 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'), + 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'), + 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto') ); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); - $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or auto",'s.code_fournisseur'=>"SU01-0001 or auto",'s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789'); + $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or empty or 'auto'",'s.code_fournisseur'=>"SU01-0001 or empty or 'auto'",'s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789'); // Import list of contact and attributes $r++; diff --git a/test/phpunit/Example_import_company_1.csv b/test/phpunit/Example_import_company_1.csv index 34f99a6b728..7ba7a797317 100755 --- a/test/phpunit/Example_import_company_1.csv +++ b/test/phpunit/Example_import_company_1.csv @@ -1,2 +1,3 @@ "Name* (s.nom)";"Status (s.status)";"Customer* (s.client)";"Supplier* (s.fournisseur)";"DateCreation (s.datec)";"CustomerCode (s.code_client)";"SupplierCode (s.code_fournisseur)";"Address (s.address)";"Zip (s.cp)";"Town (s.ville)";"Phone (s.tel)";"Fax (s.fax)";"Url (s.url)";"Email (s.email)";"IdProf1 (s.siret)";"IdProf2 (s.siren)";"IdProf3 (s.ape)";"IdProf4 (s.idprof4)";"VATIntraShort (s.tva_intra)";"Capital (s.capital)";"Note (s.note)";"ThirdPartyType (s.fk_typent)";"Effectif (s.fk_effectif)";"JuridicalStatus (s.fk_forme_juridique)";"ProspectLevel (s.fk_prospectlevel)";"ProspectStatus (s.fk_stcomm)";"DefaultLanguage (s.default_lang)";"BarCode (s.barcode)" -"MyBigCompanyImport1";1;3;1;01/01/00;"CU01-0001";"SU01-0001";"61 jump street";123456;"Big town";101010101;101010102;"http://mycompany.com";"test@mycompany.com";;;;;"FR0123456789";10000;"This is an example of note for record";2;3;1;"PL_MEDIUM";1;"en_US";123456789 +"MyBigCompanyImport1";1;3;1;01/01/00;"CU01-0001";"SU01-0001";"61 jump street";123456;"Big town";101010101;101010111;"http://mycompany.com";"test@mycompany.com";;;;;"FR0123456781";10000;"This is an example of note for record 1";2;3;1;"PL_MEDIUM";1;"en_US";123456781 +"MyBigCompanyImport2";1;3;1;01/01/00;"auto";;"62 jump street";123456;"Big town";101010102;101010112;"http://mycompany2.com";"test@mycompany2.com";;;;;"FR0123456782";10000;"This is an example of note for record 2";2;3;1;"PL_MEDIUM";1;"en_US";auto diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index d38f73326b2..1e8d91ed08d 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -162,7 +162,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase $file=dirname(__FILE__).'/Example_import_company_1.csv'; $result=dol_count_nb_of_line($file); print __METHOD__." result=".$result."\n"; - $this->assertEquals(2,$result); + $this->assertEquals(3,$result); return $result; } diff --git a/test/phpunit/ImportTest.php b/test/phpunit/ImportTest.php index 378031be257..86d23a850e1 100755 --- a/test/phpunit/ImportTest.php +++ b/test/phpunit/ImportTest.php @@ -125,7 +125,10 @@ class ImportTest extends PHPUnit_Framework_TestCase { $file=dirname(__FILE__).'/Example_import_company_1.csv'; - //if (! preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i','2012-03-23')) print 'eeeeeeeeeeee'; + // TODO + // Run import on file and check the record with field "auto" are filled + // according to option + return true; }