Skip to content

Commit

Permalink
LDEV-4644 LDEV-4631 backport admin update notifcation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jul 20, 2023
1 parent 69bbcc3 commit de72753
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 60 deletions.
1 change: 0 additions & 1 deletion core/src/main/cfml/context/admin/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ this.tag.cookie.httpOnly = true; // prevent access to session cookies from javas
this.tag.cookie.sameSite = "strict";
this.tag.cookie.path = getAppFolderPath();


this.xmlFeatures = {
externalGeneralEntities: false,
secure: true,
Expand Down
93 changes: 64 additions & 29 deletions core/src/main/cfml/context/admin/ext.functions.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,66 @@
<cfreturn RandRange(1,0)>
</cffunction>

<cffunction name="updateAvailable" output="no">
<cfargument name="data" required="yes" type="struct">
<cfargument name="extensions" required="yes" type="query">
<cfset var result=variables.getdataByid(arguments.data.id,arguments.extensions)>
<cfscript>
function updateAvailable(required struct data, required query extensions ) output="yes" {
var result=variables.getdataByid( arguments.data.id, arguments.extensions );
if ( result.count() ==0 )
return false;
var sort = queryNew( "v,type,vf,extra", "varchar,varchar,varchar,varchar" );
var r= 0;
function parseType (v) {
var filterTypes = {"beta": 1, "snapshot" : 1,"rc" : 1, "alpha": 1};
var type = ( arguments.v contains "-" ) ? listLast( arguments.v, "-" ) : "";
var extra = "";
var vv = arguments.v;
if ( type == "" ){
var suffix = listLast( vv,"." );
if ( len( suffix ) gt 1 and !isNumeric( suffix[ 1 ] ) ){
extra = suffix; // i.e .jre8, .odbcj8
vv = listDeleteAt( vv, listlen( vv,"." ), "." );
}
} else if ( !structKeyExists( filtertypes, type ) ){
extra = type & ""; // i.e. -jre8 -jre11
type = "";
vv = listFirst( vv, "-" );
}
<cfif result.count()==0><cfreturn false></cfif>
<cfif arguments.data.version LT result.version>
<cfreturn true>
</cfif>
return {
v: vv,
type: type,
extra: extra
};
}
<cfreturn false>
</cffunction>
function addVersion(sort, v, installed){
var meta = parseType( arguments.v );
if ( arguments.installed.type neq meta.type ) return;
if ( arguments.installed.extra neq meta.extra ) return;
var r = queryAddRow( arguments.sort );
querySetCell( arguments.sort, "v", variables.toVersionSortable( meta.v ), r );
querySetCell( arguments.sort, "vf", arguments.v, r );
querySetCell( arguments.sort, "type", meta.type, r);
querySetCell( arguments.sort, "extra", meta.extra, r);
}
var installed = parseType( arguments.data.version );
loop array=#result.otherVersions# index="local.i" {
addVersion( sort, i, installed );
}
addVersion( sort, result.version, installed );
querySort(sort, "v", "desc");
if ( sort.recordcount gt 0 ){
if ( sort.v[ 1 ] GT variables.toVersionSortable( installed.v ) )
return sort.vf[ 1 ];
}
return false;
}
</cfscript>

<cffunction name="doFilter" returntype="string" output="false">
<cfargument name="filter" required="yes" type="string">
Expand All @@ -35,25 +80,13 @@
</cfif>
</cffunction>







<cfscript>
</cfscript>
<cffunction name="loadCFC" returntype="struct" output="yes">
<cfargument name="provider" required="yes" type="string">
<cfset systemOutput("deprecated function call:<print-stack-trace>",true,true)>
<cfreturn createObject('component',"ExtensionProviderProxy").init(arguments.provider)>
</cffunction>


<cfset request.loadCFC=loadCFC>


<cffunction name="getDetail" returntype="struct" output="yes">
<cfargument name="hashProvider" required="yes" type="string">
<cfargument name="appId" required="yes" type="string">
Expand Down Expand Up @@ -584,16 +617,18 @@
}
function toVersionsSorted(required array versions) localMode=true {
var vs = [=];
var sorted = queryNew("ver,sort");
loop array=arguments.versions item="local.v"{
vs[toVersionSortable(v)] = v;
row = queryAddRow(sorted);
querySetCell(sorted, "ver", v, row);
querySetCell(sorted, "sort", toVersionSortable(v), row);
}
var sorted = structSort(vs,"text", "desc");
var rtn = [=];
loop array=sorted item="local.v" {
rtn[v] = vs[v];
QuerySort(sorted, 'sort', 'desc');
var result = structNew("linked");
loop query=sorted {
result[sorted.sort] = sorted.ver;
}
return rtn;
return result;
}
function toVersionSortable(required string version) localMode=true {
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/cfml/context/admin/services.update.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
//dump(var:versionsStr,expand:false);
//dump(var:updateData,expand:false);
printError(error);
currMajor=listFirst(server.lucee.version,".");
selectedUpdate = getUpdateForMajorVersion(updateData.otherVersions, currMajor );
</cfscript>
<cfoutput>

Expand Down Expand Up @@ -231,7 +235,9 @@
<cfif len(versionsStr[key].upgrade) gt 0|| len(versionsStr[key].downgrade) gt 0>
<optgroup class="td_#UcFirst(Lcase(key))#" label="#stText.services.update.short[key]#">
<cfloop array="#versionsStr[key].upgrade#" index="i">
<option class="td_#UcFirst(Lcase(key))#" value="#i#">#stText.services.update.upgradeTo# #i#</option>
<option class="td_#UcFirst(Lcase(key))#" value="#i#"
<cfif i eq selectedUpdate>selected</cfif>
>#stText.services.update.upgradeTo# #i#</option>
</cfloop>

<cfloop array="#versionsStr[key].downgrade#" index="i">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@
return rsp;
}
string function getUpdateForMajorVersion( array versions, numeric majorVersion ){
loop from="#arrayLen(arguments.versions)#" to="1" index="local.v" step="-1" {
if ( listfirst(arguments.versions[ v ],".") eq arguments.majorVersion ){
return arguments.versions[ v ];
}
}
return "";
}
</cfscript>
65 changes: 39 additions & 26 deletions core/src/main/cfml/context/admin/update.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,47 @@
<cfinclude template="web_functions.cfm">

<cfset self = adminType & ".cfm">
<cfset stText.services.update.update="A patch <b>({available})</b> is available for your current version <b>({current})</b>.">
<cfset stText.services.update.update="There is a Lucee update <b>( {available} )</b> available for your current version <b>( {current} )</b>.">

<!--- Core --->
<cfif adminType == "server">
<cfset filterMajor = true>

<cfset curr=server.lucee.version>
<cfset curr=listFirst(server.lucee.version,".")>

<cfset updateInfo=getAvailableVersion()>
<cfif server.lucee.state EQ "RC">
<cfset get_rc = "">
<cfset get_rc = []>
<cfloop index="rcList" array="#updateInfo.otherVersions#">
<cfif listContainsNoCase(rcList,"-RC") EQ 1>
<cfset get_rc = listAppend(get_rc,rcList)>
<cfset arrayAppend(get_rc,rcList)>
</cfif>
</cfloop>
<cfset available = listlast(get_rc)>
<cfset available = Arraylast(get_rc)>
<cfset hasUpdate = curr LT available>
<cfelseif server.lucee.state EQ "stable">
<cfset get_stable = "">
<cfset get_stable = []>
<cfloop index="stableList" array="#updateInfo.otherVersions#">
<cfif ( !listContainsNoCase(stableList,"-SNAPSHOT") EQ 1 ) AND ( !listContainsNoCase(stableList,"-BETA") EQ 1 AND (!listContainsNoCase(stableList,"-RC") EQ 1) )>
<cfset get_stable = listAppend(get_stable,stableList)>
<cfset arrayAppend(get_stable,stableList)>
</cfif>
</cfloop>
<cfset available = listlast(get_stable)>
<cfset available = Arraylast(get_stable)>
<cfset hasUpdate = curr LT available>
<cfelse>
<cfset ava_ver = listfirst(updateInfo.available,"-")>
<cfif curr neq ava_ver>
<!-- only show updates for the current major version, ie on 5.4, not show 6.0 snapshots -->
<cfset curr=listFirst(server.lucee.version,".")>
<cfset available = getUpdateForMajorVersion(updateInfo.otherVersions, curr )>
<cfset ava_ver = listfirst(updateInfo.available,"-")>
<cfelse>
<cfset available = updateInfo.available>
</cfif>
<cfif len(available) eq 0 or server.lucee.version eq available>
<cfset hasUpdate = false>
<cfelse>
<cfset cur_ver = listfirst(curr,"-")>
<cfloop from="1" to="#listlen(cur_ver,".")#" index="i">
<cfif len(listgetat(ava_ver,i,".")) eq 1>
Expand All @@ -76,9 +90,10 @@
<cfset cur_ver = listsetat(cur_ver,i,last,".")>
</cfif>
</cfloop>
<cfset ava_ver = ava_ver&"-"&listlast(updateInfo.available,"-")>
<cfset ava_ver = ava_ver&"-"&listlast(available,"-")>
<cfset cur_ver = cur_ver&"-"&listlast(curr,"-")>
<cfset hasUpdate = structKeyExists(updateInfo,"available") && ava_ver gt cur_ver>
</cfif>
</cfif>
</cfif>

Expand All @@ -103,19 +118,21 @@

<cfsavecontent variable="ext" trim="true">
<cfloop query="extensions">
<cfset sct={}>
<cfloop list="#extensions.columnlist()#" item="key">
<cfset sct[key]=extensions[key]>
</cfloop>
<cfif !updateAvailable(sct,external)>
<cfcontinue>
</cfif>
<cfset uid=extensions.id>
<cfset link="">
<cfset dn="">
<cfset link="#self#?action=ext.applications&action2=detail&id=#uid#">
<cfscript>
sct = {};
loop list="#extensions.columnlist()#" item="key" {
sct[ key ]=extensions[ key ];
}
updateVersion= updateAvailable( sct, external );
if (updateVersion eq "false")
continue;
uid=extensions.id
link="";
dn="";
link="#self#?action=ext.applications&action2=detail&id=#uid#";
</cfscript>
<cfoutput>
<a href="#link#" style="color:red;text-decoration:none;">- #extensions.name#</a><br>
<a href="#link#" style="color:red;text-decoration:none;">- #extensions.name# - <b>#updateVersion#</b> ( #sct.version# ) </a><br>
</cfoutput>
</cfloop>
</cfsavecontent>
Expand Down Expand Up @@ -164,11 +181,7 @@
<cfif adminType == "server" and hasUpdate>
<div class="error">
<a href="server.cfm?action=services.update" style="color:red;text-decoration:none;">
<cfif server.lucee.state eq "SNAPSHOT" OR server.lucee.state eq "BETA">
#replace( stText.services.update.update, { '{available}': updateinfo.available, '{current}': curr } )#
<cfelse>
#replace( stText.services.update.update, { '{available}': available, '{current}': curr } )#
</cfif>
#replace( stText.services.update.update, { '{available}': available, '{current}': server.lucee.version } )#
</a>
</div>
</cfif>
Expand All @@ -177,7 +190,7 @@
<cfif extensions.recordcount and len(ext)>
<div class="error">
<a href="#self#?action=ext.applications" style="color:red;text-decoration:none;">
There are some updates available for your installed Extensions.<br>
There are updates available for your installed Extension(s).<br>
#ext#
</a>
</div>
Expand Down
20 changes: 19 additions & 1 deletion core/src/main/cfml/context/admin/web_functions.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,22 @@ function _byteFormatShort(numeric left,numeric right,string suffix){
<cfargument name="href" default="">

<a class="mail-icon" href="#arguments.href#" title="Send a test mail" width="25"></a>
</cffunction>
</cffunction>

<cfscript>
/**
* replaces double quote character with two consecutive quote characters
*/
public string function escapeDoubleQuotes(required string input) {
return replace(arguments.input, '"', '""', "all");
}
/**
* replaces single quote character with two consecutive quote characters
*/
public string function escapeSingleQuotes(required string input) {
return replace(arguments.input, "'", "''", "all");
}
</cfscript>
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="5.3.11.0-SNAPSHOT"/>
<property name="version" value="5.3.11.1-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.3.11.0-SNAPSHOT</version>
<version>5.3.11.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit de72753

Please sign in to comment.