diff --git a/box.json b/box.json index 8c02c1982..dd10b2b0a 100644 --- a/box.json +++ b/box.json @@ -1,6 +1,6 @@ { "name":"ContentBox Tester Site", - "version":"6.0.0", + "version":"6.0.1", "author":"Ortus Solutions ", "shortDescription":"A tester site for developing the ContentBox Modular CMS", "type":"cms", diff --git a/changelog.md b/changelog.md index 1f1b857c2..9f4adc115 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * * * ## [Unreleased] +### Bugs +- [CONTENTBOX-1500](https://ortussolutions.atlassian.net/browse/CONTENTBOX-1500) Defensive coding for permissions migration on new instance ## [6.0.0] - 2023-12-18 diff --git a/modules/contentbox/migrations/2023_12_12_164002_EditorsCanClearCaches.cfc b/modules/contentbox/migrations/2023_12_12_164002_EditorsCanClearCaches.cfc index edad66d70..db50390d6 100755 --- a/modules/contentbox/migrations/2023_12_12_164002_EditorsCanClearCaches.cfc +++ b/modules/contentbox/migrations/2023_12_12_164002_EditorsCanClearCaches.cfc @@ -16,17 +16,31 @@ component { function up( schema, qb ){ var today = now(); var permID = createUUID(); - qb.newQuery() - .from( "cb_permission" ) - .insert( { - "permissionID" : permID, - "createdDate" : today, - "modifiedDate" : today, - "isDeleted" : 0, - "permission" : "RELOAD_CACHES", - "description" : "Ability to reload caches" - } ); - systemOutput( "√ - Reload Caches permission created", true ); + if ( + !qb.newQuery() + .from( "cb_permission" ) + .where( "permission", "RELOAD_CACHES" ) + .count() + ) { + qb.newQuery() + .from( "cb_permission" ) + .insert( { + "permissionID" : permID, + "createdDate" : today, + "modifiedDate" : today, + "isDeleted" : 0, + "permission" : "RELOAD_CACHES", + "description" : "Ability to reload caches" + } ); + systemOutput( "√ - Reload Caches permission created", true ); + } else { + var permId = qb + .newQuery() + .from( "cb_permission" ) + .where( "permission", "RELOAD_CACHES" ) + .first() + .permissionID; + } // Assign to Editors and Administrators var admin = qb @@ -36,10 +50,18 @@ component { .where( "role", "Administrator" ) .first(); - qb.newQuery() - .from( "cb_rolePermissions" ) - .insert( { "FK_roleID" : admin.roleID, "FK_permissionID" : permID } ); - systemOutput( "√ - Admin role updated with new permissions", true ); + if ( + !qb.newQuery() + .from( "cb_rolePermissions" ) + .where( "FK_permissionID", permID ) + .where( "FK_roleID", admin.roleID ) + .count() + ) { + qb.newQuery() + .from( "cb_rolePermissions" ) + .insert( { "FK_roleID" : admin.roleID, "FK_permissionID" : permID } ); + systemOutput( "√ - Admin role updated with new permissions", true ); + } var editor = qb .newQuery() @@ -48,10 +70,18 @@ component { .where( "role", "Editor" ) .first(); - qb.newQuery() - .from( "cb_rolePermissions" ) - .insert( { "FK_roleID" : editor.roleID, "FK_permissionID" : permID } ); - systemOutput( "√ - Editor role updated with new permissions", true ); + if ( + !qb.newQuery() + .from( "cb_rolePermissions" ) + .where( "FK_permissionID", permID ) + .where( "FK_roleID", editor.roleID ) + .count() + ) { + qb.newQuery() + .from( "cb_rolePermissions" ) + .insert( { "FK_roleID" : editor.roleID, "FK_permissionID" : permID } ); + systemOutput( "√ - Editor role updated with new permissions", true ); + } } function down( schema, qb ){