Skip to content

Commit

Permalink
Fix error when default group is not array
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewis-everley committed Sep 21, 2021
1 parent 88445f2 commit abffd5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ Minor update to:

# 2.2.1

* Allow changing (or removing) of default user groups
* Allow changing (or removing) of default user groups

# 2.2.2

* Minor fix for when default groups are not arrays
42 changes: 23 additions & 19 deletions src/extensions/GroupExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ public function requireDefaultRecords()
);

// Add default author group if no other group exists
foreach ($frontend_groups as $code) {
$group = Group::get()->find("Code", $code);
if (is_array($frontend_groups)) {
foreach ($frontend_groups as $code) {
$group = Group::get()->find("Code", $code);

if (empty($group)) {
$group = Group::create();
$group->Code = $code;
$group->Title = Users::convertCodeToName($code);
$group->write();
Permission::grant($group->ID, 'USERS_MANAGE_ACCOUNT');
if (empty($group)) {
$group = Group::create();
$group->Code = $code;
$group->Title = Users::convertCodeToName($code);
$group->write();
Permission::grant($group->ID, 'USERS_MANAGE_ACCOUNT');

DB::alteration_message("Front end user group {$code} created", 'created');
DB::alteration_message("Front end user group {$code} created", 'created');
}
}
}

Expand All @@ -46,18 +48,20 @@ public function requireDefaultRecords()
'verification_groups'
);

foreach ($verification_groups as $code) {
// Add default author group if no other group exists
$group = Group::get()->find("Code", $code);
if (is_array($verification_groups)) {
foreach ($verification_groups as $code) {
// Add default author group if no other group exists
$group = Group::get()->find("Code", $code);

if (empty($group)) {
$group = Group::create();
$group->Code = $code;
$group->Title = Users::convertCodeToName($code);
$group->write();
Permission::grant($group->ID, 'USERS_VERIFIED');
if (empty($group)) {
$group = Group::create();
$group->Code = $code;
$group->Title = Users::convertCodeToName($code);
$group->write();
Permission::grant($group->ID, 'USERS_VERIFIED');

DB::alteration_message("Verified users group {$code} created", 'created');
DB::alteration_message("Verified users group {$code} created", 'created');
}
}
}
}
Expand Down

0 comments on commit abffd5b

Please sign in to comment.