Overview

In order for applications to duplicate properly, database IDs, column IDs, node IDs and token must be stored in a serialized format. Applications need to serialize their IDs via the SK.Util.serialize* functions and/or the SK.DB.Setup.Serialized class. When duplicating a site, the Back-end will replace all serialized IDs with the newly duplicated ones.

The application must indicate in its ad.json that it can be duplicated. If the app stores some IDs/tokens it should indicate weather they are stored in app's properties and/or the app configuration
 

Functions

Serialization and Deserialization functionality provided by:

function SK.Util.serializeDBId ( id )
function SK.Util.serializeColId ( id )
function SK.Util.serializeNodeId ( id )
function SK.Util.serializeToken ( token )

function SK.Util.deserializeDBId ( id )
function SK.Util.deserializeColId ( id )
function SK.Util.deserializeNodeId ( id )
function SK.Util.deserializeToken ( token )
function SK.Util.deserializeMulti ( string )


Class SK.DB.Setup.Serialized



In ad.json:

"duplication": true,                   // default false

"duplication_process": {         // optional  
   "configuration":  true            // default false  
   "properties":     true              // default false
}



Example serialization code:

// create a db and return its info in serialized format
var db = new SK.DB.Setup.Serialized(
    session_id,
   {
      database: {
         name: '...'
         columns: [ ... ],
         tokens:  [ ... ]
      },
      function ( structure ) {
         // The parameter 'structure' is serialized.

         // The application can now store db IDS, etc. in its configuration
         new SK.App.Config(
            this.options
         ).set(
            {
               my_structure: structure
            },
         ...
         );
     }
   ...
);


db.create( ... )



Example deserialization code:

SK__SomeApplication = new Class({     
   initialize: function( options, view ) {
      // deserialize db id
      var db_id = SK.Util.deserializeDBId( this.options.configuration.my_structure.database.id );

      // deserialize token
      var token = SK.Util.deserializeToken( this.options.configuration.my_structure.tokens[ 0 ].token );

      // deserialize col ids
      var column_ids = [];
      for ( var i in this.options.configuration.my_structure.columns ) {
         column_ids.push( SK.Util.deserializeColId( this.options.configuration.columns[i].id ) );      }

      // Continue app logic...
  },

 

Object oriented interface

var serializer = new SK.Util.Serializer();
deserializer.dbId( serialized_db_id );
deserializer.colId( serialized_col_id );
deserializer.nodeId( serialized_node_id );
deserializer.token( serialized_token );
deserializer.multi( string );

var serializer = new SK.Util.Serializer();
serializer.dbId( db_id );
serializer.colId( col_id );
serializer.nodeId( node_id );
serializer.token( token );

 

 

Property Sheets

To (de)serialize properties, application need to extend SK.UI.Object.Properties and overwrite parents methods getObjectEnv getProperties as shown in the example below. Each property which should be (de)serialized must have an html attribute serialized="...". Available types of serialized attributes are "db_id" "col_id" "node" "token" "multi".

html code:

class="field-text w6u" id="field.Database" serializable="db_id" name="property__Database"



javascript code:

SK.MembersLogin.Properties = new Class({
   Extends     : SK.UI.Object.Properties,
   ...
   getObjectEnv: function() {
      var env = SK.Singletons.env.get( 'object_env' );
      this.deserealizeProperties( env.properties );              // this deserializes the properties with html attribute serialized="..."
      return env;
   },
   getProperties: function() {
      var properties = this.parent();
      return this.serealizeProperties( properties );               // this serializes the properties with html attribute serialized="..."
   },
...
});



If required, application may not use this functionality. Instead apps could hook on property sheet events (see Property Sheets) and do their (de)serialization manually.