aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.70_step_00184_html5_video.php
blob: a7ca83c4c09f3650873a59d39a16dbea50252940 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php

class Step00184Html5Video extends Migration
{
    /**
     * new config options to install
     */
    private $options_new = [
        [
            'name' => 'LOAD_EXTERNAL_MEDIA',
            'description' => 'Sollen externe Medien über [img/flash/audio/video] eingebunden werden? deny=nicht erlaubt, allow=erlaubt, proxy=proxy benutzen.',
            'section' => '',
            'type' => 'string',
            'value' => 'deny'
        ]
    ];

    /**
     * old config options to remove
     */
    private $options_old = [
        [
            'name' => 'EXTERNAL_IMAGE_EMBEDDING',
            'description' => 'Sollen externe Bilder über [img] eingebunden werden? deny=nicht erlaubt, allow=erlaubt, proxy=image proxy benutzen',
            'section' => '',
            'type' => 'string',
            'value' => 'deny'
        ], [
            'name' => 'EXTERNAL_FLASH_MOVIE_EMBEDDING',
            'description' => 'Sollen externe Flash-Filme mit Hilfe des [flash]-Tags der Schnellformatierung eingebunden werden? deny=nicht erlaubt, allow=erlaubt, proxy=image proxy benutzen',
            'section' => '',
            'type' => 'string',
            'value' => 'deny'
        ]
    ];

    /**
     * short description of this migration
     */
    function description()
    {
        return 'add database table for generic media proxy';
    }

    /**
     * insert list of options into config table
     */
    function insertConfig($options)
    {
        $db = DBManager::get();
        $time = time();

        $stmt = $db->prepare("
                INSERT INTO config
                    (config_id, field, value, is_default, type, section, mkdate, chdate, description)
                VALUES
                    (MD5(:name), :name, :value, 1, :type, :section, $time, $time, :description)
                ");

        foreach ($options as $option) {
            $stmt->execute($option);
        }
    }

    /**
     * remove list of options from config table
     */
    function deleteConfig($options)
    {
        $db = DBManager::get();

        $stmt = $db->prepare("DELETE FROM config WHERE field = :name");

        foreach ($options as $option) {
            $stmt->execute(['name' => $option['name']]);
        }
    }

    /**
     * perform this migration
     */
    function up()
    {
        $db = DBManager::get();

        $db->exec("CREATE TABLE media_cache (
                    id varchar(32) NOT NULL,
                    type varchar(64) NOT NULL,
                    chdate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
                    expires timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
                    PRIMARY KEY (id)) ENGINE=MyISAM");

        $db->exec("DROP TABLE image_proxy_cache");

        $this->insertConfig($this->options_new);
        $this->deleteConfig($this->options_old);
    }

    /**
     * revert this migration
     */
    function down()
    {
        $db = DBManager::get();

        $db->exec("CREATE TABLE image_proxy_cache (
                    id char(32) NOT NULL,
                    type char(10) NOT NULL,
                    length int(10) unsigned NOT NULL,
                    error char(15) NOT NULL,
                    chdate timestamp NOT NULL,
                    PRIMARY KEY (id),
                    KEY chdate (chdate, id)) ENGINE=MyISAM");

        $db->exec("DROP TABLE media_cache");

        $this->insertConfig($this->options_old);
        $this->deleteConfig($this->options_new);
    }
}