22/// This class installs and removes <!-- @echo package.printableName -->. Once the class is
33/// compiled, the application will be installed into Caché system. Then open the web-application
44/// [host]/<!-- @echo config.webApplicationName -->/ (slash at the end is required).
5- Class VisualEditor .Installer Extends %Projection .AbstractProjection [ CompileAfter = (<!-- @echo compileAfter -->) ]
5+ Class VisualEditor .Installer Extends %Projection .AbstractProjection [ Not ProcedureBlock , CompileAfter = (<!-- @echo compileAfter -->) ]
66{
77
88Projection Reference As Installer ;
@@ -11,26 +11,36 @@ Parameter DispatchClass = "VisualEditor.Router";
1111
1212Parameter RESTAppName = " /<!-- @echo config.webApplicationName -->" ;
1313
14+ ClassMethod Init ()
15+ {
16+ set installLog = " "
17+ set errorOccurred = 0
18+ }
19+
1420/// This method creates a new web application by the given spec.
1521ClassMethod RegisterWebApplication (name As %String , spec ) As %Status
1622{
23+ $$$log(" Moving to %SYS." )
1724 new $Namespace
1825 set $Namespace = " %SYS"
1926 set st = $$$OK
2027 if ('##class (Security.Applications ).Exists (name )) {
21- write !, " Creating WEB application " " " _name _" " " ..."
28+ $$$log( " Creating WEB application " " " _name _" " " ..." )
2229 set st = ##class (Security.Applications ).Create (name , .spec )
2330 if ($$$ISOK(st )) {
24- write !, " WEB application " " " _name _" " " is created."
31+ $$$log(" WEB application " " " _name _" " " is created." )
32+ } else {
33+ $$$log(" Unable to create WEB-application " " " _name _" " " !" )
34+ set st = $$$ERROR()
2535 }
2636 } else {
37+ $$$log(" WEB-application " " " _name _" " " already exists, checking it's DispatchClass..." )
2738 do ##class (Security.Applications ).Get (name , .props )
2839 if (props (" DispatchClass" ) '= ..#DispatchClass) && (name = ..#RESTAppName) {
29- write !, " WARNING! WEB application " " " _name _" " " exists but does not refer to " ,
30- ..#DispatchClass, " ." , !, " Please, set correct dispatch class for this " ,
31- " application or create a terminal WEB-application manually."
40+ $$$log(" WARNING! WEB application " " " _name _" " " exists but does not refer to " _ ..#DispatchClass _ " . Please, set correct dispatch class for this " _ " application or create the WEB-application manually." )
41+ set st = $$$ERROR()
3242 } else {
33- write !, " WEB application " " " _name _" " " already exists, so it should be ready to use."
43+ $$$log( " WEB application " " " _name _" " " already exists, so it should be ready to use." )
3444 }
3545 }
3646 return st
@@ -39,52 +49,96 @@ ClassMethod RegisterWebApplication(name As %String, spec) As %Status
3949/// This method removes web application by app name.
4050ClassMethod DeleteWebApplication (name As %String )
4151{
52+ $$$log(" Moving to %SYS." )
4253 new $Namespace
4354 set $Namespace = " %SYS"
4455 if (##class (Security.Applications ).Exists (name )) {
4556 do ##class (Security.Applications ).Get (name , .props )
4657 if (props (" DispatchClass" ) '= ..#DispatchClass) && (name = ..#RESTAppName) {
47- write !, " Won't delete web-application " " " _name _" " " because it does not refer to " ,
48- " dispatch class anymore."
58+ $$$log(" Won't delete web-application " " " _name _" " " because it does not refer to " _ " dispatch class anymore." )
4959 } else {
50- write !, " Deleting WEB application " " " _name _" " " ..."
60+ $$$log( " Deleting WEB application " " " _name _" " " ..." )
5161 do ##class (Security.Applications ).Delete (name )
52- write !, " WEB application " " " _name _" " " is deleted."
62+ $$$log( " WEB application " " " _name _" " " is deleted." )
5363 }
5464 } else {
55- write !, " Unable to remove web-application " " " _name _" " " as it does not exists."
65+ $$$log( " Unable to delete web-application " " " _name _" " " as it does not exists." )
5666 }
5767 return $$$OK
5868}
5969
6070/// This method is invoked when a class is compiled.
6171ClassMethod CreateProjection (cls As %String , ByRef params ) As %Status
6272{
63- write !, " Installing <!-- @echo package.printableName --> to " _ $Namespace
73+ do ..Init ()
74+ #define log (%s ) set installLog = installLog _ $case (installLog = " " , 1 : " " , :$C (10 )) _ %s write !, %s
75+ #define testError (%e ) if ($$$ISERR (%e )) { set errorOccurred = 1 }
76+
77+ $$$log(" Installing <!-- @echo package.printableName --> to " _ $Namespace )
6478
6579 set cspProperties (" AutheEnabled" ) = $$$AutheCache
6680 set cspProperties (" NameSpace" ) = $Namespace
6781 set cspProperties (" Description" ) = " A web application for <!-- @echo config.webApplicationName -->."
6882 set cspProperties (" IsNameSpaceDefault" ) = $$$NO
6983 set cspProperties (" DispatchClass" ) = ..#DispatchClass
7084 set st = ..RegisterWebApplication (..#RESTAppName, .cspProperties )
71- if ($$$ISERR(st )) {
72- return st
85+ $$$testError(st )
86+ if ('$$$ISERR(st )) {
87+ $$$log(" Installation is complete!" )
7388 }
74-
75- write !, " Installation is complete!"
89+ do ..Stats ()
7690
7791 return $$$OK
7892}
7993
8094/// This method is invoked when a class is 'uncompiled'.
8195ClassMethod RemoveProjection (cls As %String , ByRef params , recompile As %Boolean ) As %Status
8296{
83- write !, " Uninstalling <!-- @echo package.printableName --> from " _ $Namespace
97+ do ..Init ()
98+ #define log (%s ) set installLog = installLog _ $case (installLog = " " , 1 : " " , :$C (10 )) _ %s write !, %s
99+ #define testError (%e ) if ($$$ISERR (%e )) { set errorOccurred = 1 }
100+
101+ $$$log(" Uninstalling <!-- @echo package.printableName --> from " _ $Namespace )
84102
85103 do ..DeleteWebApplication (..#RESTAppName)
86104
87- write !, " Uninstalling is complete!"
105+ $$$log(" Uninstalling is complete!" )
106+
107+ return $$$OK
108+ }
109+
110+ /// This method sends anonymous statistics about installation process to
111+ /// <!-- @echo package.printableName --> developer.
112+ ClassMethod Stats () As %Status {
113+ if ($get (installLog ) = " " ) { return $$$OK }
114+
115+ #define checkErr (%e ) if $$$ISERR (%e ) { do $SYSTEM .Status .DisplayError (%e ) return %e }
116+
117+ set sid = $ZD ($H ,3 )
118+ set key = " x8AlP" _$E (sid ,1 ,1 )_" tq"
119+
120+ set body = ##class (%ZEN.proxyObject ).%New ()
121+ set body .cacheVersion = $ZVERSION
122+ set body .version = " <!-- @echo package.version -->"
123+ set body .success = 'errorOccurred
124+ set body .sid = sid
125+ if (errorOccurred ) { set body .log = installLog }
126+
127+ set req = ##class (%Net.HttpRequest ).%New ()
128+ set req .ContentType = " application/json"
129+ set req .Server = " stats.zitros.tk"
130+ do ##class (%ZEN.Auxiliary.jsonProvider ).%WriteJSONStreamFromObject (.jsonStream , body )
131+ do req .EntityBody .CopyFrom (jsonStream )
132+ $$$checkErr(req .Post (" /?key=" _key _" &sid=" _sid ))
133+
134+ set content = $case ($isobject (req .HttpResponse .Data ),
135+ 1 : req .HttpResponse .Data .Read ($$$MaxStringLength),
136+ :req .HttpResponse .Data )
137+ set content = $ZCVT (content , " I" , " UTF8" )
138+ $$$checkErr(##class (%ZEN.Auxiliary.jsonProvider ).%ConvertJSONToObject (content , , .obj , 1 ))
139+ if (obj .error '= " " ) {
140+ $$$checkErr($$$ERROR($$$GeneralError, " Unable to collect statistics: " _ obj .error ))
141+ }
88142
89143 return $$$OK
90144}
0 commit comments