Skip to content

Commit

Permalink
Merge branch 'hotfix-10.8.12' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicWatson committed Jun 16, 2017
2 parents 8e3d94d + 49903ab commit 44539a3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 83 deletions.
15 changes: 9 additions & 6 deletions system/Bootstrap.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,15 @@ component {
var logsMapping = request._presideMappings.logsMapping ?: "/logs";

thread name=CreateUUId() e=arguments.exception appMapping=appMapping appMappingPath=appMappingPath logsMapping=logsMapping {
new preside.system.services.errors.ErrorLogService(
appMapping = attributes.appMapping
, appMappingPath = attributes.appMappingPath
, logsMapping = attributes.logsMapping
, logDirectory = attributes.logsMapping & "/rte-logs"
).raiseError( attributes.e );
if ( !application.keyExists( "errorLogService" ) ) {
application.errorLogService = new preside.system.services.errors.ErrorLogService(
appMapping = attributes.appMapping
, appMappingPath = attributes.appMappingPath
, logsMapping = attributes.logsMapping
, logDirectory = attributes.logsMapping & "/rte-logs"
);
}
application.errorLogService.raiseError( attributes.e );
}

content reset=true;
Expand Down
29 changes: 12 additions & 17 deletions system/coldboxModifications/plugins/Renderer.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,13 @@
var locationUDF = variables.locateView;
var dPath = "";
var refMap = "";
var viewsRefMap = controller.getSetting("viewsRefMap");
</cfscript>

<!--- Check cached paths first --->
<cflock name="#locationKey#.#instance.lockName#" type="readonly" timeout="15" throwontimeout="true">
<cfif structkeyExists( controller.getSetting("viewsRefMap") ,locationKey) AND instance.isDiscoveryCaching>
<cfreturn structFind( controller.getSetting("viewsRefMap"), locationKey)>
</cfif>
</cflock>
<cfif structkeyExists( viewsRefMap, locationKey ) AND instance.isDiscoveryCaching>
<cfreturn viewsRefMap[ locationKey ]>
</cfif>

<cfscript>
if (left(arguments.view, 1) EQ "/") {
Expand Down Expand Up @@ -227,10 +226,8 @@
</cfscript>

<!--- Lock and create view entry --->
<cfif NOT structkeyExists( controller.getSetting("viewsRefMap") ,locationKey) >
<cflock name="#locationKey#.#instance.lockName#" type="exclusive" timeout="15" throwontimeout="true">
<cfset structInsert( controller.getSetting("viewsRefMap"), locationKey, refMap, true)>
</cflock>
<cfif NOT structkeyExists( viewsRefMap, locationKey )>
<cfset viewsRefMap[ locationKey ] = refMap>
</cfif>

<cfreturn refMap>
Expand Down Expand Up @@ -402,6 +399,7 @@
<cfset var viewLocations = "" />
<cfset var event = getRequestContext()>
<cfset var site = event.getSite()>
<cfset var layoutsRefMap = "">

<!--- Are we doing a nested view/layout explicit combo or already in its rendering algorithm? --->
<cfif len(trim(arguments.view))>
Expand Down Expand Up @@ -455,18 +453,15 @@
<cfelse>
<!--- Layout location key --->
<cfset cbox_layoutLocationKey = ( site.template ?: "" ) & cbox_currentLayout & arguments.module & cbox_explicitModule>
<cfset layoutsRefMap = controller.getSetting("layoutsRefMap")>

<!--- Check cached paths first --->
<cfif structkeyExists( controller.getSetting("layoutsRefMap") ,cbox_layoutLocationKey) AND instance.isDiscoveryCaching>
<cflock name="#cbox_layoutLocationKey#.#instance.lockName#" type="readonly" timeout="15" throwontimeout="true">
<cfset cbox_layoutLocation = structFind( controller.getSetting("layoutsRefMap"), cbox_layoutLocationKey)>
</cflock>
<cfif structkeyExists( layoutsRefMap, cbox_layoutLocationKey ) AND instance.isDiscoveryCaching>
<cfset cbox_layoutLocation = layoutsRefMap[ cbox_layoutLocationKey ]>
<cfelse>
<!--- Not found, cache it --->
<cflock name="#cbox_layoutLocationKey#.#instance.lockname#" type="exclusive" timeout="15" throwontimeout="true">
<cfset cbox_layoutLocation = cbox_locateUDF(cbox_currentLayout,arguments.module,cbox_explicitModule)>
<cfset structInsert( controller.getSetting("layoutsRefMap"), cbox_layoutLocationKey, cbox_layoutLocation, true)>
</cflock>
<cfset cbox_layoutLocation = cbox_locateUDF(cbox_currentLayout,arguments.module,cbox_explicitModule)>
<cfset layoutsRefMap[ cbox_layoutLocationKey ] = cbox_layoutLocation>
</cfif>

<cfset viewLocations = discoverViewPaths( reverse ( listRest( reverse( cbox_layoutLocation ), ".")),arguments.module,cbox_explicitModule) />
Expand Down
70 changes: 55 additions & 15 deletions system/services/assetManager/AssetManagerService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ component displayName="AssetManager Service" {
var derivativeDao = _getDerivativeDao();
var signature = getDerivativeConfigSignature( arguments.derivativeName );
var derivative = "";
var derivativeId = "";
var lockName = "getAssetDerivative( #arguments.assetId#, #arguments.derivativeName#, #arguments.versionId# )";
var selectFilter = "asset_derivative.asset = :asset_derivative.asset and asset_derivative.label = :asset_derivative.label";
var selectFilterParams = {
Expand All @@ -1158,19 +1159,32 @@ component displayName="AssetManager Service" {
selectFilter &= " and asset_derivative.asset_version is null";
}

lock type="readonly" name=lockName timeout=5 {
derivative = derivativeDao.selectData( filter=selectFilter, filterParams=selectFilterParams, selectFields=arguments.selectFields );
if ( derivative.recordCount ) {
return derivative;
derivative = derivativeDao.selectData( filter=selectFilter, filterParams=selectFilterParams, selectFields=arguments.selectFields );
if ( derivative.recordCount ) {
if ( ( derivative.asset_type ?: "" ) == "PENDING" ) {
return QueryNew( '' );
}

return derivative;
}

if ( arguments.createIfNotExists ) {
lock type="exclusive" name=lockName timeout=120 {
createAssetDerivative( assetId=arguments.assetId, versionId=arguments.versionId, derivativeName=arguments.derivativeName );
lock type="exclusive" name=lockName timeout=1 {
derivative = derivativeDao.selectData( filter=selectFilter, filterParams=selectFilterParams, selectFields=arguments.selectFields );
if ( derivative.recordCount ) {
if ( ( derivative.asset_type ?: "" ) == "PENDING" ) {
return QueryNew( '' );
}

return derivativeDao.selectData( filter=selectFilter, filterParams=selectFilterParams, selectFields=arguments.selectFields );
return derivative;
}

derivativeId = createAssetDerivativeRecord( assetId=arguments.assetId, versionId=arguments.versionId, derivativeName=arguments.derivativeName );
}

createAssetDerivative( derivativeId=derivativeId, assetId=arguments.assetId, versionId=arguments.versionId, derivativeName=arguments.derivativeName );

return derivativeDao.selectData( filter=selectFilter, filterParams=selectFilterParams, selectFields=arguments.selectFields );
}

return QueryNew( '' );
Expand Down Expand Up @@ -1215,11 +1229,28 @@ component displayName="AssetManager Service" {
}
}

public string function createAssetDerivativeRecord(
required string assetId
, required string derivativeName
, string versionId = ""
) {
var signature = getDerivativeConfigSignature( arguments.derivativeName );

return _getDerivativeDao().insertData( {
asset = arguments.assetId
, asset_version = arguments.versionId
, label = arguments.derivativeName & signature
, asset_type = "PENDING"
, storage_path = "PENDING"
} );
}

public string function createAssetDerivative(
required string assetId
, required string derivativeName
, string versionId = ""
, string versionId = ""
, array transformations = _getPreconfiguredDerivativeTransformations( arguments.derivativeName )
, string derivativeId = ""
) {
var signature = getDerivativeConfigSignature( arguments.derivativeName );
var asset = Len( Trim( arguments.versionId ) )
Expand Down Expand Up @@ -1270,13 +1301,22 @@ component displayName="AssetManager Service" {
, private = !isDerivativePubliclyAccessible( arguments.derivativeName ) && isAssetAccessRestricted( arguments.assetId )
);

return _getDerivativeDao().insertData( {
asset_type = assetType.typeName
, asset = arguments.assetId
, asset_version = arguments.versionId
, label = arguments.derivativeName & signature
, storage_path = storagePath
} );
if ( Len( Trim( arguments.derivativeId ) ) ) {
_getDerivativeDao().updateData( id=arguments.derivativeId, data={
asset_type = assetType.typeName
, storage_path = storagePath
} );

return arguments.derivativeId;
} else {
return _getDerivativeDao().insertData( {
asset_type = assetType.typeName
, asset = arguments.assetId
, asset_version = arguments.versionId
, label = arguments.derivativeName & signature
, storage_path = storagePath
} );
}
}

public struct function getAssetPermissioningSettings( required string assetId ) {
Expand Down
32 changes: 10 additions & 22 deletions system/services/devtools/ExtensionManagerService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ component singleton=true {
for( var extension in presentExtensions ) {
if ( !ArrayFind( listed, extension ) ) {

var extensionDir = _getExtensionsDirectory() & "/" & extension;
var manifestFilePath = extensionDir & "/manifest.json";
var extensionDir = _getExtensionsDirectory() & "/" & extension;
var manifestFilePath = extensionDir & "/manifest.json";

if ( Len( Trim( extensionDir ) ) && DirectoryExists( extensionDir ) && !FileExists( manifestFilePath ) ) {
throw( type="ExtensionManager.missingManifest", message="The extension, [#extensionDir#], does not have a manifest file" );
Expand Down Expand Up @@ -160,9 +160,7 @@ component singleton=true {
throw( type="ExtensionManager.missingManifest", message="The extension, [#arguments.extensionNameOrDirectory#], does not have a manifest file" );
}

lock name="manifestfileop-#manifestFilePath#" type="exclusive" timeout="10" {
fileContent = FileRead( manifestFilePath );
}
fileContent = FileRead( manifestFilePath );

try {
parsed = DeSerializeJson( fileContent );
Expand Down Expand Up @@ -205,13 +203,8 @@ component singleton=true {
// PRIVATE HELPERS
private array function _readExtensionsFromFile() {
var extensionsFile = _getExtensionsListFilePath();
var extensions = "";

lock name="extfileop-#extensionsFile#" type="exclusive" timeout="10" {
extensions = DeSerializeJson( FileRead( extensionsFile ) );
}

return extensions;
return DeSerializeJson( FileRead( extensionsFile ) );
}

private array function _listPresentExtensions() {
Expand All @@ -230,9 +223,7 @@ component singleton=true {
private void function _writeExtensionsToFile( required array extensions ) {
var extensionsFile = _getExtensionsListFilePath();

lock name="extfileop-#extensionsFile#" type="exclusive" timeout="10" {
FileWrite( extensionsFile, SerializeJson( arguments.extensions ) );
}
FileWrite( extensionsFile, SerializeJson( arguments.extensions ) );
}

private string function _getExtensionsListFilePath() {
Expand All @@ -243,15 +234,12 @@ component singleton=true {
var extensionsDir = _getExtensionsDirectory();
var extensionsFile = _getExtensionsListFilePath();

lock name="extfileop-#extensionsFile#" type="exclusive" timeout="10" {

if (!directoryExists(extensionsDir)){
directorycreate(extensionsDir);
}
if (!directoryExists(extensionsDir)){
directorycreate(extensionsDir);
}

if ( not FileExists( extensionsFile ) ) {
FileWrite( extensionsFile, "[]" );
}
if ( not FileExists( extensionsFile ) ) {
FileWrite( extensionsFile, "[]" );
}
}

Expand Down
52 changes: 37 additions & 15 deletions system/services/errors/ErrorLogService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ component displayName="Error Log Service" {
_setLogDirectory( arguments.logDirectory );
_setAppMapping( arguments.appMapping );
_setAppMappingPath( arguments.appMappingPath );
_setupListeners();

return this;
}
Expand Down Expand Up @@ -110,23 +111,11 @@ component displayName="Error Log Service" {

// PRIVATE HELPERS
private void function _callErrorListeners( required struct error ) {
_callListener( "#_getAppMappingPath()#.services.errors.ErrorHandler", arguments.error );
var listeners = _getListeners();

var extensions = new preside.system.services.devtools.ExtensionManagerService(
appMapping = _getAppMapping()
, extensionsDirectory = "#_getAppMapping()#/extensions"
).listExtensions( activeOnly=true );

for( var extension in extensions ) {
_callListener( "#_getAppMappingPath()#.extensions.#extension.name#.services.errors.ErrorHandler", arguments.error );
}
}

private void function _callListener( required string listenerPath, required struct error ) {
var filePath = ExpandPath( "/" & Replace( arguments.listenerPath, ".", "/", "all" ) & ".cfc" );
if ( FileExists( filePath ) ) {
for( var listenerPath in listeners ) {
try {
CreateObject( arguments.listenerPath ).raiseError( arguments.error );
CreateObject( listenerPath ).raiseError( arguments.error );
} catch ( any e ){}
}
}
Expand All @@ -151,6 +140,32 @@ component displayName="Error Log Service" {
}
}

private void function _setupListeners() {
var listeners = [];
var appListenerPath = "#_getAppMappingPath()#.services.errors.ErrorHandler";
var appFilePath = ExpandPath( "/" & Replace( appListenerPath, ".", "/", "all" ) & ".cfc" );

if ( FileExists( appFilePath ) ) {
listeners.append( appListenerPath );
}

var extensions = new preside.system.services.devtools.ExtensionManagerService(
appMapping = _getAppMapping()
, extensionsDirectory = "#_getAppMapping()#/extensions"
).listExtensions( activeOnly=true );

for( var extension in extensions ) {
var listenerPath = "#_getAppMappingPath()#.extensions.#extension.name#.services.errors.ErrorHandler";
var filePath = ExpandPath( "/" & Replace( listenerPath, ".", "/", "all" ) & ".cfc" );

if ( FileExists( filePath ) ) {
listeners.append( listenerPath );
}
}

_setListeners( listeners );
}

// GETTERS AND SETTERS
private any function _getLogDirectory() {
return _logDirectory;
Expand Down Expand Up @@ -178,4 +193,11 @@ component displayName="Error Log Service" {
_appMappingPath = arguments.appMappingPath;
}

private array function _getListeners() {
return _listeners;
}
private void function _setListeners( required array listeners ) {
_listeners = arguments.listeners;
}

}
13 changes: 5 additions & 8 deletions system/services/security/CsrfProtectionService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ component output=false singleton=true {
}

public boolean function validateToken( required string token ) output=false {
lock name="csrfProtectionService" timeout="10" {
var t = _getToken();
var t = _getToken();

if ( ( t.value ?: "" ) eq arguments.token ) {
var expired = DateDiff( "s", t.lastActive, Now() ) gte _getTokenExpiryInSeconds();
if ( ( t.value ?: "" ) eq arguments.token ) {
var expired = DateDiff( "s", t.lastActive, Now() ) gte _getTokenExpiryInSeconds();

t.lastActive = Now();
t.lastActive = Now();

return not expired;
}
return not expired;
}

return false;
}

Expand Down

0 comments on commit 44539a3

Please sign in to comment.