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
// so if the update is a no op, the return value is zero.
if($member->update(DolibarrApiAccess::$user) >= 0)
{
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
// so if the update is a no op, the return value is zero.
if ($membertype->update(DolibarrApiAccess::$user) >= 0)
{
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)
{
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
unset($object->linkedObjects);
unset($object->lines); // should be ->lines
unset($object->lignes); // we don't want lignes, we want only ->lines
unset($object->fields);

View File

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

View File

@ -217,10 +217,14 @@ class Categories extends DolibarrApi
$this->category->$field = $value;
}
if($this->category->update(DolibarrApiAccess::$user))
if ($this->category->update(DolibarrApiAccess::$user) > 0)
{
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"),
3 => $langs->trans("StatusProspect3")
);
return 1;
}
/**

View File

@ -1,20 +1,19 @@
<?php
/* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
*
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file comm/mailing/class/html.formadvtragetemaling.class.php
@ -50,31 +49,31 @@ class FormAdvTargetEmailing extends Form
*/
function multiselectProspectionStatus($selected_array = array(), $htmlname = 'cust_prospect_status') {
global $conf, $langs;
$options_array = array ();
$options_array = array();
$sql = "SELECT code, label";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_prospectlevel";
$sql .= " WHERE active > 0";
$sql .= " ORDER BY sortorder";
dol_syslog ( get_class ( $this ) . '::multiselectProspectionStatus sql=' . $sql, LOG_DEBUG );
$resql = $this->db->query ( $sql );
dol_syslog ( get_class( $this ) . '::multiselectProspectionStatus sql=' . $sql, LOG_DEBUG );
$resql = $this->db->query( $sql );
if ($resql) {
$num = $this->db->num_rows ( $resql );
$num = $this->db->num_rows( $resql );
$i = 0;
while ( $i < $num ) {
$obj = $this->db->fetch_object ( $resql );
$obj = $this->db->fetch_object( $resql );
$level = $langs->trans ( $obj->code );
$level = $langs->trans( $obj->code );
if ($level == $obj->code)
$level = $langs->trans ( $obj->label );
$options_array [$obj->code] = $level;
$level = $langs->trans( $obj->label );
$options_array[$obj->code] = $level;
$i ++;
}
} else {
dol_print_error ( $this->db );
dol_print_error($this->db);
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
/**
@ -211,11 +210,12 @@ class FormAdvTargetEmailing extends Form
*
* @return string HTML combo
*/
function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array()) {
if (is_array ( $sqlqueryparam )) {
$options_array=array();
function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array())
{
$options_array=array();
if (is_array($sqlqueryparam))
{
$param_list = array_keys ( $sqlqueryparam );
$InfoFieldList = explode ( ":", $param_list [0] );
@ -251,8 +251,6 @@ class FormAdvTargetEmailing extends Form
}
// $sql.= ' WHERE entity = '.$conf->entity;
$options_array = array();
dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {

View File

@ -149,6 +149,7 @@ class Proposals extends DolibarrApi
{
$num = $db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
while ($i < $min)
{
$obj = $db->fetch_object($result);
@ -272,7 +273,7 @@ class Proposals extends DolibarrApi
$request_data->product_type,
$request_data->rang,
$request_data->special_code,
$fk_parent_line,
$request_data->fk_parent_line,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
@ -374,25 +375,25 @@ class Proposals extends DolibarrApi
* @throws 404
*/
function deleteLine($id, $lineid) {
if(! DolibarrApiAccess::$user->rights->propal->creer) {
if(! DolibarrApiAccess::$user->rights->propal->creer) {
throw new RestException(401);
}
}
$result = $this->propal->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Proposal not found');
}
$result = $this->propal->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Proposal not found');
}
if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->propal->deleteline($lineid);
if ($updateRes > 0) {
return $this->get($id);
}
return false;
$updateRes = $this->propal->deleteline($lineid);
if ($updateRes > 0) {
return $this->get($id);
}
return false;
}
/**
@ -421,10 +422,14 @@ class Proposals extends DolibarrApi
$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 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
*

View File

@ -413,16 +413,20 @@ class Orders extends DolibarrApi
$this->commande->$field = $value;
}
// Update availability
if (!empty($this->commande->availability_id)) {
if ($this->commande->availability($this->commande->availability_id) < 0)
throw new RestException(400, 'Error while updating availability');
}
// Update availability
if (!empty($this->commande->availability_id)) {
if ($this->commande->availability($this->commande->availability_id) < 0)
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 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)
{
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;
}
if($this->contract->update(DolibarrApiAccess::$user, 0))
if ($this->contract->update(DolibarrApiAccess::$user) > 0)
{
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)
*
* @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 $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname
* @param int $maxlen Maximum length

View File

@ -378,7 +378,6 @@ class ExpenseReports extends DolibarrApi
*
* @return int
*/
/*
function put($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
@ -397,12 +396,15 @@ class ExpenseReports extends DolibarrApi
$this->expensereport->$field = $value;
}
if($this->expensereport->update(DolibarrApiAccess::$user))
if ($this->expensereport->update(DolibarrApiAccess::$user) > 0)
{
return $this->get($id);
return false;
}
else
{
throw new RestException(500, $this->task->error);
}
}
*/
/**
* 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
*

View File

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

View File

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

View File

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

View File

@ -216,10 +216,14 @@ class Users extends DolibarrApi
$this->useraccount->$field = $value;
}
if ($this->useraccount->update(DolibarrApiAccess::$user, 1))
if ($this->useraccount->update(DolibarrApiAccess::$user) > 0)
{
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;
}
/**
* 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
*
* @param Object $localobject Order
* @return void
* @return Commande
*
* @depends testCommandeFetch
* @depends testCommandUpdate
* The depends says test is run only if previous is ok
*/
public function testCommandeValid($localobject)
@ -193,7 +218,7 @@ class CommandeTest extends PHPUnit_Framework_TestCase
* testCommandeCancel
*
* @param Object $localobject Order
* @return void
* @return Commande
*
* @depends testCommandeValid
* The depends says test is run only if previous is ok
@ -217,7 +242,7 @@ class CommandeTest extends PHPUnit_Framework_TestCase
* testCommandeOther
*
* @param Object $localobject Order
* @return void
* @return int Order id
*
* @depends testCommandeCancel
* The depends says test is run only if previous is ok

View File

@ -142,7 +142,7 @@ class PropalTest extends PHPUnit_Framework_TestCase
* testPropalFetch
*
* @param int $id Id of object
* @return void
* @return Propal
*
* @depends testPropalCreate
* 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
* @return void
* @param Propal $localobject Proposal
* @return Propal
*
* @depends testPropalFetch
* 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)
{
global $conf,$user,$langs,$db;
@ -191,8 +216,8 @@ class PropalTest extends PHPUnit_Framework_TestCase
/**
* testPropalValid
*
* @param Proposal $localobject Proposal
* @return Proposal
* @param Propal $localobject Proposal
* @return Propal
*
* @depends testPropalAddLine
* The depends says test is run only if previous is ok
@ -215,7 +240,7 @@ class PropalTest extends PHPUnit_Framework_TestCase
/**
* testPropalOther
*
* @param Proposal $localobject Proposal
* @param Propal $localobject Proposal
* @return int
*
* @depends testPropalValid