Developer guide

1.Get started

Hello

Lets get started!

Was this helpful? Yes No Suggest edit

2.Good practices

Will be written soon. Sorry for the delay.

Was this helpful? Yes No Suggest edit

3.Connector creation

If you want to connect an application to Myddleware, we advise you to use this documentation.

Was this helpful? Yes No Suggest edit

3.1.Requirement

It is important that the application you want to connect has a webservice API with functions to read data. This will make it easier to use for source application and create/update data and also for target application.

In our example, we will create the shop-application connector.

First you will need to prepare Myddleware :

  • Add the service in Symfony, file <Myddleware>/RegleBundle/Resources/config/services.yml

tuto_connecteur_add_service

  • Add you application in the database, table Solution:

tuto_connecteur_add_solution_bdd

  • Finally create you connector class to develop it in teh directory <Myddleware>. The filename has to be the name of the service. The code should be this code, but change the application name :

tuto_connecteur_class_empty

Lets now look at each function and attribute and how to debug them.

Was this helpful? Yes No Suggest edit

3.2.Method getFieldsLogin

You have to put the parameters required to connect to your solution in the method getFieldsLogin.

For example, if you need an url and an APIkey you can create this method :

tuto_connecteur_method_getfieldslogin

Code available in the file <Myddleware>/src/Myddleware/RegleBundle/Solutions/shopapplication.php

If the field you need doesn’t exit in the language file <myddlware>/src/Myddleware/RegleBundle/Resources/translations ($solution->field), you can add its translation here.

Now, click on Connector->Creation, then select your application, the parameters you have added in your function should be visible :

tuto_connecteur_check_parameters

We will now develop the login function.

Was this helpful? Yes No Suggest edit

3.3.Method login

You have to add the function login to check the connexion with you application.

tuto_connecteur_method_login

Code available in the file <Myddleware>/src/Myddleware/RegleBundle/Solutions/shopapplication.php

Make sure every errors are catched and this->connexion_valide = true if the connexion works.

To debug this function, you can click on the button “test”. The function will be called each time you click on “test”, no needs to refresh the page :

tuto_connecteur_method_login_test

Let’s now create the first rule.

Was this helpful? Yes No Suggest edit

3.4.Method get_modules

You have to add the module you want to connect in this method.

In input you have access to the type of connexion, if your solution is in target or in source of the rule. Some module could be available only in source or only in target.

Y0u then return an array with a list of module :

tuto_connecteur_method_get_modules

Code available in the file <Myddleware>/src/Myddleware/RegleBundle/Solutions/shopapplication.php

Now you can check you function by creating a rule and open the module list :

tuto_connecteur_method_get_modules_test

Next step is the fields mapping, we now need to create a function for it.

Was this helpful? Yes No Suggest edit

3.5.Method get_module_fields

You have to indicate to Myddleware what fields are available for each module. If your application has a function which describe all fields for every module, you should use id. For example, we did it for Salesforce or Prestashop. Otherwise you have to describe every fields.

Add the function get_module_fields in you class.

Input :

  • Module indicate from which module we need the fields
  • Type indicate if the module is in source or in target in the rule

Output :

  • An array with all the fields for the module

You should then add the fields related (field available to create relationship) and the class attribute this->fieldsRelate

Your fields will then be displayed after clicking on the button “Go to fields mapping” :

tuto_connecteur_method_get_module_fields_test

Create a mapping and go to the tab “Simulation”. We will now create the function read_last.

Was this helpful? Yes No Suggest edit

3.6.Method read_last

The function read_last is used to :

  • Get the last data in your application when the user click on “Simulation” when a rule is created
  • Search a data in you application when Myddleware search a duplicate data
  • Get the data from a specific record in you application. The goal is to create an history before Myddleware modify this record. Another goal is to check if Myddleware will change you data. if the data Myddleware will send is the same in the you application so we cancel the data transfer.

Here is an example of input value :

tuto_connecteur_method_read_last_input

Query is the parameter used to search :

  • Query can have the entry “id” when Myddleware try to get a record before updating it
  • Query can have other parameter you have defined in the attribute FieldsDuplicate
  • Query can be empty when the user click on “Simulation” during the rule creation. In this case Myddleware has to search the last record modified in your application

The function should return an array like as below :

tuto_connecteur_method_read_last_output

The entry “done” could be equal to :

  • “1” if a data has been found
  • “0”if no data has been found and no error occured
  • “-1” if an error occured

To test it, you can simulate you rule, and data should be displayed :

tuto_connecteur_method_read_last_test

Now save your rule. You should now be able to run the rule and develop the method read.

Was this helpful? Yes No Suggest edit

3.7.Method read

You have to develop this function to read the data in your application.

Here is an example of input value :

tuto_connecteur_method_read_input

Parameters :

  • module is the module to read in your application
  • rule contains the parameters of the rule
  • date_ref is used to search all data modified or created after this reference
  • ruleParams is the parameters of the rule
  • fields contains all values the function has to return
  • offset and limit are used only if your application has to be read with limited data
  • jobId is the if of the job
  • manual indicate if the rule is run manually
  • query can be also defined. If this parameter is defined, the read method has to return the result of the query. If it is empty, then Myddleware will user the reference date to read data.

Activate your rule. You can test you function read via the command php app/console myddleware:synchro <your rule id>

The output of the function read should look like these :

tuto_connecteur_method_read_output

Then the function should return an array with these entries :

  • count with the number of records read. Has to be 2 if no record are read.
  • date_ref with the new date_ref. It has to be the max date found in the records read.
  • values with an array of records. The key of these entries has to be the id of the record. The entry id and date_modified has to be present for each record. Date modified contains the value of the date_created or date_modified depending the type of the rule (see the function getDateRefName).
Was this helpful? Yes No Suggest edit

3.8.Method create

Create a rule now with your application in target. Then create the function public function create($param) in your class.

Run your rule as you did while developing the method read.

Here is an example of input value :

tuto_connecteur_method_create_input

Parameters :

  • data contains all the record Myddleware want to create in tour application. The key of each record is the id of the data trasfer in Myddleware
  • module is the module to write in your application
  • ruleId is teh id of the rule
  • rule contains the parameters of the rule
  • ruleFields contains the fields of the rule
  • ruleParams is the parameters of the rule
  • ruleRelationships contains the relationships with the current rule
  • fieldsType contains the type of all fields in the rule
  • jobId is the if of the job

The output of the function created should look like these :

tuto_connecteur_method_create_output

The function should then return an array with an array (key = id of the data transfer in Myddleware) for each record created.  This array has 2 entries :

  • id of the record in your application
  • error : the error message or empty if the record is successfully created
Was this helpful? Yes No Suggest edit

3.9.Method update

The method update works in the same way as the method create. The output parameter must be built exactly like in the method create.

The only difference is that you have the entry “target_id” for each record in the array data. You will need this entry to update your data in your application.

Was this helpful? Yes No Suggest edit

4.Create formula

In this article we‘ll look at an important point in your synchronization rules and one of the many setting options offered by Myddleware, formulas.

 

The fundamentals

For starters, formulas allow you to format or to set the values that will be sent to a given target field . In other words, you have the option of adding fixed text to all uppercase, change timezones, concatenate several source fields etc.

 

The syntaxe

To help, syntax highlighting (1) is available to you right on your text box. Furthermore you will find below, the list of source fields that you have chosen (2), the available functions and their categories (3) and one or two drop list(s) (4) of the different values for the list type fields (as SalutationID example).

blog-formules

Examples:

– Concatenate multiple fields, Myddleware uses the “.as in PHP {field1}.{field2}.{fields3}

– Concatenate a fixed text with one or multiple fields “Client Name: “.{Firstname}.” “.{Lastname}

Three-valued condition , “If the Greeting field is ‘Mr.’ then send 1, otherwise send 2” is written as followed : (({Greeting} == “Mr.”) ? “1” : “2”), those three-valued conditions can be nested in order, for example, to make the data correspond. Thus, ({resolution} == “10” ? “Open” : ({resolution} == “20” ? “Fixed” : ({resolution} == “30” ? “Reopened” : “Suspended”))) is correct and functional, this formula means “If resolution is 10 then ‘Open’ is sent, otherwise if resolution is 20 then ‘Fixedis sent, otherwise if resolution is 30 then Reopened’ is sent, otherwise Suspended ‘ is sent.

– Add two fileds {field1} + {field2}

 

Functions

 

In the formula of Myddleware, you can use the functions listed at the bottom right (see (3) of the previous image).

 

round(numbre [, clarification)(PHP) Ex: round(525.6352, 2) // Gives 525.64

This function round floating point (up).

 

ceil(float)(PHP) Ex: ceil(525.6352) // gives 526

Rounds up.

 

abs(number)(PHP) Ex: abs(-5) // gives 5

Returns the absolute value.

 

trim(string [, Masque])(PHP) Ex: trim(” bonjour “) returns “bonjour”

Deletes spaces (or other charachters) at the begenning and the end of a string.

 

lower(STRING)(PHP) Ex: lower(“BONJOUR”) returns “bonjour”

Lowercases all charachters.

 

upper(Strin)(PHP) Ex: upper(“bonjour”) returns “BONJOUR”

Uppercases all charachters.

 

date(Format [, Timestamp])(PHP) Ex: date(“Y:m:d”) returns “2014:09:16”

Formats a local date/hour.

 

microtime([true if you want a float result])(PHP) Ex: microtime(true) returns 1410338028.5745

Returns current Unix timestamp with microseconds.

 

changeTimeZone(Date you want to change, old timezone, new timezone)(PHP) Ex: changeTimeZone(“2014-09-16 12:00:00”, “America/Denver”, “America/New_York”) returns “2014-09-16 14:00:00”

Changes the timezone of the given date.

 

changeFormatDate(Date you want to change, New format) Ex: changeTimeZone(“2014-09-16 12:00:00”, “Y/m/d H:i:s”) returns “2014/09/16 12:00:00”

Changes the format of the given date.

 

substr(String, Index)(PHP) Ex: substr(“abcdef”, -1) returns “f”

Reads a string starting of the given Index.

 

striptags(String)(PHP) Ex: striptags(“<p>Test paragraph.</p><!– Comment –> <a href=”#fragment”>Other text</a>”) returns “Test paragraph. Other text”

Strips HTML and PHP tags from a string.

 

Was this helpful? Yes No Suggest edit
Suggest Edit