diff options
Diffstat (limited to 'phpBB/phpbb/db')
8 files changed, 397 insertions, 2 deletions
| diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_cleanup.php b/phpBB/phpbb/db/migration/data/v310/profilefield_cleanup.php new file mode 100644 index 0000000000..9e7ba68327 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_cleanup.php @@ -0,0 +1,51 @@ +<?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_cleanup extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_occ') && +			!$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_interests'); +	} + +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\profilefield_interests', +			'\phpbb\db\migration\data\v310\profilefield_occupation', +		); +	} + +	public function update_schema() +	{ +		return array( +			'drop_columns'	=> array( +				$this->table_prefix . 'users'			=> array( +					'user_occ', +					'user_interests', +				), +			), +		); +	} + +	public function revert_schema() +	{ +		return array( +			'add_columns'	=> array( +				$this->table_prefix . 'users'			=> array( +					'user_occ'			=> array('MTEXT', ''), +					'user_interests'	=> array('MTEXT', ''), +				), +			), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_interests.php b/phpBB/phpbb/db/migration/data/v310/profilefield_interests.php new file mode 100644 index 0000000000..d73bc78edb --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_interests.php @@ -0,0 +1,47 @@ +<?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_interests extends \phpbb\db\migration\profilefield_base_migration +{ +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\profilefield_types', +		); +	} + +	protected $profilefield_name = 'phpbb_interests'; + +	protected $profilefield_database_type = array('MTEXT', ''); + +	protected $profilefield_data = array( +		'field_name'			=> 'phpbb_interests', +		'field_type'			=> 'profilefields.type.text', +		'field_ident'			=> 'phpbb_interests', +		'field_length'			=> '3|30', +		'field_minlen'			=> '2', +		'field_maxlen'			=> '500', +		'field_novalue'			=> '', +		'field_default_value'	=> '', +		'field_validation'		=> '.*', +		'field_required'		=> 0, +		'field_show_novalue'	=> 0, +		'field_show_on_reg'		=> 0, +		'field_show_on_pm'		=> 0, +		'field_show_on_vt'		=> 0, +		'field_show_profile'	=> 1, +		'field_hide'			=> 0, +		'field_no_view'			=> 0, +		'field_active'			=> 1, +	); + +	protected $user_column_name = 'user_interests'; +} diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_location.php b/phpBB/phpbb/db/migration/data/v310/profilefield_location.php new file mode 100644 index 0000000000..4e62eab2d7 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_location.php @@ -0,0 +1,48 @@ +<?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_location extends \phpbb\db\migration\profilefield_base_migration +{ +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\profilefield_types', +			'\phpbb\db\migration\data\v310\profilefield_on_memberlist', +		); +	} + +	protected $profilefield_name = 'phpbb_location'; + +	protected $profilefield_database_type = array('VCHAR', ''); + +	protected $profilefield_data = array( +		'field_name'			=> 'phpbb_location', +		'field_type'			=> 'profilefields.type.string', +		'field_ident'			=> 'phpbb_location', +		'field_length'			=> '20', +		'field_minlen'			=> '2', +		'field_maxlen'			=> '100', +		'field_novalue'			=> '', +		'field_default_value'	=> '', +		'field_validation'		=> '.*', +		'field_required'		=> 0, +		'field_show_novalue'	=> 0, +		'field_show_on_reg'		=> 0, +		'field_show_on_pm'		=> 1, +		'field_show_on_vt'		=> 1, +		'field_show_profile'	=> 1, +		'field_hide'			=> 0, +		'field_no_view'			=> 0, +		'field_active'			=> 1, +	); + +	protected $user_column_name = 'user_from'; +} diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_occupation.php b/phpBB/phpbb/db/migration/data/v310/profilefield_occupation.php new file mode 100644 index 0000000000..b0ea961c08 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_occupation.php @@ -0,0 +1,47 @@ +<?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_occupation extends \phpbb\db\migration\profilefield_base_migration +{ +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\profilefield_interests', +		); +	} + +	protected $profilefield_name = 'phpbb_occupation'; + +	protected $profilefield_database_type = array('MTEXT', ''); + +	protected $profilefield_data = array( +		'field_name'			=> 'phpbb_occupation', +		'field_type'			=> 'profilefields.type.text', +		'field_ident'			=> 'phpbb_occupation', +		'field_length'			=> '3|30', +		'field_minlen'			=> '2', +		'field_maxlen'			=> '500', +		'field_novalue'			=> '', +		'field_default_value'	=> '', +		'field_validation'		=> '.*', +		'field_required'		=> 0, +		'field_show_novalue'	=> 0, +		'field_show_on_reg'		=> 0, +		'field_show_on_pm'		=> 0, +		'field_show_on_vt'		=> 0, +		'field_show_profile'	=> 1, +		'field_hide'			=> 0, +		'field_no_view'			=> 0, +		'field_active'			=> 1, +	); + +	protected $user_column_name = 'user_occ'; +} diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_on_memberlist.php b/phpBB/phpbb/db/migration/data/v310/profilefield_on_memberlist.php new file mode 100644 index 0000000000..ce51944c3e --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_on_memberlist.php @@ -0,0 +1,47 @@ +<?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_on_memberlist extends \phpbb\db\migration\migration +{ +	public function effectively_installed() +	{ +		return $this->db_tools->sql_column_exists($this->table_prefix . 'profile_fields', 'field_show_on_ml'); +	} + +	static public function depends_on() +	{ +		return array( +			'\phpbb\db\migration\data\v310\profilefield_cleanup', +		); +	} + +	public function update_schema() +	{ +		return array( +			'add_columns'		=> array( +				$this->table_prefix . 'profile_fields'	=> array( +					'field_show_on_ml'		=> array('BOOL', 0), +				), +			), +		); +	} + +	public function revert_schema() +	{ +		return array( +			'drop_columns'	=> array( +				$this->table_prefix . 'profile_fields'	=> array( +					'field_show_on_ml', +				), +			), +		); +	} +} diff --git a/phpBB/phpbb/db/migration/helper.php b/phpBB/phpbb/db/migration/helper.php index 28a6a56511..009ad1da9f 100644 --- a/phpBB/phpbb/db/migration/helper.php +++ b/phpBB/phpbb/db/migration/helper.php @@ -53,7 +53,7 @@ class helper  						$steps[] = array(  							'dbtools.perform_schema_changes', array(array(  									$change_type	=> array( -									$value, +										(!is_int($key)) ? $key : 0	=> $value,  								),  							)),  						); diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php new file mode 100644 index 0000000000..dec7a4c2bb --- /dev/null +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -0,0 +1,155 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration; + +abstract class profilefield_base_migration extends \phpbb\db\migration\migration +{ +	protected $profilefield_name; + +	protected $profilefield_database_type; + +	protected $profilefield_data; + +	protected $user_column_name; + +	public function effectively_installed() +	{ +		return $this->db_tools->sql_column_exists($this->table_prefix . 'profile_fields_data', 'pf_' . $this->profilefield_name); +	} + +	public function update_schema() +	{ +		return array( +			'add_columns'	=> array( +				$this->table_prefix . 'profile_fields_data'			=> array( +					'pf_' . $this->profilefield_name		=> $this->profilefield_database_type, +				), +			), +		); +	} + +	public function revert_schema() +	{ +		return array( +			'drop_columns'	=> array( +				$this->table_prefix . 'profile_fields_data'			=> array( +					'pf_' . $this->profilefield_name, +				), +			), +		); +	} + +	public function update_data() +	{ +		return array( +			array('custom', array(array($this, 'create_custom_field'))), +			array('custom', array(array($this, 'convert_user_field_to_custom_field'))), +		); +	} + +	public function create_custom_field() +	{ +		$sql = 'SELECT MAX(field_order) as max_field_order +			FROM ' . PROFILE_FIELDS_TABLE; +		$result = $this->db->sql_query($sql); +		$max_field_order = (int) $this->db->sql_fetchfield('max_field_order'); +		$this->db->sql_freeresult($result); + +		$sql_ary = array_merge($this->profilefield_data, array( +			'field_order'			=> $max_field_order + 1, +		)); + +		$sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); +		$this->db->sql_query($sql); +		$field_id = (int) $this->db->sql_nextid(); + +		$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE); + +		$sql = 'SELECT lang_id +			FROM ' . LANG_TABLE; +		$result = $this->db->sql_query($sql); +		while ($lang_id = (int) $this->db->sql_fetchfield('lang_id')) +		{ +			$insert_buffer->insert(array( +				'field_id'				=> $field_id, +				'lang_id'				=> $lang_id, +				'lang_name'				=> strtoupper(substr($this->profilefield_name, 6)),// Remove phpbb_ from field name +				'lang_explain'			=> '', +				'lang_default_value'	=> '', +			)); +		} +		$this->db->sql_freeresult($result); + +		$insert_buffer->flush(); +	} + +	/** +	* @param int			$start		Start of staggering step +	* @return		mixed		int start of the next step, null if the end was reached +	*/ +	public function convert_user_field_to_custom_field($start) +	{ +		$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'profile_fields_data'); +		$limit = 250; +		$converted_users = 0; + +		$sql = 'SELECT user_id, ' . $this->user_column_name . ' +			FROM ' . $this->table_prefix . 'users +			WHERE ' . $this->user_column_name . " <> '' +			ORDER BY user_id"; +		$result = $this->db->sql_query_limit($sql, $limit, $start); + +		while ($row = $this->db->sql_fetchrow($result)) +		{ +			$converted_users++; + +			$cp_data = array( +				'pf_' . $this->profilefield_name		=> $row[$this->user_column_name], +			); + +			$sql = 'UPDATE ' . $this->table_prefix . 'profile_fields_data +				SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . ' +				WHERE user_id = ' . (int) $row['user_id']; +			$this->db->sql_query($sql); + +			if (!$this->db->sql_affectedrows()) +			{ +				$cp_data['user_id'] = (int) $row['user_id']; +				$cp_data = array_merge($this->get_insert_sql_array(), $cp_data); +				$insert_buffer->insert($cp_data); +			} +		} +		$this->db->sql_freeresult($result); + +		$insert_buffer->flush(); + +		if ($converted_users < $limit) +		{ +			// No more users left, we are done... +			return; +		} + +		return $start + $limit; +	} + +	protected function get_insert_sql_array() +	{ +		static $profile_row; + +		if ($profile_row === null) +		{ +			global $phpbb_container; +			$manager = $phpbb_container->get('profilefields.manager'); +			$profile_row = $manager->build_insert_sql_array(array()); +		} + +		return $profile_row; +	} +} diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php index 65098b643b..3a7207e743 100644 --- a/phpBB/phpbb/db/tools.php +++ b/phpBB/phpbb/db/tools.php @@ -492,7 +492,7 @@ class tools  			// here lies an array, filled with information compiled on the column's data  			$prepared_column = $this->sql_prepare_column_data($table_name, $column_name, $column_data); -			if (isset($prepared_column['auto_increment']) && strlen($column_name) > 26) // "${column_name}_gen" +			if (isset($prepared_column['auto_increment']) && $prepared_column['auto_increment'] && strlen($column_name) > 26) // "${column_name}_gen"  			{  				trigger_error("Index name '${column_name}_gen' on table '$table_name' is too long. The maximum auto increment column length is 26 characters.", E_USER_ERROR);  			} | 
