Fix debugs APIs

This commit is contained in:
Laurent Destailleur 2017-12-01 15:39:18 +01:00
parent e3671da37f
commit ce32da6217
21 changed files with 291 additions and 101 deletions

View File

@ -226,9 +226,13 @@ class Members extends DolibarrApi
// If there is no error, update() returns the number of affected rows // If there is no error, update() returns the number of affected rows
// so if the update is a no op, the return value is zero. // so if the update is a no op, the return value is zero.
if($member->update(DolibarrApiAccess::$user) >= 0) if($member->update(DolibarrApiAccess::$user) >= 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -204,9 +204,13 @@ class MembersTypes extends DolibarrApi
// If there is no error, update() returns the number of affected rows // If there is no error, update() returns the number of affected rows
// so if the update is a no op, the return value is zero. // so if the update is a no op, the return value is zero.
if ($membertype->update(DolibarrApiAccess::$user) >= 0) if ($membertype->update(DolibarrApiAccess::$user) >= 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -193,9 +193,13 @@ class Subscriptions extends DolibarrApi
} }
if ($subscription->update(DolibarrApiAccess::$user) > 0) if ($subscription->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -101,7 +101,7 @@ class DolibarrApi
// Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses // Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses
unset($object->linkedObjects); unset($object->linkedObjects);
unset($object->lines); // should be ->lines unset($object->lignes); // we don't want lignes, we want only ->lines
unset($object->fields); unset($object->fields);

View File

@ -184,7 +184,7 @@ class BlockedLog
*/ */
public function setObjectData(&$object, $action, $amounts) public function setObjectData(&$object, $action, $amounts)
{ {
global $user, $mysoc; global $langs, $user, $mysoc;
// Generic fields // Generic fields

View File

@ -217,10 +217,14 @@ class Categories extends DolibarrApi
$this->category->$field = $value; $this->category->$field = $value;
} }
if($this->category->update(DolibarrApiAccess::$user)) if ($this->category->update(DolibarrApiAccess::$user) > 0)
{
return $this->get ($id); return $this->get ($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -77,8 +77,6 @@ class AdvanceTargetingMailing extends CommonObject
2 => $langs->trans("StatusProspect2"), 2 => $langs->trans("StatusProspect2"),
3 => $langs->trans("StatusProspect3") 3 => $langs->trans("StatusProspect3")
); );
return 1;
} }
/** /**

View File

@ -1,7 +1,6 @@
<?php <?php
/* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro> /* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* *
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
@ -211,11 +210,12 @@ class FormAdvTargetEmailing extends Form
* *
* @return string HTML combo * @return string HTML combo
*/ */
function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array()) { function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
{
if (is_array ( $sqlqueryparam )) {
$options_array=array(); $options_array=array();
if (is_array($sqlqueryparam))
{
$param_list = array_keys ( $sqlqueryparam ); $param_list = array_keys ( $sqlqueryparam );
$InfoFieldList = explode ( ":", $param_list [0] ); $InfoFieldList = explode ( ":", $param_list [0] );
@ -251,8 +251,6 @@ class FormAdvTargetEmailing extends Form
} }
// $sql.= ' WHERE entity = '.$conf->entity; // $sql.= ' WHERE entity = '.$conf->entity;
$options_array = array();
dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG); dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {

View File

@ -149,6 +149,7 @@ class Proposals extends DolibarrApi
{ {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit)); $min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
while ($i < $min) while ($i < $min)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
@ -272,7 +273,7 @@ class Proposals extends DolibarrApi
$request_data->product_type, $request_data->product_type,
$request_data->rang, $request_data->rang,
$request_data->special_code, $request_data->special_code,
$fk_parent_line, $request_data->fk_parent_line,
$request_data->fk_fournprice, $request_data->fk_fournprice,
$request_data->pa_ht, $request_data->pa_ht,
$request_data->label, $request_data->label,
@ -387,11 +388,11 @@ class Proposals extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$request_data = (object) $request_data;
$updateRes = $this->propal->deleteline($lineid); $updateRes = $this->propal->deleteline($lineid);
if ($updateRes > 0) { if ($updateRes > 0) {
return $this->get($id); return $this->get($id);
} }
return false; return false;
} }
@ -421,10 +422,14 @@ class Proposals extends DolibarrApi
$this->propal->$field = $value; $this->propal->$field = $value;
} }
if($this->propal->update($id, DolibarrApiAccess::$user,1,'','','update')) if ($this->propal->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -1455,6 +1455,93 @@ class Propal extends CommonObject
} }
} }
/**
* Update database
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function update(User $user, $notrigger=0)
{
$error=0;
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->ref_client)) $this->ref_client=trim($this->ref_client);
if (isset($this->note) || isset($this->note_private)) $this->note_private=(isset($this->note_private) ? trim($this->note_private) : trim($this->note));
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
if (isset($this->import_key)) $this->import_key=trim($this->import_key);
// Check parameters
// Put here code to add control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
$sql.= " ref_client=".(isset($this->ref_client)?"'".$this->db->escape($this->ref_client)."'":"null").",";
$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
$sql.= " datep=".(strval($this->datep)!='' ? "'".$this->db->idate($this->datep)."'" : 'null').",";
$sql.= " date_valid=".(strval($this->date_validation)!='' ? "'".$this->db->idate($this->date_validation)."'" : 'null').",";
$sql.= " tva=".(isset($this->total_tva)?$this->total_tva:"null").",";
$sql.= " localtax1=".(isset($this->total_localtax1)?$this->total_localtax1:"null").",";
$sql.= " localtax2=".(isset($this->total_localtax2)?$this->total_localtax2:"null").",";
$sql.= " total_ht=".(isset($this->total_ht)?$this->total_ht:"null").",";
$sql.= " total=".(isset($this->total_ttc)?$this->total_ttc:"null").",";
$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
$sql.= " fk_user_author=".(isset($this->user_author_id)?$this->user_author_id:"null").",";
$sql.= " fk_user_valid=".(isset($this->user_valid)?$this->user_valid:"null").",";
$sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").",";
$sql.= " fk_cond_reglement=".(isset($this->cond_reglement_id)?$this->cond_reglement_id:"null").",";
$sql.= " fk_mode_reglement=".(isset($this->mode_reglement_id)?$this->mode_reglement_id:"null").",";
$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
$sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null")."";
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
$error++; $this->errors[]="Error ".$this->db->lasterror();
}
if (! $error)
{
if (! $notrigger)
{
// Call trigger
$result=$this->call_trigger('PROPAL_MODIFY', $user);
if ($result < 0) $error++;
// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/** /**
* Load array lines * Load array lines
* *

View File

@ -419,10 +419,14 @@ class Orders extends DolibarrApi
throw new RestException(400, 'Error while updating availability'); throw new RestException(400, 'Error while updating availability');
} }
if ($this->commande->update(DolibarrApiAccess::$user, 1, '', '', 'update')) if ($this->commande->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -191,9 +191,13 @@ class BankAccounts extends DolibarrApi
} }
if ($account->update(DolibarrApiAccess::$user) > 0) if ($account->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -483,10 +483,14 @@ class Contracts extends DolibarrApi
$this->contract->$field = $value; $this->contract->$field = $value;
} }
if($this->contract->update(DolibarrApiAccess::$user, 0)) if ($this->contract->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -391,7 +391,7 @@ abstract class CommonObject
/** /**
* Return full name (civility+' '+name+' '+lastname) * Return full name (civility+' '+name+' '+lastname)
* *
* @param Translate $langs Language object for translation of civility * @param Translate $langs Language object for translation of civility (used only if option is 1)
* @param int $option 0=No option, 1=Add civility * @param int $option 0=No option, 1=Add civility
* @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname
* @param int $maxlen Maximum length * @param int $maxlen Maximum length

View File

@ -378,7 +378,6 @@ class ExpenseReports extends DolibarrApi
* *
* @return int * @return int
*/ */
/*
function put($id, $request_data = NULL) { function put($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->expensereport->creer) { if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401); throw new RestException(401);
@ -397,12 +396,15 @@ class ExpenseReports extends DolibarrApi
$this->expensereport->$field = $value; $this->expensereport->$field = $value;
} }
if($this->expensereport->update(DolibarrApiAccess::$user)) if ($this->expensereport->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
return false;
} }
*/ else
{
throw new RestException(500, $this->task->error);
}
}
/** /**
* Delete Expense Report * Delete Expense Report
@ -480,6 +482,24 @@ class ExpenseReports extends DolibarrApi
); );
}*/ }*/
/**
* Clean sensible object datas
*
* @param object $object Object to clean
* @return array Array of cleaned object properties
*/
function _cleanObjectDatas($object) {
$object = parent::_cleanObjectDatas($object);
unset($object->barcode_type);
unset($object->barcode_type_code);
unset($object->barcode_type_label);
unset($object->barcode_type_coder);
return $object;
}
/** /**
* Validate fields before create or update object * Validate fields before create or update object
* *

View File

@ -38,7 +38,7 @@ class ExpenseReport extends CommonObject
var $fk_element = 'fk_expensereport'; var $fk_element = 'fk_expensereport';
var $picto = 'trip'; var $picto = 'trip';
var $lignes=array(); var $lines=array();
public $date_debut; public $date_debut;
@ -1934,7 +1934,7 @@ class ExpenseReport extends CommonObject
$tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); $tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type);
// calcul de tous les totaux de la ligne // calcul total of line
//$total_ttc = price2num($qty*$value_unit, 'MT'); //$total_ttc = price2num($qty*$value_unit, 'MT');
$tx_tva = $vatrate / 100; $tx_tva = $vatrate / 100;
@ -2565,7 +2565,7 @@ class ExpenseReportLine
$this->db->begin(); $this->db->begin();
// Mise a jour ligne en base // Update line in database
$sql = "UPDATE ".MAIN_DB_PREFIX."expensereport_det SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport_det SET";
$sql.= " comments='".$this->db->escape($this->comments)."'"; $sql.= " comments='".$this->db->escape($this->comments)."'";
$sql.= ",value_unit=".$this->value_unit; $sql.= ",value_unit=".$this->value_unit;

View File

@ -435,7 +435,7 @@ class Projects extends DolibarrApi
$this->project->$field = $value; $this->project->$field = $value;
} }
if($this->project->update(DolibarrApiAccess::$user, 0) > 0) if($this->project->update(DolibarrApiAccess::$user) >= 0)
{ {
return $this->get($id); return $this->get($id);
} }

View File

@ -440,7 +440,7 @@ class Tasks extends DolibarrApi
$this->task->$field = $value; $this->task->$field = $value;
} }
if($this->task->update(DolibarrApiAccess::$user, 0) > 0) if ($this->task->update(DolibarrApiAccess::$user) > 0)
{ {
return $this->get($id); return $this->get($id);
} }

View File

@ -216,10 +216,14 @@ class Users extends DolibarrApi
$this->useraccount->$field = $value; $this->useraccount->$field = $value;
} }
if ($this->useraccount->update(DolibarrApiAccess::$user, 1)) if ($this->useraccount->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id); return $this->get($id);
}
return false; else
{
throw new RestException(500, $this->task->error);
}
} }
/** /**

View File

@ -165,13 +165,38 @@ class CommandeTest extends PHPUnit_Framework_TestCase
return $localobject; return $localobject;
} }
/**
* testCommandeUpdate
*
* @param Object $localobject Commande
* @return Commande
*
* @depends testCommandeFetch
* The depends says test is run only if previous is ok
*/
public function testCommandUpdate($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject->note_private='New note private after update';
$result=$localobject->update($user);
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
return $localobject;
}
/** /**
* testCommandeValid * testCommandeValid
* *
* @param Object $localobject Order * @param Object $localobject Order
* @return void * @return Commande
* *
* @depends testCommandeFetch * @depends testCommandUpdate
* The depends says test is run only if previous is ok * The depends says test is run only if previous is ok
*/ */
public function testCommandeValid($localobject) public function testCommandeValid($localobject)
@ -193,7 +218,7 @@ class CommandeTest extends PHPUnit_Framework_TestCase
* testCommandeCancel * testCommandeCancel
* *
* @param Object $localobject Order * @param Object $localobject Order
* @return void * @return Commande
* *
* @depends testCommandeValid * @depends testCommandeValid
* The depends says test is run only if previous is ok * The depends says test is run only if previous is ok
@ -217,7 +242,7 @@ class CommandeTest extends PHPUnit_Framework_TestCase
* testCommandeOther * testCommandeOther
* *
* @param Object $localobject Order * @param Object $localobject Order
* @return void * @return int Order id
* *
* @depends testCommandeCancel * @depends testCommandeCancel
* The depends says test is run only if previous is ok * The depends says test is run only if previous is ok

View File

@ -142,7 +142,7 @@ class PropalTest extends PHPUnit_Framework_TestCase
* testPropalFetch * testPropalFetch
* *
* @param int $id Id of object * @param int $id Id of object
* @return void * @return Propal
* *
* @depends testPropalCreate * @depends testPropalCreate
* The depends says test is run only if previous is ok * The depends says test is run only if previous is ok
@ -164,14 +164,39 @@ class PropalTest extends PHPUnit_Framework_TestCase
} }
/** /**
* testPropalAddLine * testPropalUpdate
* *
* @param int $localobject Proposal * @param Propal $localobject Proposal
* @return void * @return Propal
* *
* @depends testPropalFetch * @depends testPropalFetch
* The depends says test is run only if previous is ok * The depends says test is run only if previous is ok
*/ */
public function testPropalUpdate($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject->note_private='New note private after update';
$result=$localobject->update($user);
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
return $localobject;
}
/**
* testPropalAddLine
*
* @param Propal $localobject Proposal
* @return Propal
*
* @depends testPropalUpdate
* The depends says test is run only if previous is ok
*/
public function testPropalAddLine($localobject) public function testPropalAddLine($localobject)
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
@ -191,8 +216,8 @@ class PropalTest extends PHPUnit_Framework_TestCase
/** /**
* testPropalValid * testPropalValid
* *
* @param Proposal $localobject Proposal * @param Propal $localobject Proposal
* @return Proposal * @return Propal
* *
* @depends testPropalAddLine * @depends testPropalAddLine
* The depends says test is run only if previous is ok * The depends says test is run only if previous is ok
@ -215,7 +240,7 @@ class PropalTest extends PHPUnit_Framework_TestCase
/** /**
* testPropalOther * testPropalOther
* *
* @param Proposal $localobject Proposal * @param Propal $localobject Proposal
* @return int * @return int
* *
* @depends testPropalValid * @depends testPropalValid