diff --git a/src/Dev/FixFolderPermissionsHelper.php b/src/Dev/FixFolderPermissionsHelper.php new file mode 100644 index 00000000..7d1895c9 --- /dev/null +++ b/src/Dev/FixFolderPermissionsHelper.php @@ -0,0 +1,41 @@ +setTable('"' . File::singleton()->baseTable() . '"') + ->setAssignments(['"CanViewType"' => 'Inherit']) + ->setWhere([ + '"CanViewType" IS NULL', + '"ClassName"' => Folder::class + ]) + ->execute(); + + // This part won't work if run from the CLI, because Apache and the CLI don't share the same cache. + InheritedPermissionFlusher::flush(); + + return DB::affected_rows(); + } +} diff --git a/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php b/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php new file mode 100644 index 00000000..341a50bc --- /dev/null +++ b/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php @@ -0,0 +1,26 @@ +run(); + + $this->assertEquals('Inherit', Folder::get()->filter('Name', 'ParentFolder')->first()->CanViewType); + $this->assertEquals('Anyone', Folder::get()->filter('Name', 'SubFolder')->first()->CanViewType); + $this->assertEquals('Inherit', Folder::get()->filter('Name', 'AnotherFolder')->first()->CanViewType); + $this->assertEquals(2, $updated); + } +} diff --git a/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.yml b/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.yml new file mode 100644 index 00000000..401328fa --- /dev/null +++ b/tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.yml @@ -0,0 +1,11 @@ +SilverStripe\Assets\Folder: + parent: + Name: ParentFolder + CanViewType: NULL + subfolder: + Name: SubFolder + Parent: =>SilverStripe\Assets\Folder.parent + CanViewType: Anyone + anotherfolder: + Name: AnotherFolder + CanViewType: