diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-07-09 17:00:43 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-07-09 17:00:43 +0200 |
commit | d5fd1ecfc8c2898d57135cccb06b62e9c28f1ce2 (patch) | |
tree | ab171b2f96432519df14ac3b505e5a47edd0e4f6 | |
parent | b13293947140408b634a71085efd7e255f507377 (diff) | |
parent | c468a5d8d44459b7baa40f2b3470ff296d9bc31c (diff) | |
download | forums-d5fd1ecfc8c2898d57135cccb06b62e9c28f1ce2.tar forums-d5fd1ecfc8c2898d57135cccb06b62e9c28f1ce2.tar.gz forums-d5fd1ecfc8c2898d57135cccb06b62e9c28f1ce2.tar.bz2 forums-d5fd1ecfc8c2898d57135cccb06b62e9c28f1ce2.tar.xz forums-d5fd1ecfc8c2898d57135cccb06b62e9c28f1ce2.zip |
Merge pull request #2675 from lucifer4o/ticket/12786
[ticket/12786] Extend profilefield_base_migration.php class
* lucifer4o/ticket/12786:
[ticket/12786] Correcting some tabs
[ticket/12786] Array_merge instead copy array parts
[ticket/12786] Some changes of the comments.
[ticket/12786] Dixing a typo
[ticket/12786] Some minor fixes of comments and function naming
[ticket/12786] Add clean_cpf_db_entries
[ticket/12786] White spaces found
[ticket/12786] Add create_language_entries
[ticket/12786] Add get_custom_field_id
[ticket/12786] Extend profilefield_base_migration.php class
-rw-r--r-- | phpBB/phpbb/db/migration/profilefield_base_migration.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index d416a9b228..e66e5fd080 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -21,6 +21,23 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration protected $profilefield_data; + /** + * Language data should be in array -> each language_data in separate key + * array( + * array( + * 'option_id' => value, + * 'field_type' => value, + * 'lang_value' => value, + * ), + * array( + * 'option_id' => value, + * 'field_type' => value, + * 'lang_value' => value, + * ), + * ) + */ + protected $profilefield_language_data; + protected $user_column_name; public function effectively_installed() @@ -58,6 +75,13 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration ); } + public function revert_data() + { + return array( + array('custom', array(array($this, 'delete_custom_profile_field_data'))), + ); + } + public function create_custom_field() { $sql = 'SELECT MAX(field_order) as max_field_order @@ -96,6 +120,69 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration } /** + * Create Custom profile fields languguage entries + */ + public function create_language_entries() + { + $field_id = $this->get_custom_profile_field_id(); + + $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_FIELDS_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')) + { + foreach ($this->profilefield_language_data as $language_data) + { + $insert_buffer->insert(array_merge(array( + 'field_id' => $field_id, + 'lang_id' => $lang_id, + ), $language_data)); + } + } + $this->db->sql_freeresult($result); + + $insert_buffer->flush(); + } + + /** + * Clean database when reverting the migration + */ + public function delete_custom_profile_field_data() + { + $field_id = $this->get_custom_profile_field_id(); + + $sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . ' + WHERE field_id = ' . $field_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' + WHERE field_id = ' . $field_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE field_id = ' . $field_id; + $this->db->sql_query($sql); + } + + /** + * Get custom profile field id + * @return int custom profile filed id + */ + public function get_custom_profile_field_id() + { + $sql = 'SELECT field_id + FROM ' . PROFILE_FIELDS_TABLE . " + WHERE field_name = '" . $this->profilefield_name . "'"; + $result = $this->db->sql_query($sql); + $field_id = (int) $this->db->sql_fetchfield('field_id'); + $this->db->sql_freeresult($result); + + return $field_id; + } + + /** * @param int $start Start of staggering step * @return mixed int start of the next step, null if the end was reached */ |