Child pages
  • Maintenance Mode

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

During solution import from the Servoy Admin Page, modules with certain name patterns are handled in a special way. Modules whose names start with "before_import" are handled as pre-import hooks. Their onOpen event handlers are executed before the solution is actually imported. Similarly, modules whose names start with "after_import" are handled as post-import hooks. Their onOpen event handles handlers are executed after the solution is actually imported.

...

During the execution of the onOpen event handlers from the pre-import and post-import hooks, any output printed with application.output will be redirected to the import log, which you can see in the Servoy Admin Page.

A

...

Simple Example

Suppose you have a solution called "sample_01", with two modules called "before_import_01" and "after_import_01". The "before_import_01" module has the following onOpen event handler:

...

after all messages related to the actual solution import.

What

...

Else Can You Do? The maintenance

...

Plugin.

The pre-import and post-import hooks were introduced for allowing you to automatically perform administrative tasks on the server while importing solutions:

...

This function takes the Server out of maintenance mode, so that clients can again connect to it.

Modifying Database Structure and Content

Using the maintenance plugin it is possible to programmatically modify the database structure. You can create and drop tables, and you can create and delete columns. Please refer to the API documentation of the maintenance plugin for specific details on how to do these operations.

It can happen that when you move upgrade your Servoy solution, you need to change the structure of the underlying database. Some columns may become obsolete, new columns may be needed, data may need to be reorganized, etc. You can automate all these tasks by using the maintenance plugin in a pre-import hook.

For example the following function, set as handler for the onOpen even of a pre-import hook, will delete a no longer needed column from a table.

Code Block
JavaScript
JavaScript

function onSolutionOpenBeforeImport()
{
	var server = plugins.maintenance.getServer("example_data")
	if (server) {
		var table = server.getTable("todo_list")
		if (table) {
			table.deleteColumn("todo_list_suggested_by")
			var result = server.synchronizeWithDB(table)
			if (result)
				application.output("'Suggested By' column removed.")
			else
				application.output("Something went wrong while deleting column.")
		}
		else {
			application.output("Table 'todo_list' cannot be found.")
		}
	}
	else {
		application.output("Server 'example_data' cannot be found.")
	}
}

The function tries to obtain a reference to the server where the table is stored. If successful, then it tries to obtain a reference to the table which holds the obsolete column. If this step is also successful, then it deletes the column. In order to make the change permanent, the table must be synchronized with the underlying database.