Passed
Push — master ( 51ac1b...cef3f3 )
by Thomas
09:07
created

RemoveOldPermissionsTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 20
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 13 2
1
<?php
2
3
namespace LeKoala\DevToolkit\Tasks;
4
5
use SilverStripe\ORM\DB;
6
use SilverStripe\Dev\BuildTask;
7
use SilverStripe\Security\Group;
8
use LeKoala\DevToolkit\BuildTaskTools;
9
use SilverStripe\Security\Permission;
10
use SilverStripe\Subsites\Model\Subsite;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Subsites\Model\Subsite was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * @author LeKoala <[email protected]>
14
 */
15
class RemoveOldPermissionsTask extends BuildTask
16
{
17
    use BuildTaskTools;
18
19
    protected $title = "Remove 'other' permissions from the cms";
20
    private static $segment = 'RemoveOldPermissionsTask';
0 ignored issues
show
introduced by
The private property $segment is not used, and could be removed.
Loading history...
21
22
    public function run($request)
23
    {
24
        $this->request = $request;
25
26
        $permissions = Permission::get_codes(true);
27
28
        $other = $permissions['Other'];
29
        foreach ($other as $k => $infos) {
30
            DB::prepared_query("DELETE FROM Permission WHERE Code = ?", [$k]);
31
            DB::alteration_message("Deleting $k");
32
        }
33
34
        DB::alteration_message('All done!');
35
    }
36
}
37