summaryrefslogtreecommitdiff
path: root/db/migrations/2018_01_01_000004_cleanup_group_privileges.php
blob: aead442276992c26c29dce056607775516a4fb18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

namespace Engelsystem\Migrations;

use Engelsystem\Database\Migration\Migration;

class CleanupGroupPrivileges extends Migration
{
    /**
     * Run the migration
     */
    public function up()
    {
        if (!$this->schema->hasTable('GroupPrivileges')) {
            return;
        }

        $connection = $this->schema->getConnection();

        // Add permissions to shikos to assign worklog entries
        $connection->insert(
            '
                INSERT INTO `GroupPrivileges` (`group_id`, `privilege_id`)
                VALUES (?, ?)
            ',
            [
                -40, // Shift Coordinator
                43,  // admin_user_worklog
            ]
        );

        // Delete unused privileges
        $connection->delete('
                DELETE FROM `Privileges`
                WHERE `name` IN(
                    \'user_wakeup\',
                    \'faq\',
                    \'credits\'
                )
            ');
    }

    /**
     * Reverse the migration
     */
    public function down()
    {
        if (!$this->schema->hasTable('GroupPrivileges')) {
            return;
        }

        // Add permissions to shikos to assign worklog entries
        $this->schema->getConnection()->delete(
            '
                DELETE FROM `GroupPrivileges`
                WHERE
                  group_id = ?
                  AND privilege_id = ?
            ',
            [
                -40, // Shift Coordinator
                43,  // admin_user_worklog
            ]
        );
    }
}