With Servoy Developer 2, it was not possible to access the import pages on servoy-admin using HTTP POST methods. With V3 that's now possible, opening the opportunity to automate imports to the repository.
Based on Jan Aleman's previous posting, http://forum.servoy.com/viewtopic.php?t=6051 I've expanded the code to push a new solution into the repository. It's useful for those sites running Servoy Offline, where you don't want the end users to have direct access to the repository nor the admin pages. The parameters and comments are based on the source for http://localhost:8080/servoy-admin/solutions/import
A couple of important points
- the method mustn't be in the solution you are importing to the repository. Run it from another solution.
- You need Servoy 3.1 at least (the HTTP plugin on earlier versions didn't support this method)
- Code: Select all
var SolutionRelease = application.getSolutionRelease();
var SolutionName = application.getSolutionName()
var L_Poster, L_HttpResult, L_HttpCode, L_TmpFile,L_TmpSiNo, L_AddParam ;
L_TmpFile = plugins.file.convertStringToJSFile('C:/Program Files/Servoy3/solutions/MySolution2.servoy');
L_TmpSiNo = L_TmpFile.exists();
if ( L_TmpSiNo == true )
{
//Import file...
L_Poster = plugins.http.getPoster('http://localhost:8080/servoy-admin/solutions/import');
L_AddParam = L_Poster.addFile('if','file',L_TmpFile);
L_AddParam = L_Poster.addParameter('submit','Import!');
//General options...
L_AddParam = L_Poster.addParameter('ac','1'); // 1 = Activate new release of imported solution and modules
L_AddParam = L_Poster.addParameter('os','1'); // 1 = Overwrite repository styles with import version
L_AddParam = L_Poster.addParameter('om','1'); // 1 = Overwrite repository media with import version
L_AddParam = L_Poster.addParameter('og','1'); // 1 = Overwrite repository group security settings with import version
L_AddParam = L_Poster.addParameter('fs','0'); // 1 = Override auto enter types to the auto enter types contained in the import version.
//WARNING: This may break other solutions using the same tables, or cause tables to use nonexistent dbidentity or dbsequence sequences or other database auto enter types!
L_AddParam = L_Poster.addParameter('ak','0'); // 1 = Allow reserved SQL keywords as table or column names (will fail unless supported by the backend database)
L_AddParam = L_Poster.addParameter('sd','0'); // 1 = Import solution sample data
L_AddParam = L_Poster.addParameter('id','0'); // 1 = Import internationalization
L_AddParam = L_Poster.addParameter('io','0'); // 1 = Insert new internationalization (i18n) keys only
//User import options...
L_AddParam = L_Poster.addParameter('up','1');
// 0 = Do not import users contained in import
// 1 = Create nonexisting users and add existing users to groups specified in import
// 2 = Overwrite existing users completely (USE WITH CARE)
L_AddParam = L_Poster.addParameter('aa','1'); // 1 = Allow users to be added to the Administrators group
// Merging options - if merging
// L_AddParam = L_Poster.addParameter('ms','0'); // Merge solution if revision information is available, and when a merge conflict arises use:
// L_AddParam = L_Poster.addParameter('ul','0'); // 0 = repository version; 1 = import version
// or Merging options - if not merging
L_AddParam = L_Poster.addParameter('ms','1'); // Do not merge solution, and:
L_AddParam = L_Poster.addParameter('of','1'); // overwrite repository forms with import version
L_AddParam = L_Poster.addParameter('df','1'); // delete repository forms which do not exist in import version
// DO POST
L_HttpCode = L_Poster.doPost(AdminUsername, AdminPassword);
L_HttpResult = L_Poster.getPageData();
if (utils.stringPatternCount(L_HttpResult, "Import successful...") > 0 )
{
plugins.dialogs.showInfoDialog( "Success!", "Update successfully completed. Click OK to continue", "OK")
application.closeSolution("MySolution") // to close the updater and re-open MySolution
}
else
{
// an error occurred, error handling here
plugins.dialogs.showErrorDialog( "ERROR", "Import failed", "OK")
}
}