Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
add_video_files_attachment_group
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 depends_on
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update_data
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 add_video_files
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\db\migration\data\v400;
15
16use phpbb\attachment\attachment_category;
17
18class add_video_files_attachment_group extends \phpbb\db\migration\migration
19{
20    public static function depends_on()
21    {
22        return ['\phpbb\db\migration\data\v400\dev'];
23    }
24
25    public function update_data()
26    {
27        return [
28            ['custom', [[$this, 'add_video_files']]],
29        ];
30    }
31
32    public function add_video_files()
33    {
34        $sql = 'SELECT group_id
35            FROM ' . $this->table_prefix . 'extension_groups
36            WHERE ' . $this->db->sql_build_array('SELECT', ['group_name' => 'VIDEO_FILES']);
37        $result = $this->db->sql_query($sql);
38        $video_group_id = $this->db->sql_fetchfield('group_id');
39        $this->db->sql_freeresult($result);
40
41        if ($video_group_id === false)
42        {
43            $sql = 'INSERT INTO ' . $this->table_prefix . 'extension_groups ' . $this->db->sql_build_array('INSERT', [
44                'group_name'        => 'VIDEO_FILES',
45                'cat_id'            => attachment_category::VIDEO,
46                'allow_group'        => 0,
47                'upload_icon'        => '',
48                'max_filesize'        => 0,
49                'allowed_forums'    => '',
50            ]);
51            $this->db->sql_query($sql);
52            $video_group_id = $this->db->sql_nextid();
53        }
54        else
55        {
56            $sql = 'UPDATE ' . $this->table_prefix . 'extension_groups SET cat_id = ' . attachment_category::VIDEO . '
57                WHERE ' . $this->db->sql_build_array('SELECT', ['group_id' => $video_group_id]);
58            $this->db->sql_query($sql);
59        }
60
61        $video_extensions = ['mp4', 'ogg', 'webm'];
62
63        foreach ($video_extensions as $video_extension)
64        {
65            $sql = 'SELECT group_id
66                FROM ' . $this->table_prefix . 'extensions
67                WHERE ' . $this->db->sql_build_array('SELECT', ['extension' => $video_extension]);
68            $result = $this->db->sql_query($sql);
69            $extension_group_id = $this->db->sql_fetchfield('group_id');
70            $this->db->sql_freeresult($result);
71
72            if ($extension_group_id === false)
73            {
74                $sql = 'INSERT INTO ' . $this->table_prefix . 'extensions ' . $this->db->sql_build_array('INSERT', [
75                    'group_id'    => $video_group_id,
76                    'extension'    => $video_extension,
77                ]);
78                $this->db->sql_query($sql);
79            }
80            else if ($extension_group_id != $video_group_id)
81            {
82                $sql = 'UPDATE ' . $this->table_prefix . "extensions SET group_id = $video_group_id
83                    WHERE " . $this->db->sql_build_array('SELECT', ['extension' => $video_extension]);
84                $this->db->sql_query($sql);
85            }
86        }
87    }
88}