I have a need to support offline sites ( eg Servoy Developer run in Offline mode, server and client on the same machine) . Sometimes this involves instructing them to roll back. I don't necessarily want them to fiddle with the repository nor the admin pages, and I don't really want to do this myself n times.
Here's a method that works from within Servoy. It will roll back the currently opened solution by 1 release (checking first that there's more than 1)
Big thanks to Jan Aleman for the tips on using the POST features of the HTTP plugin. I found the correct parameters to use in the source of the admin pages.
A question for those wiser than me - there's a parameter mode = 3. What's it for and what are the other mode options?
- Code: Select all
var L_Poster, L_HttpCode, L_AddParam;
var SolutionName = application.getSolutionName()
var SolutionRelease = application.getSolutionRelease();
if (SolutionRelease == 1)
{
plugins.dialogs.showErrorDialog( "ERROR", "Nothing to rollback", "Cancel")
return
}
L_Poster = plugins.http.getPoster('http://localhost:8080/servoy-admin/solutions/activate/' + SolutionName + '.' + parseInt(SolutionRelease-1));
L_AddParam = L_Poster.addParameter('mode','3'); // not sure what mode does but 3 works.
L_AddParam = L_Poster.addParameter('submit','Activate!');
L_HttpCode = L_Poster.doPost(AdminUsername, AdminPassword);
application.output(L_HttpCode)
if (L_HttpCode == 200 )
{
// successful rollback - close the solution
plugins.dialogs.showInfoDialog( "Success!", "The solution has been rolled back 1 version\nClick OK to exit, then reopen the solution.", "OK")
application.closeSolution()
}
else
{
// an error occurred, error handling here
plugins.dialogs.showErrorDialog( "ERROR", "Rollback failed", "OK")
}