This commit is contained in:
fhenry 2013-05-01 14:38:43 +02:00
commit f3480bf502
8 changed files with 35 additions and 33 deletions

View File

@ -938,7 +938,7 @@ class DoliDBMysqli
* *
* @param string $table Name of table * @param string $table Name of table
* @param string $field Optionnel : Name of field if we want description of field * @param string $field Optionnel : Name of field if we want description of field
* @return resource Resource * @return resultset Resultset x (x->Field, x->Type, ...)
*/ */
function DDLDescTable($table,$field="") function DDLDescTable($table,$field="")
{ {

View File

@ -1169,7 +1169,7 @@ class DoliDBPgsql
* *
* @param string $table Name of table * @param string $table Name of table
* @param string $field Optionnel : Name of field if we want description of field * @param string $field Optionnel : Name of field if we want description of field
* @return resource Resource * @return resultset Resultset x (x->attname)
*/ */
function DDLDescTable($table,$field="") function DDLDescTable($table,$field="")
{ {

View File

@ -751,12 +751,14 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n
{ {
$error=0; $error=0;
//print "x".$file." ".$disableglob; //print "x".$file." ".$disableglob;exit;
$ok=true; $ok=true;
$file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset
if (empty($disableglob) && ! empty($file_osencoded)) if (empty($disableglob) && ! empty($file_osencoded))
{ {
foreach (glob($file_osencoded) as $filename) $globencoded=str_replace('[','\[',$file_osencoded);
$globencoded=str_replace(']','\]',$globencoded);
foreach (glob($globencoded) as $filename)
{ {
if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr
else $ok=unlink($filename); // The unlink encapsulated by dolibarr else $ok=unlink($filename); // The unlink encapsulated by dolibarr

View File

@ -66,8 +66,7 @@ class ImportCsv extends ModeleImports
global $conf,$langs; global $conf,$langs;
$this->db = $db; $this->db = $db;
$this->separator=','; // Change also function cleansep $this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
if (! empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->IMPORT_CSV_SEPARATOR_TO_USE;
$this->enclosure='"'; $this->enclosure='"';
$this->escape='"'; $this->escape='"';
@ -579,7 +578,7 @@ class ImportCsv extends ModeleImports
//var_dump($objimport->array_import_convertvalue); exit; //var_dump($objimport->array_import_convertvalue); exit;
// Build SQL request // Build SQL request
if (! tablewithentity($tablename)) if (! tablewithentity($tablename))
{ {
$sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key';
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias];
@ -651,25 +650,16 @@ function cleansep($value)
function tablewithentity($table) function tablewithentity($table)
{ {
global $db; global $db;
$sql = "SHOW COLUMNS FROM ".$table." LIKE 'entity'";
$resql=$db->query($sql); $resql=$db->DDLDescTable($table,'entity');
if ($resql) if ($resql)
{ {
$numrows=$db->num_rows($resql); $i=0;
if ($numrows) $obj=$db->fetch_object($resql);
{ if ($obj) return 1;
return 1; else return 0;
}
else
{
return 0;
}
}
else
{
return -1;
} }
else return -1;
} }
?> ?>

View File

@ -355,7 +355,7 @@ class modSociete extends DolibarrModules
$this->import_label[$r]='ImportDataset_company_2'; $this->import_label[$r]='ImportDataset_company_2';
$this->import_icon[$r]='contact'; $this->import_icon[$r]='contact';
$this->import_entities_array[$r]=array('s.fk_soc'=>'company'); // We define here only fields that use another icon that the one defined into import_icon $this->import_entities_array[$r]=array('s.fk_soc'=>'company'); // We define here only fields that use another icon that the one defined into import_icon
$this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople'); // List of tables to insert into (insert done in same order) $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople','extra'=>MAIN_DB_PREFIX.'socpeople_extrafields'); // List of tables to insert into (insert done in same order)
$this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName*','s.civilite'=>'UserTitle','s.name'=>"Name*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",'s.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note'=>"Note",'s.datec'=>"DateCreation"); $this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName*','s.civilite'=>'UserTitle','s.name'=>"Name*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",'s.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note'=>"Note",'s.datec'=>"DateCreation");
// Add extra fields // Add extra fields
$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'contact'"; $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'contact'";
@ -370,7 +370,7 @@ class modSociete extends DolibarrModules
} }
} }
// End add extra fields // End add extra fields
$this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'socpeople'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this->import_convertvalue_array[$r]=array( $this->import_convertvalue_array[$r]=array(
's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'), 's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cpays.class.php','class'=>'Cpays','method'=>'fetch','dict'=>'DictionnaryCountry'), 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cpays.class.php','class'=>'Cpays','method'=>'fetch','dict'=>'DictionnaryCountry'),

View File

@ -33,7 +33,7 @@
else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); }
else size.val('').attr('disabled','disabled'); else size.val('').attr('disabled','disabled');
} }
init_typeoffields(''); init_typeoffields('<?php echo GETPOST('type'); ?>');
jQuery("#type").change(function() { jQuery("#type").change(function() {
init_typeoffields($(this).val()); init_typeoffields($(this).val());
}); });

View File

@ -1017,7 +1017,7 @@ if ($step == 4 && $datatoimport)
} }
else else
{ {
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryFieldHaveNoSource")).'">'.$langs->trans("NextStep").'</a>'; print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SomeMandatoryFieldHaveNoSource")).'">'.$langs->trans("NextStep").'</a>';
} }
} }
@ -1281,7 +1281,7 @@ if ($step == 5 && $datatoimport)
} }
else else
{ {
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("RunSimulateImportFile").'</a>'; print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("RunSimulateImportFile").'</a>';
} }
print '</center>'; print '</center>';
} }

View File

@ -326,7 +326,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
// Again to test with overwriting=1 // Again to test with overwriting=1
$result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1); $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1);
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
$this->assertGreaterThanOrEqual(1,$result); // Should be 1 $this->assertGreaterThanOrEqual(1,$result,'copy destination already exists, overwrite'); // Should be 1
// Again to test with overwriting=1 // Again to test with overwriting=1
$result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1); $result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1);
@ -340,7 +340,17 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
// Again to test no erreor when deleteing a non existing file // Again to test no erreor when deleteing a non existing file
$result=dol_delete_file($conf->admin->dir_temp.'/file2.csv'); $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv');
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
$this->assertTrue($result); $this->assertTrue($result,'delete file that does not exists');
// Test copy with special char / delete with blob
$result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv',0,1);
print __METHOD__." result=".$result."\n";
$this->assertGreaterThanOrEqual(1,$result,'copy file with special char, overwrite'); // Should be 1
// Try to delete using a glob criteria
$result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv');
print __METHOD__." result=".$result."\n";
$this->assertTrue($result,'delete file using glob criteria');
} }
/** /**