aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.120_create_open_graph_data_table.php
blob: 3dce2c52edbcac2096c80e5ddfda223118e7c4d0 (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 CreateOpenGraphDataTable extends Migration
{
    public function up() 
    {
        DBManager::get()->exec("
            CREATE TABLE IF NOT EXISTS `opengraphdata` (
                `url` varchar(1000) NOT NULL,
                `is_opengraph` tinyint(2) DEFAULT NULL,
                `title` text,
                `image` varchar(1024) DEFAULT NULL,
                `description` text,
                `type` varchar(64) DEFAULT NULL,
                `data` text NOT NULL,
                `last_update` bigint(20) NOT NULL,
                `chdate` bigint(20) NOT NULL,
                `mkdate` bigint(20) NOT NULL,
                PRIMARY KEY (`url`)
            ) ENGINE=MyISAM
        ");
        $options[] =
            [
            'name'        => 'OPENGRAPH_ENABLE',
            'type'        => 'boolean',
            'value'       => '1',
            'range'       => 'global',
            'section'     => 'global',
            'description' => 'De-/Aktiviert OpenGraph-Informationen und deren Abrufen.'
            ];

        $stmt = DBManager::get()->prepare("
                INSERT IGNORE INTO config
                    (config_id, field, value, is_default, type, `range`, section, mkdate, chdate, description)
                VALUES
                    (MD5(:name), :name, :value, 1, :type, :range, :section, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)
                ");

        foreach ($options as $option) {
            $stmt->execute($option);
        }
    }
    
    public function down()
    {
        DBManager::get()->exec("DROP TABLE TABLE IF EXISTS `opengraph`");
        DBManager::get()->exec("DELETE FROM config WHERE field = 'OPENGRAPH_ENABLE'");
    }
}