aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/6.0.2_captcha_by_altcha.php
blob: 3749c7140dde074b858f8490795a5df53a917baa (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
<?php
return new class extends Migration
{
    public function description(): string
    {
        return 'Creates a config entry for the key used for captchas and '
             . 'db storage for solved challenges.';
    }

    protected function up(): void
    {
        $query = "INSERT INTO `config` (`field`, `value`, `type`, `range`, `mkdate`, `chdate`, `description`)
                  VALUES ('CAPTCHA_KEY', '', 'string', 'global', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?)";
        DBManager::get()->execute($query, [
            'Speichert den für Captchas verwendeten Schlüssel (Wert leeren, um einen neuen zu generieren)',
        ]);

        $query = "CREATE TABLE `captcha_challenges` (
                      `challenge_id` int(11) NOT NULL AUTO_INCREMENT,
                      `salt` CHAR(32) COLLATE `latin1_bin` NOT NULL,
                      `number` INT(11) UNSIGNED NOT NULL,
                      `mkdate` INT(11) UNSIGNED NOT NULL,
                      PRIMARY KEY (`challenge_id`)                        
                  )";
        DBManager::get()->exec($query);
    }

    protected function down(): void
    {
        $query = "DROP TABLE `captcha_challenges`";
        DBManager::get()->exec($query);

        $query = "DELETE `config`, `config_values`
                  FROM `config`
                  LEFT JOIN `config_values` USING (`field`)
                  WHERE `field` = 'CAPTCHA_KEY'";
        DBManager::get()->exec($query);
    }
};