GroupExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 12 2
1
<?php
2
namespace UserManagement\Extension;
3
4
use SilverStripe\ORM\DataExtension;
5
use SilverStripe\Security\Group;
6
7
/**
8
 * Class GroupExtension
9
 *
10
 * @package user-management
11
 */
12
class GroupExtension extends DataExtension
13
{
14
    /**
15
     * Add default records to database.
16
     *
17
     * This function is called whenever the database is built, after
18
     * the database tables have all been created. Overload
19
     * this to add default records when the database is built,
20
     * but make sure you call parent::requireDefaultRecords().
21
     */
22 1
    public function requireDefaultRecords()
23
    {
24 1
        parent::requireDefaultRecords();
25
26
        // Add default general group if doesn't exists
27 1
        $allGroups = Group::get()->filter('Title', 'general');
28 1
        if ($allGroups->count() == 0) {
29 1
            $authorGroup = new Group();
30 1
            $authorGroup->Code = 'general';
31 1
            $authorGroup->Title = _t(__CLASS__ . '.DefaultGroupTitleGeneral', 'General');
32 1
            $authorGroup->Sort = 1;
33 1
            $authorGroup->write();
34
        }
35
    }
36
}
37