generated from intersystems-community/intersystems-iris-dev-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLine.cls
151 lines (126 loc) · 6.91 KB
/
Line.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Include dc.one.Line
/// contains useful one-liners for ObjectScript development
Class dc.one.Line
{
/// Add one line to the history of the IRIS terminal for Linux. It is very convenient to insert commands into the iris.script file, for example, to test a module in terminal mode.
/// Samples:
/// if $zf(-1,"echo ':do 1^%SS' >> ~/.iris_history")
ClassMethod Add2History()
{
if $zf(-1,"echo ':zpm ""test my-module""' >> ~/.iris_history")
}
/// Add a one-line Z-command
/// Samples:
/// set line="ZPMN(m="""") new $namespace zpm ""zn ""_m_""*"" quit" do ##class(dc.one.Line).AddLineInZZCommand(line)
/// set line="ZPMF(m="""") new $namespace zpm ""ver"" zpm ""repo -list"" zpm ""find ""_m quit" do ##class(dc.one.Line).AddLineInZZCommand(line)
/// set line="ZLIC() new $namespace zn ""%SYS"" do ^CKEY quit" do ##class(dc.one.Line).AddLineInZZCommand(line)
/// set line="ZPIPE(%a) new $namespace zn """_$namespace_""" do cmd^Zpipe(%a) quit" do ##class(dc.one.Line).AddLineInZZCommand(line)
/// set line="ZZJSN(in,out="""") new $namespace zn """_$namespace_""" new res,t,zr set t=$t,zr=$zr set res=$$Do^ZPretty(.in) if (out="""") { write res,! } elseif ($isObject(out) && out.%IsA(""%Stream.Object"")) { do out.Write(res) } else { set @out=res } set $zr=zr if t {} quit" do ##class(dc.one.Line).AddLineInZZCommand(line)
ClassMethod AddLineInZZCommand(line,rou="%ZLANGC00")
{
new $namespace set $namespace="%sys" merge r=^rMAC(rou,0) for i=1:1 { quit:'$DATA(r(i),str) set:$p(str,"(")=$p(line,"(") r(i)=line,yes=1 } if '$GET(yes) { set r(i)=line,r(0)=i } D ROUTINE^%R(rou_".MAC",.r,.err,"CS",0)
}
ClassMethod CreateSSL()
{
$$$onessl
x "n $namespace set $namespace=""%SYS"", name=""DefaultSSL"" do:'##class(Security.SSLConfigs).Exists(name) ##class(Security.SSLConfigs).Create(name)"
}
/// install ZPM. You can call this, or copy the line
/// courtesy Eduard Lebedyuk
ClassMethod InstallZPM()
{
$$$onezpm
s r=##class(%Net.HttpRequest).%New(),r.Server="pm.community.intersystems.com",r.SSLConfiguration="ISC.FeatureTracker.SSL.Config" d r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c")
}
/// Read file. Sample run: if ##class(dc.one.Line).ReadFile("/irisdev/app/module.xml",.txt) write txt
/// by Sergey Mikhaylenko
ClassMethod ReadFile(filename="/irisdev/app/module.xml",ByREf txt) as %Status
{
set f=##class(%File).%New(filename) if f.Open("RSU") {s txt=f.Read() w !,txt } else { w !,$System.Status.GetErrorText($g(%objlasterror)) quit $g(%objlasterror) } d f.%Close() quit $$$OK
}
/// Write to file. Sample run: write ##class(dc.one.Line).Write2File("d:\!\log.txt","do 1^%SS")
/// by Sergey Mikhaylenko
ClassMethod Write2File(fn = "/tmp/log.txt", ByRef cmd) As %Status
{
set:$g(fn)="" fn="/tmp/log.txt" open fn:("WNSK\UTF8\"):1 if $test { use fn xecute cmd close fn quit $$$OK } else { w !,$System.Status.GetErrorText($g(%objlasterror)) quit $g(%objlasterror) }
}
/// install ZPM with proxy. You can call this, or copy the line
/// modified Sergey Mikhaylenko
ClassMethod InstallZPMproxy()
{
s r=##class(%Net.HttpRequest).%New(),proxy=$System.Util.GetEnviron("https_proxy") Do ##class(%Net.URLParser).Parse(proxy,.pr) s:$G(pr("host"))'="" r.ProxyHTTPS=1,r.ProxyTunnel=1,r.ProxyPort=pr("port"),r.ProxyServer=pr("host") s:$G(pr("username"))'=""&&($G(pr("password"))'="") r.ProxyAuthorization="Basic "_$system.Encryption.Base64Encode(pr("username")_":"_pr("password")) set r.Server="pm.community.intersystems.com",r.SSLConfiguration="ISC.FeatureTracker.SSL.Config" d r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c")
}
/// install ZPM latest beta version. You can call this, or copy the line
/// modified Sergey Mikhaylenko
ClassMethod InstallZPMBeta()
{
s r=##class(%Net.HttpRequest).%New(),proxy=$System.Util.GetEnviron("https_proxy") Do ##class(%Net.URLParser).Parse(proxy,.pr) s:$G(pr("host"))'="" r.ProxyHTTPS=1,r.ProxyTunnel=1,r.ProxyPort=pr("port"),r.ProxyServer=pr("host") s:$G(pr("username"))'=""&&($G(pr("password"))'="") r.ProxyAuthorization="Basic "_$system.Encryption.Base64Encode(pr("username")_":"_pr("password")) set r.Server="github.com",r.SSLConfiguration="ISC.FeatureTracker.SSL.Config" d r.Get("/intersystems-community/zpm/releases/download/v0.4.1-beta.12/zpm-0.4.1-beta.12.xml"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c")
}
/// Enable IRIS BI in an Namespace
/// Create %All Namespace
/// , but don't forget to return to the initial namespace
ClassMethod CreatePersentAll() As %Status
{
Set sc = $$$OK
//n $namespace
//set $namespace="%SYS",P("Globals")="%DEFAULTDB",sc=##class(Config.Namespaces).Create("%All",.P)
$$$onepercentall
x "n $namespace set $namespace=""%SYS"",P(""Globals"")=""%DEFAULTDB"",sc=##class(Config.Namespaces).Create(""%All"",.P)"
Return sc
}
/// enable IRIS BI in a namespace
ClassMethod EnableIRISBI()
{
// enable in a given namespace
do EnableDeepSee^%SYS.cspServer("/csp/namespace/")
// enable in a current namespace
$$$oneenableirisbi($namespace)
do EnableDeepSee^%SYS.cspServer("/csp/"_$$$LOWER($namespace))
}
/// Unexpire passwords to simplify dev mode. Don't use in Production
ClassMethod UnExpireUserPasswords()
{
$$$oneendlesspass
X "n $namespace set $namespace=""%SYS"" Do ##class(Security.Users).UnExpireUserPasswords(""*"")"
}
/// Export Global in the repo (docker runtime)
ClassMethod ExportGlobal()
{
$$$oneexportglobal("GlobalD","/irisrun/repo/src/gbl/")
d $System.OBJ.Export("GlobalD.GBL","/irisrun/repo/src/gbl/GlobalD.xml")
}
/// turns off random global names for class storage strategy
ClassMethod TurnOffRandomGlobals() As %Status
{
set sc=$SYSTEM.SQL.Util.SetOption("DDLUseExtentSet",0,.oldval)
return sc
}
/// Make the storage structure for DDL created and UDL created classes similar
/// $lb("",col1,col2,,n)
/// it makes it cancelling Final clause in the Storage
ClassMethod UnifiedLBStorage() As %Status
{
set sc=$SYSTEM.SQL.Util.SetOption("DDLFinal",0,.oldval)
return sc
}
/// Change password for preset users
ClassMethod ChangeAdminPassword() As %Status
{
$$$changealladminpass("pass")
x "new $namespace,s,p,n set $namespace=""%SYS"",p(""Password"")=""NewPass123"" for n=""admin"",""cspsystem"",""iam"",""superuser"",""unknownuser"",""_system"",""_ensemble"" set s=##class(Security.Users).Modify(n,.p)"
quit $$$OK
}
/// do ##class(dc.one.Line).passwordless()
/// https://community.intersystems.com/post/passwordless-mode-dev-mode-iris
ClassMethod passwordless(app="/csp/sys") As %Status
{
X "n $namespace set $namespace=""%SYS"" set par(""AutheEnabled"")=64,tSC=##class(Security.Applications).Modify($g(app,""/csp/sys""),.par),role=""%All"",tSC=##class(Security.Users).AddRoles(""UnknownUser"",.role,1) "
quit $$$OK
}
/// Fastest way to create a namespace with two databases for code and globals
/// do ##class(dc.one.Line).createdatabase("testdb")
ClassMethod createdatabase(name) As %Library.ResultSet
{
quit $SYSTEM.SQL.Execute("CREATE DATABASE "_name)
}
}