« Back to Product

Documentation

Migrate

Require: IP-Symcon >= 7.0

 string Migrate ()

Returns

JSON encoded object with the new configuration/attributes.
Empty string unless changes are needed.

Description

This function is only called when IP-Symcon is started or after a module update. It is not called the first time an instance is created. The delivered persistence is independent of the properties/attributes already registered in Create. As a result, it can be adjusted/corrected as desired so that it fits the new properties/attributes. This allows, for example, old properties (e.g. due to a typo) to be corrected in the name or content.

The new values are directly available in the properties/attributes in the subsequent ApplyChanges function.

Warning

The Migrate function is called by IP-Symcon. It must therefore be overwritten by the base class in order to add your own extensions

Example

public function Migrate($JSONData) {

    // Don't remove this line
    parent::Migrate($JSONData);

    // Example data for JSONData
    /*
    {
        "attributes": {
            "MyAttribute": "MyValue"
        },
        "configuration": {
            "MyConfiguration": "MyValue"
        }
    }
    */

    // Migrate Configuration/Attributes
    $j = json_decode($JSONString);
    $j->attributes->NewAttribut = $j->attributes->MyAttribute;
    $j->configuration->NewConfiguration = $j->configuration->MyConfiguration;
    return json_encode($j);

}
Any questions?