aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/6.0.10_remove_restapi.php
blob: 50629162073b6bd13873e2e9a9257d81da0e77f7 (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
<?php
final class RemoveRestapi extends Migration
{
    private Migration $other_migration;

    public function __construct($verbose = false)
    {
        parent::__construct($verbose);

        require_once __DIR__ . '/1.127_setup_api.php';
        $this->other_migration = new SetupApi($verbose);
    }

    public function description()
    {
        return 'Removes the deprecated REST API (essentially reverts migration 1.127)';
    }

    protected function up()
    {
        $this->other_migration->dropTables();

        // Delete config
        $query = "DELETE `config`, `config_values`
                  FROM `config`
                  LEFT JOIN `config_values` USING(`field`)
                  WHERE `field` IN ('API_ENABLED', 'API_OAUTH_AUTH_PLUGIN')";
        DBManager::get()->exec($query);

        // Disable all RESTAPI-Plugins
        $query = "UPDATE `plugins`
                  SET `enabled` = 'no'
                  WHERE FIND_IN_SET('RESTAPIPlugin', `plugintype`)";
        DBManager::get()->exec($query);
    }

    protected function down()
    {
        // Add config entries
        $query = "INSERT IGNORE INTO `config`
                    (`field`, `value`, `type`, `range`, `section`,
                     `mkdate`, `chdate`, `description`)
                  VALUES (:field, :value, :type, 'global', 'global',
                          UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)";
        $statement = DBManager::get()->prepare($query);

        $statement->execute([
            ':field' => 'API_ENABLED',
            ':value' => 0,
            ':type'  => 'boolean',
            ':description' => 'Schaltet die REST-API an',
        ]);

        $statement->execute([
            ':field'       => 'API_OAUTH_AUTH_PLUGIN',
            ':value'       => 'Standard',
            ':type'        => 'string',
            ':description' => 'Definiert das für OAuth verwendete Authentifizierungsverfahren',
        ]);

        $this->other_migration->createTables();
    }
}