Prepare fix #yogosha6443

This commit is contained in:
Laurent Destailleur
2021-06-30 17:14:19 +02:00
parent 7c2121c439
commit bda36337cd
14 changed files with 78 additions and 238 deletions

View File

@@ -1013,7 +1013,7 @@ class Setup extends DolibarrApi
$list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed; $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
$list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique; $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
$list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired; $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
$list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? unserialize($tab->param) : ''); $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? jsonOrUnserialize($tab->param) : ''); // This may be a string encoded with serialise() or json_encode()
$list[$tab->elementtype][$tab->name]['pos'] = $tab->pos; $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
$list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable; $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
$list[$tab->elementtype][$tab->name]['perms'] = $tab->perms; $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;

View File

@@ -777,10 +777,8 @@ class BlockedLog
public function dolDecodeBlockedData($data, $mode = 0) public function dolDecodeBlockedData($data, $mode = 0)
{ {
try { try {
//include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
//include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; //include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$aaa = unserialize($data); $aaa = unserialize($data);
//$aaa = unserialize($data);
} catch (Exception $e) { } catch (Exception $e) {
//print $e->getErrs); //print $e->getErrs);
} }

View File

@@ -163,8 +163,8 @@ if (GETPOST("account") || GETPOST("ref")) {
$sqls[] = $sql; $sqls[] = $sql;
// Social contributions // Social contributions
$sql = " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, cs.date_ech as dlr"; $sql = " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, cs.date_ech as dlr,";
$sql .= ", cs.fk_account"; $sql .= " 0 as socid, 'noname' as name, 0 as fournisseur";
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id";
$sql .= " WHERE cs.entity = ".$conf->entity; $sql .= " WHERE cs.entity = ".$conf->entity;
@@ -188,7 +188,18 @@ if (GETPOST("account") || GETPOST("ref")) {
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
while ($sqlobj = $db->fetch_object($resql)) { while ($sqlobj = $db->fetch_object($resql)) {
$tab_sqlobj[] = $sqlobj; $tmpobj = new stdClass();
$tmpobj->family = $sqlobj->family;
$tmpobj->objid = $sqlobj->objid;
$tmpobj->ref = $sqlobj->ref;
$tmpobj->total_ttc = $sqlobj->total_ttc;
$tmpobj->type = $sqlobj->type;
$tmpobj->dlt = $sqlobj->dlr;
$tmpobj->socid = $sqlobj->socid;
$tmpobj->name = $sqlobj->name;
$tmpobj->fournisseur = $sqlobj->fournisseur;
$tab_sqlobj[] = $tmpobj;
$tab_sqlobjOrder[] = $db->jdate($sqlobj->dlr); $tab_sqlobjOrder[] = $db->jdate($sqlobj->dlr);
} }
$db->free($resql); $db->free($resql);
@@ -201,15 +212,6 @@ if (GETPOST("account") || GETPOST("ref")) {
if (!$error) { if (!$error) {
array_multisort($tab_sqlobjOrder, $tab_sqlobj); array_multisort($tab_sqlobjOrder, $tab_sqlobj);
// Apply distinct filter
foreach ($tab_sqlobj as $key => $value) {
$tab_sqlobj[$key] = "'".serialize($value)."'";
}
$tab_sqlobj = array_unique($tab_sqlobj);
foreach ($tab_sqlobj as $key => $value) {
$tab_sqlobj[$key] = unserialize(trim($value, "'"));
}
$num = count($tab_sqlobj); $num = count($tab_sqlobj);
$i = 0; $i = 0;

View File

@@ -8167,15 +8167,6 @@ abstract class CommonObject
} else { } else {
$queryarray[$field] = $this->db->idate($this->{$field}); $queryarray[$field] = $this->db->idate($this->{$field});
} }
} elseif ($this->isArray($info)) {
if (!empty($this->{$field})) {
if (!is_array($this->{$field})) {
$this->{$field} = array($this->{$field});
}
$queryarray[$field] = serialize($this->{$field});
} else {
$queryarray[$field] = null;
}
} elseif ($this->isDuration($info)) { } elseif ($this->isDuration($info)) {
// $this->{$field} may be null, '', 0, '0', 123, '123' // $this->{$field} may be null, '', 0, '0', 123, '123'
if ((isset($this->{$field}) && $this->{$field} != '') || !empty($info['notnull'])) { if ((isset($this->{$field}) && $this->{$field} != '') || !empty($info['notnull'])) {
@@ -8236,16 +8227,6 @@ abstract class CommonObject
} else { } else {
$this->{$field} = $db->jdate($obj->{$field}); $this->{$field} = $db->jdate($obj->{$field});
} }
} elseif ($this->isArray($info)) {
if (!empty($obj->{$field})) {
$this->{$field} = @unserialize($obj->{$field});
// Hack for data not in UTF8
if ($this->{$field } === false) {
@unserialize(utf8_decode($obj->{$field}));
}
} else {
$this->{$field} = array();
}
} elseif ($this->isInt($info)) { } elseif ($this->isInt($info)) {
if ($field == 'rowid') { if ($field == 'rowid') {
$this->id = (int) $obj->{$field}; $this->id = (int) $obj->{$field};

View File

@@ -936,7 +936,7 @@ class ExtraFields
$this->attribute_computed[$tab->name] = $tab->fieldcomputed; $this->attribute_computed[$tab->name] = $tab->fieldcomputed;
$this->attribute_unique[$tab->name] = $tab->fieldunique; $this->attribute_unique[$tab->name] = $tab->fieldunique;
$this->attribute_required[$tab->name] = $tab->fieldrequired; $this->attribute_required[$tab->name] = $tab->fieldrequired;
$this->attribute_param[$tab->name] = ($tab->param ? unserialize($tab->param) : ''); $this->attribute_param[$tab->name] = ($tab->param ? jsonOrUnserialize($tab->param) : '');
$this->attribute_pos[$tab->name] = $tab->pos; $this->attribute_pos[$tab->name] = $tab->pos;
$this->attribute_alwayseditable[$tab->name] = $tab->alwayseditable; $this->attribute_alwayseditable[$tab->name] = $tab->alwayseditable;
$this->attribute_perms[$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); $this->attribute_perms[$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms);
@@ -954,7 +954,7 @@ class ExtraFields
$this->attributes[$tab->elementtype]['computed'][$tab->name] = $tab->fieldcomputed; $this->attributes[$tab->elementtype]['computed'][$tab->name] = $tab->fieldcomputed;
$this->attributes[$tab->elementtype]['unique'][$tab->name] = $tab->fieldunique; $this->attributes[$tab->elementtype]['unique'][$tab->name] = $tab->fieldunique;
$this->attributes[$tab->elementtype]['required'][$tab->name] = $tab->fieldrequired; $this->attributes[$tab->elementtype]['required'][$tab->name] = $tab->fieldrequired;
$this->attributes[$tab->elementtype]['param'][$tab->name] = ($tab->param ? unserialize($tab->param) : ''); $this->attributes[$tab->elementtype]['param'][$tab->name] = ($tab->param ? jsonOrUnserialize($tab->param) : '');
$this->attributes[$tab->elementtype]['pos'][$tab->name] = $tab->pos; $this->attributes[$tab->elementtype]['pos'][$tab->name] = $tab->pos;
$this->attributes[$tab->elementtype]['alwayseditable'][$tab->name] = $tab->alwayseditable; $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name] = $tab->alwayseditable;
$this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); $this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms);

View File

@@ -37,7 +37,7 @@ if (class_exists($keyforclass)) {
/* /*
* case 'sellist': * case 'sellist':
* $tmp=''; * $tmp='';
* $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
* if ($tmpparam['options'] && is_array($tmpparam['options'])) { * if ($tmpparam['options'] && is_array($tmpparam['options'])) {
* $tmpkeys=array_keys($tmpparam['options']); * $tmpkeys=array_keys($tmpparam['options']);
* $tmp=array_shift($tmpkeys); * $tmp=array_shift($tmpkeys);

View File

@@ -39,7 +39,7 @@ if ($resql) { // This can fail when class is used on old database (during mig
case 'checkbox': case 'checkbox':
case 'select': case 'select':
if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT)) { if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT)) {
$tmpparam = unserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...) $tmpparam = jsonOrUnserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...)
if ($tmpparam['options'] && is_array($tmpparam['options'])) { if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$typeFilter = "Select:".$obj->param; $typeFilter = "Select:".$obj->param;
} }
@@ -47,7 +47,7 @@ if ($resql) { // This can fail when class is used on old database (during mig
break; break;
case 'sellist': case 'sellist':
$tmp = ''; $tmp = '';
$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null $tmpparam = jsonOrUnserialize($obj->param); // $tmp may be array 'options' => array 'c_currencies:code_iso:code_iso' => null
if ($tmpparam['options'] && is_array($tmpparam['options'])) { if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$tmpkeys = array_keys($tmpparam['options']); $tmpkeys = array_keys($tmpparam['options']);
$tmp = array_shift($tmpkeys); $tmp = array_shift($tmpkeys);

View File

@@ -993,7 +993,7 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
function dol_clone($object, $native = 0) function dol_clone($object, $native = 0)
{ {
if (empty($native)) { if (empty($native)) {
$myclone = unserialize(serialize($object)); $myclone = unserialize(serialize($object)); // serialize then unserialize is hack to be sure to have a new object for all fields
} else { } else {
$myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep the reference (refering to the same target/variable) $myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep the reference (refering to the same target/variable)
} }
@@ -10301,9 +10301,10 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
*/ */
function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $texttoshow = '') function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $texttoshow = '')
{ {
/*
global $conf; global $conf;
/*if (!empty($conf->dol_no_mouse_hover)) { if (!empty($conf->dol_no_mouse_hover)) {
$showonlyonhover = 0; $showonlyonhover = 0;
}*/ }*/
@@ -10315,3 +10316,19 @@ function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $tex
return $result; return $result;
} }
/**
* Decode an encode string. The string can be encoded in json format (recommended) or with serialize (avoid this)
*
* @param string $stringtodecode String to decode (json or serialize coded)
*/
function jsonOrUnserialize($stringtodecode)
{
$result = json_decode($stringtodecode);
if ($result === null) {
$result = unserialize($stringtodecode);
}
return $result;
}

View File

@@ -277,8 +277,8 @@ class ExportCsv extends ModeleExports
$newvalue = $this->csvClean($newvalue, $outputlangs->charset_output); $newvalue = $this->csvClean($newvalue, $outputlangs->charset_output);
if (preg_match('/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7)) { if (preg_match('/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
$array = unserialize($typefield); $array = json_decode($typefield, true);
$array = $array['options']; $array = $array['options'];
$newvalue = $array[$newvalue]; $newvalue = $array[$newvalue];
} }

View File

@@ -315,8 +315,8 @@ class ExportExcel2007 extends ModeleExports
$newvalue = $this->excel_clean($newvalue); $newvalue = $this->excel_clean($newvalue);
$typefield = isset($array_types[$code]) ? $array_types[$code] : ''; $typefield = isset($array_types[$code]) ? $array_types[$code] : '';
if (preg_match('/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7)) { if (preg_match('/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
$array = unserialize($typefield); $array = json_decode($typefield, true);
$array = $array['options']; $array = $array['options'];
$newvalue = $array[$newvalue]; $newvalue = $array[$newvalue];
} }

View File

@@ -252,8 +252,8 @@ class ExportTsv extends ModeleExports
$newvalue = $this->tsv_clean($newvalue, $outputlangs->charset_output); $newvalue = $this->tsv_clean($newvalue, $outputlangs->charset_output);
if (preg_match('/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7)) { if (preg_match('/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
$array = unserialize($typefield); $array = json_decode($typefield, true);
$array = $array['options']; $array = $array['options'];
$newvalue = $array[$newvalue]; $newvalue = $array[$newvalue];
} }

View File

@@ -285,7 +285,7 @@ class modFournisseur extends DolibarrModules
$r++; $r++;
$this->export_code[$r] = $this->rights_class.'_'.$r; $this->export_code[$r] = $this->rights_class.'_'.$r;
$this->export_label[$r] = 'Vendor invoices and lines of invoices'; $this->export_label[$r] = 'Vendor invoices and lines of invoices';
$this->export_icon[$r] = 'bill'; $this->export_icon[$r] = 'invoice';
$this->export_permission[$r] = array(array("fournisseur", "facture", "export")); $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
$this->export_fields_array[$r] = array( $this->export_fields_array[$r] = array(
's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
@@ -328,81 +328,14 @@ class modFournisseur extends DolibarrModules
); );
$this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
// Add extra fields object // Add extra fields object
$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")"; $keyforselect = 'facture_fourn';
$resql = $this->db->query($sql); $keyforelement = 'invoice';
if ($resql) { // This can fail when class is used on old database (during migration for example) $keyforaliasextra = 'extra';
while ($obj = $this->db->fetch_object($resql)) { include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
$fieldname = 'extra.'.$obj->name; $keyforselect = 'facture_fourn_det';
$fieldlabel = ucfirst($obj->label); $keyforelement = 'invoice_line';
$typeFilter = "Text"; $keyforaliasextra = 'extraline';
switch ($obj->type) { include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
case 'int':
case 'double':
case 'price':
$typeFilter = "Numeric";
break;
case 'date':
case 'datetime':
$typeFilter = "Date";
break;
case 'boolean':
$typeFilter = "Boolean";
break;
case 'sellist':
$tmp = '';
$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$var = array_keys($tmpparam['options']);
$tmp = array_shift($var);
}
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
$typeFilter = "List:".$tmp;
}
break;
}
$this->export_fields_array[$r][$fieldname] = $fieldlabel;
$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
$this->export_entities_array[$r][$fieldname] = 'invoice';
}
}
// End add extra fields
// Add extra fields line
$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
$resql = $this->db->query($sql);
if ($resql) { // This can fail when class is used on old database (during migration for example)
while ($obj = $this->db->fetch_object($resql)) {
$fieldname = 'extraline.'.$obj->name;
$fieldlabel = ucfirst($obj->label);
$typeFilter = "Text";
switch ($obj->type) {
case 'int':
case 'double':
case 'price':
$typeFilter = "Numeric";
break;
case 'date':
case 'datetime':
$typeFilter = "Date";
break;
case 'boolean':
$typeFilter = "Boolean";
break;
case 'sellist':
$tmp = '';
$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$tmp = array_shift(array_keys($tmpparam['options']));
}
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
$typeFilter = "List:".$tmp;
}
break;
}
$this->export_fields_array[$r][$fieldname] = $fieldlabel;
$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
$this->export_entities_array[$r][$fieldname] = 'invoice_line';
}
}
// End add extra fields line // End add extra fields line
$this->export_sql_start[$r] = 'SELECT DISTINCT '; $this->export_sql_start[$r] = 'SELECT DISTINCT ';
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
@@ -426,7 +359,7 @@ class modFournisseur extends DolibarrModules
$r++; $r++;
$this->export_code[$r] = $this->rights_class.'_'.$r; $this->export_code[$r] = $this->rights_class.'_'.$r;
$this->export_label[$r] = 'Factures fournisseurs et reglements'; $this->export_label[$r] = 'Factures fournisseurs et reglements';
$this->export_icon[$r] = 'bill'; $this->export_icon[$r] = 'invoice';
$this->export_permission[$r] = array(array("fournisseur", "facture", "export")); $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
$this->export_fields_array[$r] = array( $this->export_fields_array[$r] = array(
's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
@@ -465,43 +398,10 @@ class modFournisseur extends DolibarrModules
'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'); 'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project');
$this->export_dependencies_array[$r] = array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $this->export_dependencies_array[$r] = array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
// Add extra fields object // Add extra fields object
$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")"; $keyforselect = 'facture_fourn';
$resql = $this->db->query($sql); $keyforelement = 'invoice';
if ($resql) { // This can fail when class is used on old database (during migration for example) $keyforaliasextra = 'extra';
while ($obj = $this->db->fetch_object($resql)) { include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
$fieldname = 'extra.'.$obj->name;
$fieldlabel = ucfirst($obj->label);
$typeFilter = "Text";
switch ($obj->type) {
case 'int':
case 'double':
case 'price':
$typeFilter = "Numeric";
break;
case 'date':
case 'datetime':
$typeFilter = "Date";
break;
case 'boolean':
$typeFilter = "Boolean";
break;
case 'sellist':
$tmp = '';
$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$array_keys = array_keys($tmpparam['options']);
$tmp = array_shift($array_keys);
}
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
$typeFilter = "List:".$tmp;
}
break;
}
$this->export_fields_array[$r][$fieldname] = $fieldlabel;
$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
$this->export_entities_array[$r][$fieldname] = 'invoice';
}
}
// End add extra fields object // End add extra fields object
$this->export_sql_start[$r] = 'SELECT DISTINCT '; $this->export_sql_start[$r] = 'SELECT DISTINCT ';
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
@@ -564,83 +464,16 @@ class modFournisseur extends DolibarrModules
); );
$this->export_dependencies_array[$r] = array('order_line'=>'fd.rowid', 'product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $this->export_dependencies_array[$r] = array('order_line'=>'fd.rowid', 'product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
// Add extra fields object // Add extra fields object
$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")"; $keyforselect = 'commande_fournisseur';
$resql = $this->db->query($sql); $keyforelement = 'order';
if ($resql) { // This can fail when class is used on old database (during migration for example) $keyforaliasextra = 'extra';
while ($obj = $this->db->fetch_object($resql)) { include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
$fieldname = 'extra.'.$obj->name;
$fieldlabel = ucfirst($obj->label);
$typeFilter = "Text";
switch ($obj->type) {
case 'int':
case 'double':
case 'price':
$typeFilter = "Numeric";
break;
case 'date':
case 'datetime':
$typeFilter = "Date";
break;
case 'boolean':
$typeFilter = "Boolean";
break;
case 'sellist':
$tmp = '';
$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
$tmpkey = array_keys($tmpparam['options']);
if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$tmp = array_shift($tmpkey);
}
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
$typeFilter = "List:".$tmp;
}
break;
}
$this->export_fields_array[$r][$fieldname] = $fieldlabel;
$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
$this->export_entities_array[$r][$fieldname] = 'order';
}
}
// End add extra fields object // End add extra fields object
// Add extra fields line // Add extra fields line
$sql = "SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")"; $keyforselect = 'commande_fournisseurdet';
$resql = $this->db->query($sql); $keyforelement = 'order_line';
if ($resql) { // This can fail when class is used on old database (during migration for example) $keyforaliasextra = 'extraline';
while ($obj = $this->db->fetch_object($resql)) { include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
$fieldname = 'extraline.'.$obj->name;
$fieldlabel = ucfirst($obj->label);
$typeFilter = "Text";
switch ($obj->type) {
case 'int':
case 'double':
case 'price':
$typeFilter = "Numeric";
break;
case 'date':
case 'datetime':
$typeFilter = "Date";
break;
case 'boolean':
$typeFilter = "Boolean";
break;
case 'sellist':
$tmp = '';
$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
if ($tmpparam['options'] && is_array($tmpparam['options'])) {
$tmpparam_param_key = array_keys($tmpparam['options']);
$tmp = array_shift($tmpparam_param_key);
}
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
$typeFilter = "List:".$tmp;
}
break;
}
$this->export_fields_array[$r][$fieldname] = $fieldlabel;
$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
$this->export_entities_array[$r][$fieldname] = 'order_line';
}
}
// End add extra fields line // End add extra fields line
$this->export_sql_start[$r] = 'SELECT DISTINCT '; $this->export_sql_start[$r] = 'SELECT DISTINCT ';
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';

View File

@@ -18,8 +18,8 @@
CREATE TABLE llx_oauth_token ( CREATE TABLE llx_oauth_token (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
service varchar(36), -- What king of key or token: 'Google', 'Stripe', 'auth-public-key', ... service varchar(36), -- What king of key or token: 'Google', 'Stripe', 'auth-public-key', ...
token text, -- token in serialize() format, of an object StdOAuth2Token of library phpoauth2 token text, -- token in serialize format, of an object StdOAuth2Token of library phpoauth2. Deprecated, use tokenstring instead.
tokenstring text, -- token in text or json format. Value depends on 'service'. For example for an OAUTH service: '{"access_token": "sk_test_cccc", "refresh_token": "rt_aaa", "token_type": "bearer", ..., "scope": "read_write"} tokenstring text, -- token in json or text format. Value depends on 'service'. For example for an OAUTH service: '{"access_token": "sk_test_cccc", "refresh_token": "rt_aaa", "token_type": "bearer", ..., "scope": "read_write"}
fk_soc integer, -- Id of thirdparty in llx_societe fk_soc integer, -- Id of thirdparty in llx_societe
fk_user integer, -- Id of user in llx_user fk_user integer, -- Id of user in llx_user
fk_adherent integer, -- Id of member in llx_adherent fk_adherent integer, -- Id of member in llx_adherent

View File

@@ -161,6 +161,15 @@ class JsonLibTest extends PHPUnit\Framework\TestCase
$this->savlangs=$langs; $this->savlangs=$langs;
$this->savdb=$db; $this->savdb=$db;
// Try to decode a string encoded with serialize
$encoded = 'a:1:{s:7:"options";a:3:{s:3:"app";s:11:"Application";s:6:"system";s:6:"System";s:6:"option";s:6:"Option";}}';
$decoded=json_decode($encoded, true);
$this->assertEquals(null, $decoded, 'test to json_decode() a string that was encoded with serialize()');
$encoded = 'rubishstring!aa{bcd';
$decoded=json_decode($encoded, true);
$this->assertEquals(null, $decoded, 'test to json_decode() a string that was encoded with serialize()');
// Do a test with an array starting with 0 // Do a test with an array starting with 0
$arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); $arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "'));
$arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]'; $arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]';