Interfaces from foreign systems toward Dolibarr: Difference between revisions

(Created page with '{{TemplateDocDevEn}} {{ToTranslate}} Il y a 2 méthodes pour permettre à une application extérieure d'insérer des données dans Dolibarr. Les 2 techniques possibles sont les s...')
 
(Add Chinese)
Tag: 2017 source edit
 
(29 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<!-- BEGIN origin interlang links -->
<!-- You can edit this section but do NOT remove these comments
    Links below will be automatically replicated on translated pages by PolyglotBot -->
[[fr:Interfaces_Exterieur_vers_Dolibarr]]
[[es:Interfaces_del_Exterior_hacia_Dolibarr]]
[[zh:外部系统到Dolibarr的接口]]
<!-- END interlang links -->
{{TemplateDocDevEn}}
{{TemplateDocDevEn}}
{{ToTranslate}}
There are 3 methods to allow an external application to insert data into Dolibarr (For information on the other direction and allow Dolibarr to insert datas into external systems, see page [[Interfaces Dolibarr toward foreign systems]]).
Il y a 2 méthodes pour permettre à une application extérieure d'insérer des données dans Dolibarr. Les 2 techniques possibles sont les suivantes:
 
== Insertion des données directement en base ==
Cette solution requiert de connaître le modèle physique et les valeurs autorisées des champs. Elle est risquée et devra être réécrite en cas de modification du format de base de Dolibarr.
 
'''Avantages:''' Peut être réalisé dans n'importe quel langage.
 
'''Inconvénient:''' Cette technique est très fortement déconseillée. A la première montée de version de Dolibarr, cette méthode risque de ne plus fonctionner et devoir être réécrite.
De plus, en utilisant cette méthode, vous passer outre les règles de validation métier, ce qui crée un risque de corrompre les données. Cette méthode nécessite aussi de connaitre la base Dolibarr.


== Utilisation des classes PHP ==
To act on Dolibarr from external system, there is 3 possible solutions:
Il est possible d'utiliser les objets métiers de Dolibarr (Les fichiers xxx.class.php).
Chacun de ces fichiers offre un classe munie de méthodes pour:
* la récupération d'une entité (la méthode fetch)
* l'insertion en base d'une entité (la méthode create ou insert)
* la mise à jour d'une entité (la méthode update)
* la suppression d'une entité (la méthode delete) si applicable à l'objet
* d'autres méthodes diverses propre à l'entité manipulée.
Cette technique est préférable à la précédente.


'''Avantages:''' Elle offre l'avantage de passer à travers les couches de validations métiers des données. Le code d'interface ne doit normallement pas être réécrit en cas de montée de version de Dolibarr.


'''Inconvénients:''' Elle n'est exploitable qu'en langage PHP.
= Insert data directly into database =
This solution requires knowledge of the physical model and the allowed values of the fields. It is risky and should be rewritten if modified format based Dolibarr.


'''Advantages:''' Can be made in any language.


Voici un exemple pour la création d'un tiers (société client par exemple):
'''Disadvantage:''' This technique is highly discouraged. At the first upgrade of Dolibarr version, this method will not work and will need to be rewritten. Moreover, using this method, you override the business rules validations, which creates a risk of corrupting data. This method also needs to know the basis Dolibarr.


<pre>
= Using PHP classes =
// On declare la classe que l'on va manipuler
It is possible to use business objects Dolibarr (xxx.class.php files). Each of these files provides a class of methods for:
include_once('/pathofdolibarrhtdocs/societe.class.php');
* reading of an entity (the fetch method)
* insertion into database of an entity (the create method or insert)
* updating an entity (the update method)
* deletion of an entity (the delete method) if applicable to the object
* various other methods specific to the entity manipulated.


// On cree une instance de l'objet à manipuler
This technique is better than first one.
$mycompany = new Societe($db);


// On renseigne ces caractéristiques
'''Advantages:''' It offers the advantage of passing through layers of data validation business. The interface code should normally not be rewritten when upgrading version Dolibarr.
$mycompany->nom='Big Brother';
$mycompany->client=1;


// Si on veut que l'action de creation soit associé a un utilisateur 'loginuser' particulier,
'''Disadvantages:''' It is usable in PHP only. Your code must be stored on the same server as the Dolibarr files.
// il faut decommenter cette ligne pour charger les caractéristiques de cet utilisateur.
// Si on laisse commenter, Dolibarr mettra null dans les champs du user de création ou mise a jour.
// $user->fetch('loginuser');


// On invoque la creation
See page [[Business Objects]].
$id=$mycompany->create($user);


// Pour charger l'objet
= Web services =
$mycompany->fetch($id);
See [[Module Web Services REST|Module Web Services API REST]] and [[Module Web Services|Module Web Services API SOAP]].


// Pour mettre a jour
The REST APIs are those used by the Automation tools nocode platforms.
$mycompany->update($user);
</pre>


Rem: Si on est dans le cas d'un script externe à Dolibarr, il est nécessaire de faire au début,
= See also =
avant le include de la classe manipulée
* [[Hooks system]]
<pre>include('/pathofdolibarrhtdocs/master.inc.php');</pre>
* [[Triggers]]
pour que les objets $db, $lang et $user soient créés.
* [[Interfaces Dolibarr toward foreign systems]]
Si on veut que les actions (creation, mise a jour), soit associées dans le suivi à un utilisateur particulier, il est nécessaire de faire avant

Latest revision as of 06:58, 27 September 2023


There are 3 methods to allow an external application to insert data into Dolibarr (For information on the other direction and allow Dolibarr to insert datas into external systems, see page Interfaces Dolibarr toward foreign systems).

To act on Dolibarr from external system, there is 3 possible solutions:


Insert data directly into database

This solution requires knowledge of the physical model and the allowed values of the fields. It is risky and should be rewritten if modified format based Dolibarr.

Advantages: Can be made in any language.

Disadvantage: This technique is highly discouraged. At the first upgrade of Dolibarr version, this method will not work and will need to be rewritten. Moreover, using this method, you override the business rules validations, which creates a risk of corrupting data. This method also needs to know the basis Dolibarr.

Using PHP classes

It is possible to use business objects Dolibarr (xxx.class.php files). Each of these files provides a class of methods for:

  • reading of an entity (the fetch method)
  • insertion into database of an entity (the create method or insert)
  • updating an entity (the update method)
  • deletion of an entity (the delete method) if applicable to the object
  • various other methods specific to the entity manipulated.

This technique is better than first one.

Advantages: It offers the advantage of passing through layers of data validation business. The interface code should normally not be rewritten when upgrading version Dolibarr.

Disadvantages: It is usable in PHP only. Your code must be stored on the same server as the Dolibarr files.

See page Business Objects.

Web services

See Module Web Services API REST and Module Web Services API SOAP.

The REST APIs are those used by the Automation tools nocode platforms.

See also