aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/5.2.6_update_core_plugins.php
blob: a9f504899b22d7962acfed8a5b2ae212a89ab18a (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
<?php

class UpdateCorePlugins extends Migration
{
    private static $core_widgets = [
        'core/ActivityFeed' => 'ActivityFeed',
        'core/Blubber' => 'Blubber',
        'core/ContentsWidget' => 'ContentsWidget',
        'core/Forum' => 'CoreForum',
        'core/EvaluationsWidget' => 'EvaluationsWidget',
        'core/NewsWidget' => 'NewsWidget',
        'core/QuickSelection' => 'QuickSelection',
        'core/ScheduleWidget' => 'ScheduleWidget',
        'core/TerminWidget' => 'TerminWidget'
    ];

    public function description()
    {
        return 'convert old core plugins into new core pugins';
    }

    public function up()
    {
        $db = DBManager::get();
        $stmt = $db->prepare('UPDATE plugins SET pluginpath = ? WHERE pluginclassname = ?');

        foreach (self::$core_widgets as $core_widget) {
            $stmt->execute(['', $core_widget]);
        }

        $db->exec("UPDATE help_content SET route = REPLACE(route, 'plugins.php/coreforum', 'dispatch.php/course/forum')");
        $db->exec("UPDATE help_tour_steps SET route = REPLACE(route, 'plugins.php/coreforum', 'dispatch.php/course/forum')");
    }

    public function down()
    {
        $db = DBManager::get();

        $stmt = $db->prepare('UPDATE plugins SET pluginpath = ? WHERE pluginclassname = ?');

        foreach (self::$core_widgets as $pluginpath => $core_widget) {
            $stmt->execute([$pluginpath, $core_widget]);
        }

        $db->exec("UPDATE help_content SET route = REPLACE(route, 'dispatch.php/course/forum', 'plugins.php/coreforum')");
        $db->exec("UPDATE help_tour_steps SET route = REPLACE(route, 'dispatch.php/course/forum', 'plugins.php/coreforum')");
    }
}