Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
profilefield_types
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 6
240
0.00% covered (danger)
0.00%
0 / 1
 depends_on
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 update_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 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 update_profile_fields_type
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 update_profile_fields_lang_type
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 convert_phpbb30_field_type
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
72
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 profilefield_types extends \phpbb\db\migration\migration
17{
18
19    public static function depends_on()
20    {
21        return array(
22            '\phpbb\db\migration\data\v310\alpha2',
23        );
24    }
25
26    public function update_schema()
27    {
28        return array(
29            'change_columns'    => array(
30                $this->table_prefix . 'profile_fields'            => array(
31                    'field_type'        => array('VCHAR:100', ''),
32                ),
33                $this->table_prefix . 'profile_fields_lang'        => array(
34                    'field_type'        => array('VCHAR:100', ''),
35                ),
36            ),
37        );
38    }
39
40    public function update_data()
41    {
42        return array(
43            array('custom', array(array($this, 'update_profile_fields_type'))),
44            array('custom', array(array($this, 'update_profile_fields_lang_type'))),
45        );
46    }
47
48    public function update_profile_fields_type()
49    {
50        // Update profile field types
51        $sql = 'SELECT field_type
52            FROM ' . $this->table_prefix . 'profile_fields
53            GROUP BY field_type';
54        $result = $this->db->sql_query($sql);
55
56        while ($row = $this->db->sql_fetchrow($result))
57        {
58            $sql = 'UPDATE ' . $this->table_prefix . "profile_fields
59                SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "'
60                WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'";
61            $this->sql_query($sql);
62        }
63        $this->db->sql_freeresult($result);
64    }
65
66    public function update_profile_fields_lang_type()
67    {
68        // Update profile field language types
69        $sql = 'SELECT field_type
70            FROM ' . $this->table_prefix . 'profile_fields_lang
71            GROUP BY field_type';
72        $result = $this->db->sql_query($sql);
73
74        while ($row = $this->db->sql_fetchrow($result))
75        {
76            $sql = 'UPDATE ' . $this->table_prefix . "profile_fields_lang
77                SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "'
78                WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'";
79            $this->sql_query($sql);
80        }
81        $this->db->sql_freeresult($result);
82    }
83
84    /**
85    * Determine the new field type for a given phpBB 3.0 field type
86    *
87    *    @param    $field_type    string        Field type in 3.0
88    *    @return        string        Field new type which is used since 3.1
89    */
90    public function convert_phpbb30_field_type($field_type)
91    {
92        switch ($field_type)
93        {
94            case FIELD_INT:
95                return 'profilefields.type.int';
96            case FIELD_STRING:
97                return 'profilefields.type.string';
98            case FIELD_TEXT:
99                return 'profilefields.type.text';
100            case FIELD_BOOL:
101                return 'profilefields.type.bool';
102            case FIELD_DROPDOWN:
103                return 'profilefields.type.dropdown';
104            case FIELD_DATE:
105                return 'profilefields.type.date';
106            default:
107                return $field_type;
108        }
109    }
110}