Skip to content

Commit 0f3e834

Browse files
authored
Merge pull request #61 from intersystems-community/stage
fix show description and install not latest version with proxy
2 parents 5d96c6f + 93d7198 commit 0f3e834

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

src/cls/ZPM/Package.cls

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,6 @@ ClassMethod LoadFromGitHub(Url = "")
488488
do ##class(%File).RemoveDirectoryTree(outputFolder)
489489
}
490490

491-
ClassMethod GetTopVersion(pkg As %String) As %String
492-
{
493-
Set version = ""
494-
&sql(SELECT TOP 1 version INTO :version FROM ZPM.Package
495-
WHERE name = :pkg
496-
ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC )
497-
Return version
498-
}
499-
500491
/// returns latest versions of packages
501492
ClassMethod GetLatest(searchTerms As %DynamicArray = "", Output pStatus As %Status) As %DynamicArray
502493
{
@@ -521,11 +512,12 @@ ClassMethod GetLatest(searchTerms As %DynamicArray = "", Output pStatus As %Stat
521512
}
522513
Set searchCondition = searchCondition_ " ) "
523514
}
524-
Set sql = "SELECT name, repository, description "_
525-
"FROM ZPM.Package p1 "_
526-
"WHERE "_ searchCondition _
527-
"GROUP BY name "_
528-
"ORDER BY name"
515+
set sql = "SELECT name, repository, description, "_
516+
" ( SELECT TOP 1 version FROM ZPM.Package p2 WHERE p1.name=p2.name ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC ) version " _
517+
" FROM ZPM.Package p1 "_
518+
" WHERE "_searchCondition_" "_
519+
" GROUP BY name ORDER BY name"
520+
529521
Set tStatement = ##class(%SQL.Statement).%New()
530522
Set tStatus = tStatement.%Prepare(sql)
531523
If ($$$ISERR(tStatus)) {
@@ -541,9 +533,9 @@ ClassMethod GetLatest(searchTerms As %DynamicArray = "", Output pStatus As %Stat
541533
While tResult.%Next() {
542534
Set tPkgInfo = {
543535
"name": (tResult.name),
544-
"description": (tResult.Description),
536+
"description": (tResult.description),
545537
"repository": (tResult.repository),
546-
"versions": [(..GetTopVersion(tResult.name))]
538+
"versions": [(tResult.version)]
547539
}
548540
do tList.%Push(tPkgInfo)
549541
}

src/cls/ZPM/Registry.cls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ ClassMethod Reset() As %Status
9393
ClassMethod Package(pkg As %String = "", version As %String = "") As %Status
9494
{
9595
Set pkg = $$$lcase(pkg)
96+
97+
If (version="") {
98+
$$$ThrowOnError(##class(ZPM.UpLink).FindPackageInAllUpLinks(pkg))
99+
}
100+
96101
Set version = ##class(ZPM.Package).VersionFind(pkg, version)
97102
If (version = "") {
98103
Return ..ReportHttpStatusCode(..#HTTP404NOTFOUND)

src/cls/ZPM/UpLink.cls

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,49 @@ Method UpdatePackagesFromOneUpLink() As %Status
101101
While iter.%GetNext(.key , .package ) {
102102
Do ..AddPackage(package)
103103
}
104-
} Catch {
105-
Return 0
104+
} Catch ex {
105+
Do ex.Log()
106+
Return ex.AsStatus()
107+
}
108+
}
109+
110+
Method FindPackageInOneUpLink(pkg As %String)
111+
{
112+
If ('..MatchAllowlist(pkg)) {
113+
Return $$$ERROR($$$GeneralError, "invalid package name "_pkg)
114+
}
115+
Set httprequest = ..GetHttpRequest()
116+
Set searchStr = "packages/"_pkg
117+
Set tSC = httprequest.Get(..Location_searchStr)
118+
If ($$$ISERR(tSC)) { Return tSC }
119+
Try {
120+
Set package = {}.%FromJSON(httprequest.HttpResponse.Data)
121+
Set iter = package.versions.%GetIterator()
122+
While iter.%GetNext(.key , .version ) {
123+
set tPackage = {"name":(package.name), "description":"", "repository":(package.repository), "versions":[(version)]}
124+
Do ..AddPackage(tPackage)
125+
}
126+
} Catch ex {
127+
Do ex.Log()
128+
Return ex.AsStatus()
106129
}
107130
}
108131

132+
ClassMethod FindPackageInAllUpLinks(pkg As %String) As %Status
133+
{
134+
Do ..ReadUplinksFromFile()
135+
Set sql = "SELECT ID FROM ZPM.UpLink WHERE Active = 1 ORDER BY Position"
136+
Set statement = ##class(%SQL.Statement).%New()
137+
Set tSC = statement.%Prepare(sql)
138+
If $$$ISERR(tSC) { Return tSC }
139+
Set resultset=statement.%Execute()
140+
While resultset.%Next() {
141+
Set uplink = ..%OpenId(resultset.ID)
142+
Do uplink.FindPackageInOneUpLink(pkg)
143+
}
144+
Return $$$OK
145+
}
146+
109147
ClassMethod LoadPackageFromAllUpLinks(pkg As %String = "", version As %String = "") As ZPM.Package
110148
{
111149
Do ..ReadUplinksFromFile()
@@ -145,6 +183,7 @@ Method LoadPackageFromOneUpLink(pPackage As ZPM.Package, pkg As %String = "", ve
145183
$$$ThrowOnError(..LoadPackage(pPackage, pkg, version))
146184
$$$ThrowOnError(..LoadInstaller(pPackage, pkg, version))
147185
} Catch ex {
186+
do ex.Log()
148187
Return ex.AsStatus()
149188
}
150189
Return $$$OK
@@ -314,6 +353,7 @@ ClassMethod ReadUplinksFromFile() As %Status
314353
}
315354
}
316355
} Catch ex {
356+
do ex.Log()
317357
Set sc = ex.AsStatus()
318358
}
319359
Return sc
@@ -366,7 +406,11 @@ ClassMethod AddUplink(name, url, allowList, position) As %Status
366406
If $Data(tComponents("port"), port), port'="" {
367407
Set tUplink.Port = port
368408
}
369-
Set tUplink.Location = tComponents("path")
409+
Set tPath = tComponents("path")
410+
If ($EXTRACT(tPath,*) = "/") {
411+
Set tPath = $EXTRACT(tPath,1,*-1)
412+
}
413+
Set tUplink.Location = tPath
370414
If $Get(tComponents("scheme"))="https" {
371415
Set tUplink.SSL = 1
372416
}

zpm-registry.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
uplinks:
22
pm:
33
url: https://pm.community.intersystems.com/
4-
allow_packages: zpm*
4+
allow_packages: zpm*,?u*

0 commit comments

Comments
 (0)