aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2014-02-10 13:52:12 +0100
committerNils Adermann <naderman@naderman.de>2014-02-10 13:52:12 +0100
commit840ab75520726e4db689ab1a92de6c17d86b107b (patch)
tree887704c33fe0ebebbceceee0544969e0ff1f631b /phpBB/phpbb
parent02674de89367895642b57450b5444ab23488ab9b (diff)
parent4663ea7c8288ae56e00e2270aee49cb14a7c0276 (diff)
downloadforums-840ab75520726e4db689ab1a92de6c17d86b107b.tar
forums-840ab75520726e4db689ab1a92de6c17d86b107b.tar.gz
forums-840ab75520726e4db689ab1a92de6c17d86b107b.tar.bz2
forums-840ab75520726e4db689ab1a92de6c17d86b107b.tar.xz
forums-840ab75520726e4db689ab1a92de6c17d86b107b.zip
Merge pull request #1988 from nickvergessen/ticket/12115
[ticket/12115] Convert occupation profile field to custom field
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/db/migration/data/v310/profilefield_cleanup.php51
-rw-r--r--phpBB/phpbb/db/migration/data/v310/profilefield_interests.php47
-rw-r--r--phpBB/phpbb/db/migration/data/v310/profilefield_occupation.php47
-rw-r--r--phpBB/phpbb/db/migration/profilefield_base_migration.php155
-rw-r--r--phpBB/phpbb/profilefields/type/type_base.php8
-rw-r--r--phpBB/phpbb/profilefields/type/type_bool.php2
-rw-r--r--phpBB/phpbb/profilefields/type/type_date.php6
-rw-r--r--phpBB/phpbb/profilefields/type/type_dropdown.php4
-rw-r--r--phpBB/phpbb/profilefields/type/type_int.php4
-rw-r--r--phpBB/phpbb/profilefields/type/type_interface.php17
-rw-r--r--phpBB/phpbb/profilefields/type/type_string_common.php12
11 files changed, 339 insertions, 14 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_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/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/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php
index 95e9b8768b..9c363a7b4e 100644
--- a/phpBB/phpbb/profilefields/type/type_base.php
+++ b/phpBB/phpbb/profilefields/type/type_base.php
@@ -79,6 +79,14 @@ abstract class type_base implements type_interface
/**
* {@inheritDoc}
*/
+ public function get_field_name($field_name)
+ {
+ return isset($this->user->lang[$field_name]) ? $this->user->lang[$field_name] : $field_name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php
index 47a5ed4992..fa9c0a8714 100644
--- a/phpBB/phpbb/profilefields/type/type_bool.php
+++ b/phpBB/phpbb/profilefields/type/type_bool.php
@@ -136,7 +136,7 @@ class type_bool extends type_base
if (!$field_value && $field_data['field_required'])
{
- return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
+ return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php
index 0de80f2baf..fc012dd97a 100644
--- a/phpBB/phpbb/profilefields/type/type_date.php
+++ b/phpBB/phpbb/profilefields/type/type_date.php
@@ -159,17 +159,17 @@ class type_date extends type_base
if ((!$day || !$month || !$year) && $field_data['field_required'])
{
- return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
+ return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
}
if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
{
- return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']);
+ return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name']));
}
if (checkdate($month, $day, $year) === false)
{
- return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']);
+ return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name']));
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php
index b5b393d91b..bcf0ba05f9 100644
--- a/phpBB/phpbb/profilefields/type/type_dropdown.php
+++ b/phpBB/phpbb/profilefields/type/type_dropdown.php
@@ -137,12 +137,12 @@ class type_dropdown extends type_base
if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value))
{
- return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']);
+ return $this->user->lang('FIELD_INVALID_VALUE', $this->get_field_name($field_data['lang_name']));
}
if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
{
- return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
+ return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php
index 77a4f813da..b89faca018 100644
--- a/phpBB/phpbb/profilefields/type/type_int.php
+++ b/phpBB/phpbb/profilefields/type/type_int.php
@@ -126,11 +126,11 @@ class type_int extends type_base
if ($field_value < $field_data['field_minlen'])
{
- return $this->user->lang('FIELD_TOO_SMALL', (int) $row['field_minlen'], $row['lang_name']);
+ return $this->user->lang('FIELD_TOO_SMALL', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
}
else if ($field_value > $field_data['field_maxlen'])
{
- return $this->user->lang('FIELD_TOO_LARGE', (int) $row['field_maxlen'], $row['lang_name']);
+ return $this->user->lang('FIELD_TOO_LARGE', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php
index 7d0cf7662f..94f6882524 100644
--- a/phpBB/phpbb/profilefields/type/type_interface.php
+++ b/phpBB/phpbb/profilefields/type/type_interface.php
@@ -33,6 +33,13 @@ interface type_interface
public function get_service_name();
/**
+ * Get the name of template file for this type
+ *
+ * @return string Returns the name of the template file
+ */
+ public function get_template_filename();
+
+ /**
* Get dropdown options for second step in ACP
*
* @param string $default_lang_id ID of the default language
@@ -174,4 +181,14 @@ interface type_interface
* @return null
*/
public function display_options(&$template_vars, &$field_data);
+
+ /**
+ * Return templated value/field. Possible values for $mode are:
+ * change == user is able to set/enter profile values; preview == just show the value
+ *
+ * @param string $mode Mode for displaying the field (preview|change)
+ * @param array $profile_row Array with data for this field
+ * @return null
+ */
+ public function process_field_row($mode, $profile_row);
}
diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php
index d322099c34..f00a7e6a08 100644
--- a/phpBB/phpbb/profilefields/type/type_string_common.php
+++ b/phpBB/phpbb/profilefields/type/type_string_common.php
@@ -52,16 +52,16 @@ abstract class type_string_common extends type_base
}
else if (trim($field_value) === '' && $field_data['field_required'])
{
- return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
+ return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
}
if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
{
- return $this->user->lang('FIELD_TOO_SHORT', (int) $row['field_minlen'], $row['lang_name']);
+ return $this->user->lang('FIELD_TOO_SHORT', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
}
else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
{
- return $this->user->lang('FIELD_TOO_LONG', (int) $row['field_maxlen'], $row['lang_name']);
+ return $this->user->lang('FIELD_TOO_LONG', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
}
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
@@ -72,13 +72,13 @@ abstract class type_string_common extends type_base
switch ($row['field_validation'])
{
case '[0-9]+':
- return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $row['lang_name']);
+ return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $this->get_field_name($field_data['lang_name']));
case '[\w]+':
- return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $row['lang_name']);
+ return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $this->get_field_name($field_data['lang_name']));
case '[\w_\+\. \-\[\]]+':
- return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $row['lang_name']);
+ return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $this->get_field_name($field_data['lang_name']));
}
}
}