File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
modules/@apostrophecms/page Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -920,6 +920,37 @@ module.exports = {
920
920
}
921
921
}
922
922
} ,
923
+ detectSchemaConflicts ( ) {
924
+ for ( const left of self . typeChoices ) {
925
+ for ( const right of self . typeChoices ) {
926
+ const diff = compareSchema ( left , right ) ;
927
+ if ( diff . size ) {
928
+ self . apos . util . warnDev ( `The page type "${ left . name } " has a conflict with "${ right . name } " (${ formatDiff ( diff ) } )` ) ;
929
+ }
930
+ }
931
+ }
932
+ function compareSchema ( left , right ) {
933
+ const conflicts = new Map ( ) ;
934
+ if ( left . name === right . name ) {
935
+ return conflicts ;
936
+ }
937
+
938
+ const leftSchema = self . apos . modules [ left . name ] . schema ;
939
+ const rightSchema = self . apos . modules [ right . name ] . schema ;
940
+ for ( const leftField of leftSchema ) {
941
+ const rightField = rightSchema . find ( field => field . name === leftField . name ) ;
942
+ if ( rightField && leftField . type !== rightField . type ) {
943
+ conflicts . set ( leftField . name , [ leftField . type , rightField . type ] ) ;
944
+ }
945
+ }
946
+
947
+ return conflicts ;
948
+ }
949
+ function formatDiff ( diff ) {
950
+ return Array . from ( diff . entries ( ) )
951
+ . map ( ( [ entry , [ left , right ] ] ) => `${ entry } :${ left } vs ${ entry } :${ right } ` ) ;
952
+ }
953
+ } ,
923
954
async manageOrphans ( ) {
924
955
const managed = self . apos . doc . getManaged ( ) ;
925
956
You can’t perform that action at this time.
0 commit comments