Skip to content

Commit

Permalink
FIXED #1824 Add ref_ext for Contact webservices
Browse files Browse the repository at this point in the history
Add possibility to use ref_ext to reference contact using webservice, field was present but not saved and not used to fetch object
  • Loading branch information
Arnaud Aujon authored and aaujon committed Feb 5, 2015
1 parent 212319b commit 65efa7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
9 changes: 7 additions & 2 deletions htdocs/contact/class/contact.class.php
Expand Up @@ -140,6 +140,7 @@ function create($user)
$sql.= ", statut";
$sql.= ", canvas";
$sql.= ", entity";
$sql.= ",ref_ext";
$sql.= ", import_key";
$sql.= ") VALUES (";
$sql.= "'".$this->db->idate($now)."',";
Expand All @@ -152,6 +153,7 @@ function create($user)
$sql.= " ".$this->statut.",";
$sql.= " ".(! empty($this->canvas)?"'".$this->canvas."'":"null").",";
$sql.= " ".$conf->entity.",";
$sql.= "'".$this->db->escape($this->ref_ext)."',";
$sql.= " ".(! empty($this->import_key)?"'".$this->import_key."'":"null");
$sql.= ")";

Expand Down Expand Up @@ -496,10 +498,12 @@ function update_perso($id, $user=0)
*
* @param int $id id du contact
* @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
* @param string $ref_ext External reference, not given by Dolibarr
* @return int -1 if KO, 0 if OK but not found, 1 if OK
*/
function fetch($id, $user=0)
function fetch($id, $user=0, $ref_ext='')
{
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
global $langs;

$langs->load("companies");
Expand All @@ -521,7 +525,8 @@ function fetch($id, $user=0)
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
$sql.= " WHERE c.rowid = ". $id;
if ($id) $sql.= " WHERE c.rowid = ". $id;
elseif ($ref_ext) $sql .= " WHERE c.ref_ext = '".$this->db->escape($ref_ext)."'";

dol_syslog(get_class($this)."::fetch sql=".$sql);
$resql=$this->db->query($sql);
Expand Down
22 changes: 12 additions & 10 deletions htdocs/webservices/server_contact.php
Expand Up @@ -83,6 +83,7 @@

$contact_fields = array(
'id' => array('name'=>'id','type'=>'xsd:string'),
'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'),
'lastname' => array('name'=>'lastname','type'=>'xsd:string'),
'firstname' => array('name'=>'firstname','type'=>'xsd:string'),
'address' => array('name'=>'address','type'=>'xsd:string'),
Expand Down Expand Up @@ -176,14 +177,14 @@
$server->register(
'getContact',
// Entry values
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
array('authentication'=>'tns:authentication','id'=>'xsd:string','ref_ext'=>'xsd:string'),
// Exit values
array('result'=>'tns:result','contact'=>'tns:contact'),
$ns,
$ns.'#getContact',
$styledoc,
$styleuse,
'WS to get contact'
'WS to get a contact'
);

// Register WSDL
Expand Down Expand Up @@ -232,16 +233,15 @@
* Get Contact
*
* @param array $authentication Array of authentication information
* @param int $id Id of object
* @param string $ref Ref of object
* @param ref_ext $ref_ext Ref external of object
* @param int $id Id of object
* @param string $ref_ext Ref external of object
* @return mixed
*/
function getContact($authentication,$id,$ref='',$ref_ext='')
function getContact($authentication,$id,$ref_ext)
{
global $db,$conf,$langs;

dol_syslog("Function: getContact login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
dol_syslog("Function: getContact login=".$authentication['login']." id=".$id." ref_ext=".$ref_ext);

if ($authentication['entity']) $conf->entity=$authentication['entity'];

Expand All @@ -251,18 +251,18 @@ function getContact($authentication,$id,$ref='',$ref_ext='')
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
if (! $error && ($id && $ref_ext))
{
$error++;
$errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
$errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
}

if (! $error)
{
$fuser->getrights();

$contact=new Contact($db);
$result=$contact->fetch($id,$ref,$ref_ext);
$result=$contact->fetch($id,0,$ref_ext);
if ($result > 0)
{
// Only internal user who have contact read permission
Expand All @@ -273,6 +273,7 @@ function getContact($authentication,$id,$ref='',$ref_ext='')
){
$contact_result_fields =array(
'id' => $contact->id,
'ref_ext' => $contact->ref_ext,
'lastname' => $contact->lastname,
'firstname' => $contact->firstname,
'address' => $contact->address,
Expand Down Expand Up @@ -383,6 +384,7 @@ function createContact($authentication,$contact)
$newobject=new Contact($db);

$newobject->id=$contact['id'];
$newobject->ref_ext=$contact['ref_ext'];
$newobject->civility_id=$contact['civility_id'];
$newobject->lastname=$contact['lastname'];
$newobject->firstname=$contact['firstname'];
Expand Down

0 comments on commit 65efa7d

Please sign in to comment.