Skip to content

Commit

Permalink
Convert group code to ensure it is correct on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewis-everley committed Feb 1, 2022
1 parent 9e81a70 commit 268ff05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@

## 1.3.1

* Ensure that only one of each user group is created on build
* Ensure that only one of each user group is created on build

## 1.3.2

* Change default contact group tag matches what is converted by SilverStripe

## 1.3.3

* Ensure groups are using a compatible code when initially creating.
12 changes: 7 additions & 5 deletions src/extensions/GroupExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace SilverCommerce\ContactAdmin\Extensions;

use SilverStripe\ORM\DB;
use SilverStripe\Core\Convert;
use SilverStripe\Security\Group;
use SilverStripe\ORM\DataExtension;
use SilverCommerce\ContactAdmin\Helpers\ContactHelper;
use SilverStripe\ORM\DB;

/**
* Scaffold Any Default User Groups
Expand All @@ -22,17 +23,18 @@ public function requireDefaultRecords()
continue;
}

$code = Convert::raw2url($code);

$existing = Group::get()->find('Code', $code);

if (!empty($existing)) {
DB::alteration_message('Skipping existing group ' . $title, 'error');
continue;
}

$group = Group::create([
'Code' => $code,
'Title' => $title
]);
$group = Group::create();
$group->Code = $code;
$group->Title = $title;
$group->write();

DB::alteration_message('Created group ' . $title, 'created');
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ContactHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ContactHelper
* @var array
*/
private static $default_user_groups = [
'contact_users' => 'Contact Users'
'contact-users' => 'Contact Users'
];

/**
Expand Down

0 comments on commit 268ff05

Please sign in to comment.