Skip to content

Commit

Permalink
Fix maxi debug of APIs (clean output fields)
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 21, 2017
1 parent 6a96a97 commit aad0da2
Show file tree
Hide file tree
Showing 21 changed files with 828 additions and 46 deletions.
4 changes: 2 additions & 2 deletions htdocs/adherents/class/api_members.class.php
Expand Up @@ -225,13 +225,13 @@ function put($id, $request_data = null)

// 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)
if ($member->update(DolibarrApiAccess::$user) >= 0)
{
return $this->get($id);
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $member->error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion htdocs/adherents/class/api_memberstypes.class.php
Expand Up @@ -209,7 +209,7 @@ function put($id, $request_data = null)
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $membertype->error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion htdocs/adherents/class/api_subscriptions.class.php
Expand Up @@ -198,7 +198,7 @@ function put($id, $request_data = null)
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $subscription->error);
}
}

Expand Down
49 changes: 38 additions & 11 deletions htdocs/api/class/api.class.php
Expand Up @@ -97,14 +97,14 @@ function _cleanObjectDatas($object) {
// Remove $db object property for object
unset($object->db);
unset($object->ismultientitymanaged);
unset($object->restrictiononfksoc);

// Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses
unset($object->linkedObjects);

unset($object->lignes); // we don't want lignes, we want only ->lines

unset($object->fields);

unset($object->oldline);

unset($object->error);
Expand Down Expand Up @@ -141,6 +141,8 @@ function _cleanObjectDatas($object) {
unset($object->picto);

unset($object->facturee); // Replace with billed
unset($object->fieldsforcombobox);
unset($object->comments);

unset($object->skip_update_total);
unset($object->context);
Expand All @@ -157,23 +159,48 @@ function _cleanObjectDatas($object) {
unset($object->oldcopy);

// If object has lines, remove $db property
if(isset($object->lines) && count($object->lines) > 0) {
if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
$nboflines = count($object->lines);
for ($i=0; $i < $nboflines; $i++)
{
$this->_cleanObjectDatas($object->lines[$i]);

unset($object->lines[$i]->contact);
unset($object->lines[$i]->contact_id);
unset($object->lines[$i]->country);
unset($object->lines[$i]->country_id);
unset($object->lines[$i]->country_code);
unset($object->lines[$i]->mode_reglement_id);
unset($object->lines[$i]->mode_reglement_code);
unset($object->lines[$i]->mode_reglement);
unset($object->lines[$i]->cond_reglement_id);
unset($object->lines[$i]->cond_reglement_code);
unset($object->lines[$i]->cond_reglement);
unset($object->lines[$i]->fk_delivery_address);
unset($object->lines[$i]->fk_projet);
unset($object->lines[$i]->thirdparty);
unset($object->lines[$i]->user);
unset($object->lines[$i]->model_pdf);
unset($object->lines[$i]->modelpdf);
unset($object->lines[$i]->note_public);
unset($object->lines[$i]->note_private);
unset($object->lines[$i]->fk_incoterms);
unset($object->lines[$i]->libelle_incoterms);
unset($object->lines[$i]->location_incoterms);
unset($object->lines[$i]->name);
unset($object->lines[$i]->lastname);
unset($object->lines[$i]->firstname);
unset($object->lines[$i]->civility_id);
unset($object->lines[$i]->fk_multicurrency);
unset($object->lines[$i]->multicurrency_code);
unset($object->lines[$i]->shipping_method_id);
}
}

// If object has linked objects, remove $db property
/*
if(isset($object->linkedObjects) && count($object->linkedObjects) > 0) {
foreach($object->linkedObjects as $type_object => $linked_object) {
foreach($linked_object as $object2clean) {
$this->_cleanObjectDatas($object2clean);
}
}
}*/
if (! empty($object->thirdparty) && is_object($object->thirdparty))
{
$this->_cleanObjectDatas($object->thirdparty);
}

return $object;
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/class/api_categories.class.php
Expand Up @@ -223,7 +223,7 @@ function put($id, $request_data = NULL)
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $this->category->error);
}
}

Expand Down
10 changes: 7 additions & 3 deletions htdocs/comm/propal/class/api_proposals.class.php
Expand Up @@ -389,12 +389,16 @@ function deleteLine($id, $lineid) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

// TODO Check the lineid $lineid is a line of ojbect

$updateRes = $this->propal->deleteline($lineid);
if ($updateRes > 0) {
return $this->get($id);
}

return false;
else
{
throw new RestException(405, $this->propal->error);
}
}

/**
Expand Down Expand Up @@ -442,7 +446,7 @@ function put($id, $request_data = NULL) {
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $this->propal->error);
}
}

Expand Down
5 changes: 5 additions & 0 deletions htdocs/comm/propal/class/propal.class.php
Expand Up @@ -804,6 +804,8 @@ function deleteline($lineid)

if ($this->statut == self::STATUS_DRAFT)
{
$this->db->begin();

$line=new PropaleLigne($this->db);

// For triggers
Expand All @@ -813,15 +815,18 @@ function deleteline($lineid)
{
$this->update_price(1);

$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
else
{
$this->error='ErrorDeleteLineNotAllowedByObjectStatus';
return -2;
}
}
Expand Down
20 changes: 12 additions & 8 deletions htdocs/commande/class/api_orders.class.php
Expand Up @@ -372,19 +372,23 @@ function deleteLine($id, $lineid) {

$result = $this->commande->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Commande not found');
throw new RestException(404, 'Order not found');
}

if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

$request_data = (object) $request_data;
// TODO Check the lineid $lineid is a line of ojbect

$updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid);
if ($updateRes > 0) {
return $this->get($id);
}
return false;
else
{
throw new RestException(405, $this->commande->error);
}
}

/**
Expand Down Expand Up @@ -434,7 +438,7 @@ function put($id, $request_data = NULL) {
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $this->commande->error);
}
}

Expand Down Expand Up @@ -534,7 +538,7 @@ function validate($id, $idwarehouse=0, $notrigger=0)
* @url POST {id}/reopen
*
* @return int
*
*
* @throws 304
* @throws 400
* @throws 401
Expand All @@ -545,7 +549,7 @@ function reopen($id) {

if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
}
if(empty($id)) {
throw new RestException(400, 'Order ID is mandatory');
}
Expand All @@ -572,7 +576,7 @@ function reopen($id) {
* @url POST {id}/setinvoiced
*
* @return int
*
*
* @throws 400
* @throws 401
* @throws 404
Expand All @@ -582,7 +586,7 @@ function setinvoiced($id) {

if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
}
if(empty($id)) {
throw new RestException(400, 'Order ID is mandatory');
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -2074,7 +2074,6 @@ function stock_array($filtre_statut=self::STATUS_CANCELED)
*/
function deleteline($user=null, $lineid=0)
{

if ($this->statut == self::STATUS_DRAFT)
{
$this->db->begin();
Expand Down Expand Up @@ -2137,7 +2136,8 @@ function deleteline($user=null, $lineid=0)
}
else
{
return -1;
$this->error='ErrorDeleteLineNotAllowedByObjectStatus';
return -1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/bank/class/api_bankaccounts.class.php
Expand Up @@ -196,7 +196,7 @@ function put($id, $request_data = null)
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $account->error);
}
}

Expand Down
20 changes: 13 additions & 7 deletions htdocs/compta/facture/class/api_invoices.class.php
Expand Up @@ -240,7 +240,7 @@ function createInvoiceFromOrder($orderid) {
}
if(! DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
}
if(empty($orderid)) {
throw new RestException(400, 'Order ID is mandatory');
}
Expand Down Expand Up @@ -380,18 +380,24 @@ function deleteLine($id, $lineid) {
throw new RestException(404, 'Invoice not found');
}

$result = $this->invoice->deleteline($lineid);
if( $result < 0) {
// TODO Check the lineid $lineid is a line of ojbect

$updateRes = $this->invoice->deleteline($lineid);
if ($updateRes > 0) {
return $this->get($id);
}
else
{
throw new RestException(405, $this->invoice->error);
}

$result = $this->invoice->fetch($id);
/*$result = $this->invoice->fetch($id);
$this->invoice->getLinesArray();
$result = array();
foreach ($this->invoice->lines as $line) {
array_push($result,$this->_cleanObjectDatas($line));
}
}*/
return $result;
}

Expand Down Expand Up @@ -508,10 +514,10 @@ function postLine($id, $request_data = NULL) {
$request_data->fk_parent_line = 0;
}

// calculate pa_ht
// calculate pa_ht
$marginInfos = getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht);
$pa_ht = $marginInfos[0];

$updateRes = $this->invoice->addline(
$request_data->desc,
$request_data->subprice,
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/facture/class/facture.class.php
Expand Up @@ -3009,7 +3009,7 @@ function deleteline($rowid)

if (! $this->brouillon)
{
$this->error='ErrorBadStatus';
$this->error='ErrorDeleteLineNotAllowedByObjectStatus';
return -1;
}

Expand Down
9 changes: 7 additions & 2 deletions htdocs/contrat/class/api_contracts.class.php
Expand Up @@ -450,11 +450,16 @@ function deleteLine($id, $lineid) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

// TODO Check the lineid $lineid is a line of ojbect

$updateRes = $this->contract->deleteline($lineid, DolibarrApiAccess::$user);
if ($updateRes > 0) {
return $this->get($id);
}
return false;
else
{
throw new RestException(405, $this->contract->error);
}
}

/**
Expand Down Expand Up @@ -489,7 +494,7 @@ function put($id, $request_data = NULL) {
}
else
{
throw new RestException(500, $this->task->error);
throw new RestException(500, $this->contract->error);
}
}

Expand Down
1 change: 1 addition & 0 deletions htdocs/contrat/class/contrat.class.php
Expand Up @@ -1758,6 +1758,7 @@ function deleteline($idline, User $user)
}
else
{
$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
return -2;
}
}
Expand Down
3 changes: 3 additions & 0 deletions htdocs/core/lib/functions2.lib.php
Expand Up @@ -2223,6 +2223,9 @@ function getModuleDirForApiClass($module)
elseif ($module == 'order' || $module == 'orders') {
$moduledirforclass = 'commande';
}
elseif ($module == 'shipments') {
$moduledirforclass = 'expedition';
}
elseif ($module == 'facture' || $module == 'invoice' || $module == 'invoices') {
$moduledirforclass = 'compta/facture';
}
Expand Down

0 comments on commit aad0da2

Please sign in to comment.