mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-05 16:27:38 +02:00
Merge remote-tracking branch 'github-nickvergessen/ticket/11201' into develop
* github-nickvergessen/ticket/11201: (50 commits) [ticket/11201] Remove empty calls section from .yml [ticket/11201] Split template file into multiple files [ticket/11201] Remove dependency from types on the manager [ticket/11201] Rename profilefields class to manager [ticket/11201] Fix parameter description [ticket/11201] Use !== null, its faster [ticket/11201] Also translate profile fields in UCP and ACP [ticket/11201] Add parameters and variables to profile field class [ticket/11201] Add commas on last array entry [ticket/11201] Allow translation of profile field name and explanation [ticket/11201] Fix some variable names [ticket/11201] Add tables to constructor in tests [ticket/11201] Add a method to return the translated full name of the type [ticket/11201] Remove db depending code from field class [ticket/11201] Add variables to classes and add constructor doc blocks [ticket/11201] Update copyright in class file [ticket/11201] Add visibility and remove unused variable [ticket/11201] Add some commas at the last array entry [ticket/11201] Cast some variables to integer [ticket/11201] Inject table names rather then using constants ... Conflicts: phpBB/config/services.yml
This commit is contained in:
106
phpBB/phpbb/db/migration/data/v310/profilefield_types.php
Normal file
106
phpBB/phpbb/db/migration/data/v310/profilefield_types.php
Normal 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 string 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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1474,52 +1474,7 @@ class tools
|
||||
}
|
||||
|
||||
// Get type
|
||||
if (strpos($column_data[0], ':') !== false)
|
||||
{
|
||||
list($orig_column_type, $column_length) = explode(':', $column_data[0]);
|
||||
if (!is_array($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']))
|
||||
{
|
||||
$column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'], $column_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule']))
|
||||
{
|
||||
switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][0])
|
||||
{
|
||||
case 'div':
|
||||
$column_length /= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][1];
|
||||
$column_length = ceil($column_length);
|
||||
$column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit']))
|
||||
{
|
||||
switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][0])
|
||||
{
|
||||
case 'mult':
|
||||
$column_length *= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][1];
|
||||
if ($column_length > $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][2])
|
||||
{
|
||||
$column_type = $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][3];
|
||||
}
|
||||
else
|
||||
{
|
||||
$column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$orig_column_type .= ':';
|
||||
}
|
||||
else
|
||||
{
|
||||
$orig_column_type = $column_data[0];
|
||||
$column_type = $this->dbms_type_map[$this->sql_layer][$column_data[0]];
|
||||
}
|
||||
list($column_type, $orig_column_type) = $this->get_column_type($column_data[0]);
|
||||
|
||||
// Adjust default value if db-dependent specified
|
||||
if (is_array($column_data[1]))
|
||||
@@ -1694,6 +1649,65 @@ class tools
|
||||
return $return_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column's database type from the type map
|
||||
*
|
||||
* @param string $column_map_type
|
||||
* @return array column type for this database
|
||||
* and map type without length
|
||||
*/
|
||||
function get_column_type($column_map_type)
|
||||
{
|
||||
if (strpos($column_map_type, ':') !== false)
|
||||
{
|
||||
list($orig_column_type, $column_length) = explode(':', $column_map_type);
|
||||
if (!is_array($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']))
|
||||
{
|
||||
$column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'], $column_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule']))
|
||||
{
|
||||
switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][0])
|
||||
{
|
||||
case 'div':
|
||||
$column_length /= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][1];
|
||||
$column_length = ceil($column_length);
|
||||
$column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit']))
|
||||
{
|
||||
switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][0])
|
||||
{
|
||||
case 'mult':
|
||||
$column_length *= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][1];
|
||||
if ($column_length > $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][2])
|
||||
{
|
||||
$column_type = $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][3];
|
||||
}
|
||||
else
|
||||
{
|
||||
$column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$orig_column_type .= ':';
|
||||
}
|
||||
else
|
||||
{
|
||||
$orig_column_type = $column_map_type;
|
||||
$column_type = $this->dbms_type_map[$this->sql_layer][$column_map_type];
|
||||
}
|
||||
|
||||
return array($column_type, $orig_column_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new column
|
||||
*/
|
||||
|
Reference in New Issue
Block a user