File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { StrapiContext } from './@types' ;
2
2
import { setupGQL } from './graphql' ;
3
3
import permissions from './permissions' ;
4
+ import { CONFIG_PARAMS } from './utils/constants' ;
5
+ import { getPluginService } from './utils/getPluginService' ;
4
6
5
7
export default async ( { strapi } : StrapiContext ) => {
6
8
if ( strapi . plugin ( 'graphql' ) ) {
@@ -53,4 +55,20 @@ export default async ({ strapi }: StrapiContext) => {
53
55
] ;
54
56
55
57
await strapi . admin . services . permission . actionProvider . registerMany ( actions ) ;
58
+
59
+ const commonService = getPluginService ( strapi , 'common' ) ;
60
+ const enabledCollections = await commonService . getConfig ( CONFIG_PARAMS . ENABLED_COLLECTIONS , [ ] ) ;
61
+
62
+ if ( enabledCollections . length ) {
63
+ strapi . db . lifecycles . subscribe ( {
64
+ models : enabledCollections ,
65
+ afterDelete : async ( event ) => {
66
+ const uid = event . model . uid ;
67
+ const { documentId, locale } = event . result ;
68
+ const relation = [ uid , documentId ] . join ( ':' ) ;
69
+ await commonService . perRemove ( relation , locale ) ;
70
+ } ,
71
+ } ) ;
72
+ }
73
+
56
74
} ;
Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ export const getCommentRepositorySource = (strapi: CoreStrapi) => {
34
34
return strapi . query ( modelUid ) . delete ( params )
35
35
. then ( result => ( result ? shouldValidateObject ( isValidationEnabled , commentResultValidator . findOne ) ( result ) : null ) ) ;
36
36
} ,
37
+ async deleteMany ( params : Params ) {
38
+ return strapi . query ( modelUid ) . deleteMany ( params )
39
+ } ,
37
40
updateMany ( params : Params ) {
38
41
return strapi . query ( modelUid ) . updateMany ( params ) ;
39
42
} ,
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ const commonService = ({ strapi }: StrapiContext) => ({
161
161
isAdmin = false ,
162
162
omit = [ ] ,
163
163
locale,
164
- limit
164
+ limit,
165
165
} : clientValidator . FindAllInHierarchyValidatorSchema ,
166
166
relatedEntity ?: any ,
167
167
) {
@@ -342,6 +342,17 @@ const commonService = ({ strapi }: StrapiContext) => ({
342
342
return content ;
343
343
} ,
344
344
345
+ async perRemove ( related : string , locale ?: string ) {
346
+ const defaultLocale = await strapi . plugin ( 'i18n' ) ?. service ( 'locales' ) . getDefaultLocale ( ) || null ;
347
+ return getCommentRepository ( strapi )
348
+ . deleteMany ( {
349
+ where : {
350
+ related,
351
+ $or : [ { locale } , defaultLocale === locale ? { locale : { $eq : null } } : null ] . filter ( Boolean )
352
+ } ,
353
+ } ) ;
354
+ } ,
355
+
345
356
346
357
registerLifecycleHook ( /*{ callback, contentTypeName, hookName }*/ ) {
347
358
} ,
You can’t perform that action at this time.
0 commit comments