diff --git a/interceptors/DataApiInterceptors.cfc b/interceptors/DataApiInterceptors.cfc index fe29bdd..3878f3c 100755 --- a/interceptors/DataApiInterceptors.cfc +++ b/interceptors/DataApiInterceptors.cfc @@ -111,6 +111,14 @@ component extends="coldbox.system.Interceptor" { } } + public void function preDeleteObjectData( event, interceptData ) { + if ( !_applicationLoaded ) return; + + if( isEmptyString( interceptData.id ?: "" ) ){ + interceptData.deletedIds = dataApiQueueService.getDeletedRecordIds( argumentCollection = interceptData ); + } + } + public void function postDeleteObjectData( event, interceptData ) { if ( !_applicationLoaded ) return; diff --git a/services/DataApiQueueService.cfc b/services/DataApiQueueService.cfc index b8aa3d8..d9e8cb9 100755 --- a/services/DataApiQueueService.cfc +++ b/services/DataApiQueueService.cfc @@ -235,7 +235,11 @@ component { string objectName = "" , string id = "" , any filter = {} + , array deletedIds = [] ) { + if( $helpers.isEmptyString( filter.id ?: "" ) && arrayLen( deletedIds ) ) { + filter = { id = deletedIds }; + } if ( IsStruct( filter ) && filter.count() == 1 ) { var value = filter.id ?: ( filter[ "#objectName#.id" ] ?: "" ); if ( !IsArray( value ) ) { @@ -349,6 +353,28 @@ component { return subscribers; } + public array function getDeletedRecordIds ( + required string objectName + , any filter = {} + , struct filterParams = {} + , array extraFilters = [] + , array savedFilters = [] + ){ + var values = []; + + arguments.selectFields = [ "id" ]; + + try{ + var queuedObj = $getPresideObject( objectName ).selectData( argumentCollection=arguments ); + if( queuedObj.recordcount ) { + values = valueArray( queuedObj, "id" ); + } + } catch( any e ) { + values = []; + } + + return values; + } // PRIVATE HELPERS private struct function _getQueueFilter( required string queueName ) {