aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/5.1.48_cleanup_consultation_responsibilities.php
blob: 0dc3bfc988c0b99e18197830c33c58c07cd48c97 (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
<?php
final class CleanupConsultationResponsibilities extends Migration
{
    public function description()
    {
        return 'Remove all orphaned entries in table "consultation_responsibilities"';
    }

    protected function up()
    {
        $query = "DELETE FROM `consultation_responsibilities`
                  WHERE (
                    `range_type` = 'user'
                    AND `range_id` NOT IN (
                        SELECT `user_id`
                        FROM `auth_user_md5`
                    )
                  ) OR (
                    `range_type` = 'institute'
                    AND `range_id` NOT IN (
                        SELECT `Institut_id`
                        FROM `Institute`
                    )
                  ) OR (
                    `range_type` = 'statusgroup'
                    AND `range_id` NOT IN (
                        SELECT `statusgruppe_id`
                        FROM `statusgruppen`
                    )
                  )";
        DBManager::get()->exec($query);
    }
}