1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-13 20:24:08 +02:00

[ticket/11201] Change type from integer to service name

PHPBB3-11201
This commit is contained in:
Joas Schilling
2014-01-17 19:33:29 +01:00
parent 0ec6af38a9
commit aa2f0a652f
12 changed files with 210 additions and 34 deletions

View File

@@ -0,0 +1,106 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_types extends \phpbb\db\migration\migration
{
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\alpha2',
);
}
public function update_schema()
{
return array(
'change_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_type' => array('VCHAR:100', ''),
),
$this->table_prefix . 'profile_fields_lang' => array(
'field_type' => array('VCHAR:100', ''),
),
),
);
}
public function update_data()
{
return array(
array('custom', array(array($this, 'update_profile_fields_type'))),
array('custom', array(array($this, 'update_profile_fields_lang_type'))),
);
}
public function update_profile_fields_type()
{
// Update profile field types
$sql = 'SELECT field_type
FROM ' . $this->table_prefix . 'profile_fields
GROUP BY field_type';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql = 'UPDATE ' . $this->table_prefix . "profile_fields
SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "'
WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'";
$this->sql_query($sql);
}
$this->db->sql_freeresult($result);
}
public function update_profile_fields_lang_type()
{
// Update profile field language types
$sql = 'SELECT field_type
FROM ' . $this->table_prefix . 'profile_fields_lang
GROUP BY field_type';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql = 'UPDATE ' . $this->table_prefix . "profile_fields_lang
SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "'
WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'";
$this->sql_query($sql);
}
$this->db->sql_freeresult($result);
}
/**
* Determine the new field type for a given phpBB 3.0 field type
*
* @param $field_type int Field type in 3.0
* @return string Field new type which is used since 3.1
*/
public function convert_phpbb30_field_type($field_type)
{
switch ($field_type)
{
case FIELD_INT:
return 'profilefields.type.int';
case FIELD_STRING:
return 'profilefields.type.string';
case FIELD_TEXT:
return 'profilefields.type.text';
case FIELD_BOOL:
return 'profilefields.type.bool';
case FIELD_DROPDOWN:
return 'profilefields.type.dropdown';
case FIELD_DATE:
return 'profilefields.type.date';
default:
return $field_type;
}
}
}