Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
teampage
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 6
90
0.00% covered (danger)
0.00%
0 / 1
 effectively_installed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 depends_on
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update_schema
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
2
 revert_schema
0.00% covered (danger)
0.00%
0 / 10
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_groups_teampage
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
20
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\v310;
15
16class teampage extends \phpbb\db\migration\migration
17{
18    public function effectively_installed()
19    {
20        return $this->db_tools->sql_table_exists($this->table_prefix . 'teampage');
21    }
22
23    public static function depends_on()
24    {
25        return array('\phpbb\db\migration\data\v310\dev');
26    }
27
28    public function update_schema()
29    {
30        return array(
31            'add_tables'        => array(
32                $this->table_prefix . 'teampage'    => array(
33                    'COLUMNS'        => array(
34                        'teampage_id'        => array('UINT', null, 'auto_increment'),
35                        'group_id'            => array('UINT', 0),
36                        'teampage_name'        => array('VCHAR_UNI:255', ''),
37                        'teampage_position'    => array('UINT', 0),
38                        'teampage_parent'    => array('UINT', 0),
39                    ),
40                    'PRIMARY_KEY'        => 'teampage_id',
41                ),
42            ),
43            'drop_columns'        => array(
44                $this->table_prefix . 'groups'        => array(
45                    'group_teampage',
46                ),
47            ),
48        );
49    }
50
51    public function revert_schema()
52    {
53        return array(
54            'drop_tables'        => array(
55                $this->table_prefix . 'teampage',
56            ),
57            'add_columns'        => array(
58                $this->table_prefix . 'groups'        => array(
59                    'group_teampage'    => array('UINT', 0, 'after' => 'group_legend'),
60                ),
61            ),
62        );
63    }
64
65    public function update_data()
66    {
67        return array(
68            array('custom', array(array($this, 'add_groups_teampage'))),
69        );
70    }
71
72    public function add_groups_teampage()
73    {
74        $sql = 'SELECT teampage_id
75            FROM ' . TEAMPAGE_TABLE;
76        $result = $this->db->sql_query_limit($sql, 1);
77        $added_groups_teampage = (bool) $this->db->sql_fetchfield('teampage_id');
78        $this->db->sql_freeresult($result);
79
80        if (!$added_groups_teampage)
81        {
82            $sql = 'SELECT *
83                FROM ' . GROUPS_TABLE . '
84                WHERE group_type = ' . GROUP_SPECIAL . "
85                    AND (group_name = 'ADMINISTRATORS'
86                        OR group_name = 'GLOBAL_MODERATORS')
87                ORDER BY group_name ASC";
88            $result = $this->db->sql_query($sql);
89
90            $teampage_entries = array();
91            while ($row = $this->db->sql_fetchrow($result))
92            {
93                $teampage_entries[] = array(
94                    'group_id'            => (int) $row['group_id'],
95                    'teampage_name'        => '',
96                    'teampage_position'    => count($teampage_entries) + 1,
97                    'teampage_parent'    => 0,
98                );
99            }
100            $this->db->sql_freeresult($result);
101
102            if (count($teampage_entries))
103            {
104                $this->db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries);
105            }
106            unset($teampage_entries);
107        }
108
109    }
110}