Skip to content

Commit 86bfb1b

Browse files
authored
Merge pull request #79 from intersystems-community/stage
Stage
2 parents e867c18 + c33fef3 commit 86bfb1b

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

module.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<Document name="zpm-registry.ZPM">
44
<Module>
55
<Name>zpm-registry</Name>
6+
<ExternalName>ZPM Registry</ExternalName>
67
<Description>Registry server for ZPM</Description>
7-
<Version>1.1.5</Version>
8+
<Version>1.1.6</Version>
89
<Packaging>module</Packaging>
910
<Dependencies>
1011
<ModuleReference>

src/cls/ZPM/Package.cls

+35-5
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ ClassMethod ServerURL() As %String
112112
Set host = host_":"_port
113113
}
114114
}
115-
#; If not behind the proxy where it have to be hidden redirect from / to /registry
116-
if %request.GetCgiEnv("HTTP_X_FORWARDED_HOST")="" {
117-
Set host = host _ $p(%request.Application, "/" ,1,*-1)
115+
If (%request.GetCgiEnv("HTTP_X_ORIGINAL_URI")'="") {
116+
Set path = $REPLACE(%request.URL, %request.Application,"",1,1)
117+
Set urlpart = $EXTRACT(%request.GetCgiEnv("HTTP_X_ORIGINAL_URI"),1,$FIND(%request.GetCgiEnv("HTTP_X_ORIGINAL_URI"), path) - $Length(path)-1)
118+
Set host = host _ $p(urlpart, "/" ,1,*-1)
119+
} Else {
120+
#; If not behind the proxy where it have to be hidden redirect from / to /registry
121+
If %request.GetCgiEnv("HTTP_X_FORWARDED_HOST")="" {
122+
Set host = host _ $p(%request.Application, "/" ,1,*-1)
123+
}
118124
}
119125
Return host
120126
}
@@ -507,7 +513,7 @@ ClassMethod LoadFromGitHub(Url = "")
507513
}
508514

509515
/// returns latest versions of packages
510-
ClassMethod GetLatest(searchTerms As %DynamicArray = "", Output pStatus As %Status) As %DynamicArray
516+
ClassMethod GetLatest(searchTerms As %DynamicArray = "", manifest As %String = "", allVersions As %String = "", Output pStatus As %Status) As %DynamicArray
511517
{
512518
Set pStatus = 1
513519
If ( '($CLASSNAME(searchTerms)="%Library.DynamicArray" ) || (searchTerms.%Size()=0) ) {
@@ -530,8 +536,9 @@ ClassMethod GetLatest(searchTerms As %DynamicArray = "", Output pStatus As %Stat
530536
}
531537
Set searchCondition = searchCondition_ " ) "
532538
}
533-
set sql = "SELECT name, repository, description, version "_
539+
set sql = "SELECT p1.name, p1.repository, p1.description, p1.version, ul.Host "_
534540
" FROM ZPM.Package p1 "_
541+
" LEFT JOIN ZPM.UpLink ul ON ul.ID = p1.UpLink " _
535542
" WHERE "_searchCondition_" "_
536543
" AND p1.version = ( 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 ) "
537544

@@ -552,8 +559,31 @@ ClassMethod GetLatest(searchTerms As %DynamicArray = "", Output pStatus As %Stat
552559
"name": (tResult.name),
553560
"description": (tResult.description),
554561
"repository": (tResult.repository),
562+
"origin": (tResult.Host),
555563
"versions": [(tResult.version)]
556564
}
565+
566+
If (manifest = "1") {
567+
Set tPkgInfo.manifest = ""
568+
Set package = ##class(ZPM.Package).%OpenId(tResult.name_"||"_tResult.version)
569+
If ($IsObject(package.manifest)) {
570+
while ('package.manifest.AtEnd) {
571+
Set tPkgInfo.manifest = tPkgInfo.manifest _ package.manifest.Read(100)
572+
}
573+
}
574+
}
575+
576+
If (allVersions = "1") {
577+
Set tPkgInfo.allVersions = []
578+
Set sql2 = "SELECT version "_
579+
" FROM ZPM.Package WHERE name = ? "_
580+
" ORDER BY versionMajor DESC, versionMinor DESC, versionPatch DESC, versionPrerelease DESC, versionBuildmetadata DESC"
581+
Set versionsResult = ##class(%SQL.Statement).%ExecDirect(, sql2, tResult.name)
582+
While versionsResult.%Next() {
583+
Do tPkgInfo.allVersions.%Push(versionsResult.version)
584+
}
585+
}
586+
557587
do tList.%Push(tPkgInfo)
558588
}
559589
Return tList

src/cls/ZPM/Registry.cls

+3-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ ClassMethod AllPackages() As %Status
238238
} Catch ex {}
239239
$$$ThrowOnError(##class(ZPM.UpLink).UpdatePackagesFromAllUpLinks())
240240

241-
Set tList = ##class(ZPM.Package).GetLatest(searchTerms, .tSC)
241+
Set manifest = %request.Get("manifest","")
242+
Set allVersions = %request.Get("allVersions","")
243+
Set tList = ##class(ZPM.Package).GetLatest(searchTerms, manifest, allVersions, .tSC)
242244

243245
If ($$$ISERR(tSC)) {
244246
Return ..ReportHttpStatusCode(..#HTTP400BADREQUEST, tSC)

0 commit comments

Comments
 (0)