From 564924e876d26d973487a00befb26601b4d9948a Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 11:48:06 +0300 Subject: [PATCH 01/10] [ticket/12786] Extend profilefield_base_migration.php class If extensions authors will use profilefield_base_migration.php class as base class for creation of CPFs, the class need to be extended a bit. At the moment there are two issues with it: It does not create entries for PROFILE_FIELDS_LANG_TABLE (as it can't know what fields to create). The migration is not "cleaning" the DBMS after purging the extension and leaves everything except the CPF column. Adding profilefield_language_data PHPBB3-12786 --- .../db/migration/profilefield_base_migration.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index d416a9b228..1a88ef0d48 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -21,6 +21,22 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration protected $profilefield_data; + /*Language data should be in array -> each language_data in seaprte key + * array( + * '1' => array( + * 'option_id' => value, + * 'field_type' => value, + * 'lang_value' => value, + * ), + * '2' => array( + * 'option_id' => value, + * 'field_type' => value, + * 'lang_value' => value, + * ), + * ) + */ + protected $profilefield_language_data; + protected $user_column_name; public function effectively_installed() From b70a1cc4af7831909b87bc3628ab2a06e8b16b83 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 11:50:40 +0300 Subject: [PATCH 02/10] [ticket/12786] Add get_custom_field_id Adding function to get CPFs ID PHPBB3-12786 --- .../db/migration/profilefield_base_migration.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index 1a88ef0d48..31244bf957 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -111,6 +111,19 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration $insert_buffer->flush(); } + /** + * 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'); + + return $field_id; + } + /** * @param int $start Start of staggering step * @return mixed int start of the next step, null if the end was reached From e3b07274ef514906920006104604b7d43284bf9c Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 11:51:47 +0300 Subject: [PATCH 03/10] [ticket/12786] Add create_language_entries Add function to create entries in PROFILE_FIELDS_LANG_TABLE PHPBB3-12786 --- .../migration/profilefield_base_migration.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index 31244bf957..f96495d2df 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -111,6 +111,36 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration $insert_buffer->flush(); } + /** + * 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( + 'field_id' => $field_id, + 'lang_id' => $lang_id, + 'option_id' => $language_data['option_id'], + 'field_type' => $language_data['field_type'], + 'lang_value' => $language_data['lang_value'], + )); + } + } + $this->db->sql_freeresult($result); + + $insert_buffer->flush(); + } + /** * Get custom profile field id * @return int custom profile filed id From 52204e0e6dc3119be54df28f12cf39b7116830e0 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 12:21:40 +0300 Subject: [PATCH 04/10] [ticket/12786] White spaces found Removed some white spaces PHPBB3-12786 --- phpBB/phpbb/db/migration/profilefield_base_migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index f96495d2df..b2c0161286 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -117,9 +117,9 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration 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); From 18631801d53a3631a928a32d79695d3486d40ca0 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 16:28:57 +0300 Subject: [PATCH 05/10] [ticket/12786] Add clean_cpf_db_entries Add function to clean the cpf fields entries PHPBB3-12786 --- .../migration/profilefield_base_migration.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index b2c0161286..e360de1d8e 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -141,6 +141,29 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration $insert_buffer->flush(); } + /** + * Clean db after purging of extension + * function should be called from migration + * using revert_data() + */ + public function clean_cpf_db_entries() + { + $field_id = $this->get_custom_profile_field_id(); + + //Let's clean the field + //1. PROFILE_FIELDS_TABLE + $sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . ' WHERE field_id = ' . $field_id; + $this->db->sql_query($sql); + + //2. PPROFILE_LANG_TABLE + $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE field_id = ' . $field_id; + $this->db->sql_query($sql); + + //3. PROFILE_FIELDS_LANG_TABLE + $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 From ffbd7cf1a755e354ddb629e583ee6b534a66bdd4 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 22:32:42 +0300 Subject: [PATCH 06/10] [ticket/12786] Some minor fixes of comments and function naming PHPBB3-12786 --- .../migration/profilefield_base_migration.php | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) mode change 100644 => 100755 phpBB/phpbb/db/migration/profilefield_base_migration.php diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php old mode 100644 new mode 100755 index e360de1d8e..3b9ad3e249 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -21,14 +21,15 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration protected $profilefield_data; - /*Language data should be in array -> each language_data in seaprte key + /** + *Language data should be in array -> each language_data in seaprte key * array( - * '1' => array( + * array( * 'option_id' => value, * 'field_type' => value, * 'lang_value' => value, * ), - * '2' => array( + * array( * 'option_id' => value, * 'field_type' => value, * 'lang_value' => value, @@ -74,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 @@ -143,24 +151,21 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration /** * Clean db after purging of extension - * function should be called from migration - * using revert_data() */ - public function clean_cpf_db_entries() + public function delete_custom_profile_field_data() { $field_id = $this->get_custom_profile_field_id(); - //Let's clean the field - //1. PROFILE_FIELDS_TABLE - $sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . ' WHERE field_id = ' . $field_id; + $sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . ' + WHERE field_id = ' . $field_id; $this->db->sql_query($sql); - //2. PPROFILE_LANG_TABLE - $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE field_id = ' . $field_id; + $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' + WHERE field_id = ' . $field_id; $this->db->sql_query($sql); - //3. PROFILE_FIELDS_LANG_TABLE - $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE field_id = ' . $field_id; + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE field_id = ' . $field_id; $this->db->sql_query($sql); } @@ -170,9 +175,12 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration */ public function get_custom_profile_field_id() { - $sql = 'SELECT field_id FROM ' . PROFILE_FIELDS_TABLE . ' WHERE field_name = \'' . $this->profilefield_name . '\''; + $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; } From 41047bc369e3919fe855c7a03d7d1bc7965092be Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 22:46:45 +0300 Subject: [PATCH 07/10] [ticket/12786] Dixing a typo Typos fixed PHPBB3-12786 --- phpBB/phpbb/db/migration/profilefield_base_migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 phpBB/phpbb/db/migration/profilefield_base_migration.php diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php old mode 100755 new mode 100644 index 3b9ad3e249..63cc1b827f --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -22,7 +22,7 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration protected $profilefield_data; /** - *Language data should be in array -> each language_data in seaprte key + * Language data should be in array -> each language_data in separate key * array( * array( * 'option_id' => value, From c9da9ec8587bc3e74e7a0f5a79a232865592f6ce Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Sun, 29 Jun 2014 23:51:40 +0300 Subject: [PATCH 08/10] [ticket/12786] Some changes of the comments. Comments and quotes PHPBB3-12786 [ticket/12786] PHPBB3-12786 Revert "[ticket/12786]" This reverts commit 61a6647101731110f67689b109de953f7449b03e. --- phpBB/phpbb/db/migration/profilefield_base_migration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index 63cc1b827f..9bc789779b 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -150,7 +150,7 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration } /** - * Clean db after purging of extension + * Clean database when reverting the migration */ public function delete_custom_profile_field_data() { @@ -175,8 +175,8 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration */ public function get_custom_profile_field_id() { - $sql = "SELECT field_id - FROM " . PROFILE_FIELDS_TABLE . " + $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'); From 4cec5bcd556e0edcf43bf25d628c552106e97b13 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Fri, 4 Jul 2014 14:17:29 +0300 Subject: [PATCH 09/10] [ticket/12786] Array_merge instead copy array parts nickvergessen proposed this PHPBB3-12786 --- phpBB/phpbb/db/migration/profilefield_base_migration.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index 9bc789779b..578ce52d1c 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -135,13 +135,10 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration { foreach ($this->profilefield_language_data as $language_data) { - $insert_buffer->insert(array( + $insert_buffer->insert(array_merge(array( 'field_id' => $field_id, 'lang_id' => $lang_id, - 'option_id' => $language_data['option_id'], - 'field_type' => $language_data['field_type'], - 'lang_value' => $language_data['lang_value'], - )); + ), $language_data)); } } $this->db->sql_freeresult($result); From c468a5d8d44459b7baa40f2b3470ff296d9bc31c Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Tue, 8 Jul 2014 22:01:49 +0300 Subject: [PATCH 10/10] [ticket/12786] Correcting some tabs Some tabs needed corection PHPBB3-12786 --- .../migration/profilefield_base_migration.php | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index 578ce52d1c..e66e5fd080 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -24,17 +24,17 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration /** * 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, - * ), - * ) + * array( + * 'option_id' => value, + * 'field_type' => value, + * 'lang_value' => value, + * ), + * array( + * 'option_id' => value, + * 'field_type' => value, + * 'lang_value' => value, + * ), + * ) */ protected $profilefield_language_data; @@ -138,7 +138,7 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration $insert_buffer->insert(array_merge(array( 'field_id' => $field_id, 'lang_id' => $lang_id, - ), $language_data)); + ), $language_data)); } } $this->db->sql_freeresult($result); @@ -153,16 +153,16 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration { $field_id = $this->get_custom_profile_field_id(); - $sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . ' - WHERE field_id = ' . $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; + $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; + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE field_id = ' . $field_id; $this->db->sql_query($sql); } @@ -172,9 +172,9 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration */ public function get_custom_profile_field_id() { - $sql = 'SELECT field_id - FROM ' . PROFILE_FIELDS_TABLE . " - WHERE field_name = '" . $this->profilefield_name . "'"; + $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);