diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index c19ff18985..e202bcd82d 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -834,10 +834,10 @@ INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_len INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_occupation', 'profilefields.type.text', 'phpbb_occupation', '3|30', '2', '500', '', '', '.*', 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, '', ''); INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_icq', 'profilefields.type.string', 'phpbb_icq', '20', '3', '15', '', '', '[0-9]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 6, 1, 'SEND_ICQ_MESSAGE', 'https://www.icq.com/people/%s/'); INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_yahoo', 'profilefields.type.string', 'phpbb_yahoo', '40', '5', '255', '', '', '.*', 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 8, 1, 'SEND_YIM_MESSAGE', 'ymsgr:sendim?%s'); -INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_facebook', 'profilefields.type.string', 'phpbb_facebook', '20', '5', '50', '', '', '[\w.]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 9, 1, 'VIEW_FACEBOOK_PROFILE', 'http://facebook.com/%s/'); -INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_twitter', 'profilefields.type.string', 'phpbb_twitter', '20', '1', '15', '', '', '[\w_]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 10, 1, 'VIEW_TWITTER_PROFILE', 'http://twitter.com/%s'); +INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_facebook', 'profilefields.type.string', 'phpbb_facebook', '20', '5', '50', '', '', '[\w.]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 9, 1, 'VIEW_FACEBOOK_PROFILE', 'https://facebook.com/%s/'); +INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_twitter', 'profilefields.type.string', 'phpbb_twitter', '20', '1', '15', '', '', '[\w_]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 10, 1, 'VIEW_TWITTER_PROFILE', 'https://twitter.com/%s'); INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_skype', 'profilefields.type.string', 'phpbb_skype', '20', '6', '32', '', '', '[a-zA-Z][\w\.,\-_]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 11, 1, 'VIEW_SKYPE_PROFILE', 'skype:%s?userinfo'); -INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_youtube', 'profilefields.type.string', 'phpbb_youtube', '40', '23', '255', '', '', 'https:\/\/(www\.)?youtube\.com\/.+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 12, 1, 'VIEW_YOUTUBE_CHANNEL', '%s'); +INSERT INTO phpbb_profile_fields (field_name, field_type, field_ident, field_length, field_minlen, field_maxlen, field_novalue, field_default_value, field_validation, field_required, field_show_novalue, field_show_on_reg, field_show_on_pm, field_show_on_vt, field_show_on_ml, field_show_profile, field_hide, field_no_view, field_active, field_order, field_is_contact, field_contact_desc, field_contact_url) VALUES ('phpbb_youtube', 'profilefields.type.string', 'phpbb_youtube', '40', '23', '255', '', '', '(@[a-zA-Z0-9_.-]{3,30}|c/[a-zA-Z][\w\.,\-_]+|channel/[a-zA-Z][\w\.,\-_]+)', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 12, 1, 'VIEW_YOUTUBE_CHANNEL', '%s'); # User Notification Options (for first user) INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('notification.type.post', 0, 2, 'notification.method.board'); diff --git a/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php b/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php index 232e3b486f..bcf097609a 100644 --- a/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php +++ b/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php @@ -15,7 +15,7 @@ namespace phpbb\db\migration\data\v33x; class profilefield_youtube_update extends \phpbb\db\migration\migration { - protected $youtube_url_matcher = 'https:\\/\\/(www\\.)?youtube\\.com\\/.+'; + public static $youtube_url_matcher = 'https:\\/\\/(www\\.)?youtube\\.com\\/.+'; public function effectively_installed() { @@ -30,7 +30,7 @@ class profilefield_youtube_update extends \phpbb\db\migration\migration $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - return !$row || $row['field_validation'] === $this->youtube_url_matcher; + return !$row || $row['field_validation'] === self::$youtube_url_matcher; } public static function depends_on() @@ -48,7 +48,7 @@ class profilefield_youtube_update extends \phpbb\db\migration\migration $profile_fields = $this->table_prefix . 'profile_fields'; $profile_fields_data = $this->table_prefix . 'profile_fields_data'; - $field_validation = $this->db->sql_escape($this->youtube_url_matcher); + $field_validation = $this->db->sql_escape(self::$youtube_url_matcher); $min_length = strlen('https://youtube.com/c/') + 1; diff --git a/phpBB/phpbb/db/migration/data/v33x/profilefields_update.php b/phpBB/phpbb/db/migration/data/v33x/profilefields_update.php new file mode 100644 index 0000000000..eb3e7acaa8 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v33x/profilefields_update.php @@ -0,0 +1,190 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v33x; + +class profilefields_update extends \phpbb\db\migration\migration +{ + /** @var string YouTube URLs matcher: handle or custom URL or channel URL */ + protected $youtube_url_matcher = '(@[a-zA-Z0-9_.-]{3,30}|c/[a-zA-Z][\w\.,\-_]+|channel/[a-zA-Z][\w\.,\-_]+)'; + + public static function depends_on(): array + { + return ['\phpbb\db\migration\data\v33x\v3310']; + } + + public function update_schema(): array + { + return [ + 'change_columns' => [ + $this->table_prefix . 'profile_fields' => [ + 'field_validation' => ['VCHAR_UNI:128', ''], + ], + ] + ]; + } + + public function revert_schema(): array + { + return [ + 'change_columns' => [ + $this->table_prefix . 'profile_fields' => [ + 'field_validation' => ['VCHAR_UNI:64', ''], + ], + ] + ]; + } + + public function update_data(): array + { + return [ + ['custom', [[$this, 'update_youtube_profile_field']]], + ['custom', [[$this, 'update_other_profile_fields']]], + ]; + } + + public function revert_data(): array + { + return [ + ['custom', [[$this, 'revert_youtube_profile_field']]], + ['custom', [[$this, 'revert_other_profile_fields']]], + ]; + } + + public function update_youtube_profile_field(): bool + { + $profile_fields = $this->table_prefix . 'profile_fields'; + $profile_fields_data = $this->table_prefix . 'profile_fields_data'; + $end_time = time() + 5; // allow up to 5 seconds for migration to run + + $field_validation = $this->db->sql_escape($this->youtube_url_matcher); + + $this->db->sql_query( + "UPDATE $profile_fields + SET field_length = '20', + field_minlen = '3', + field_maxlen = '60', + field_validation = '$field_validation', + field_contact_url = '%s' + WHERE field_name = 'phpbb_youtube'" + ); + + $yt_profile_field = 'pf_phpbb_youtube'; + $has_youtube_url = $this->db->sql_like_expression($this->db->get_any_char() . 'youtube.com/' . $this->db->get_any_char()); + + $update_aborted = false; + + $sql = 'SELECT user_id, pf_phpbb_youtube + FROM ' . $profile_fields_data . " + WHERE $yt_profile_field <> '' + AND $yt_profile_field $has_youtube_url"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $updated_youtube_url_part = $this->get_youtube_url_part($row['pf_phpbb_youtube']); + if ($updated_youtube_url_part != $row['pf_phpbb_youtube']) + { + $this->db->sql_query( + "UPDATE $profile_fields_data + SET $yt_profile_field = '$updated_youtube_url_part' + WHERE user_id = {$row['user_id']}" + ); + } + + if (time() > $end_time) + { + $update_aborted = true; + break; + } + } + $this->db->sql_freeresult($result); + + return $update_aborted != true; + } + + public function update_other_profile_fields(): void + { + $profile_fields = $this->table_prefix . 'profile_fields'; + + $this->db->sql_query( + "UPDATE $profile_fields + SET field_contact_url = 'https://facebook.com/%s/' + WHERE field_name = 'phpbb_facebook'" + ); + + $this->db->sql_query( + "UPDATE $profile_fields + SET field_contact_url = 'https://twitter.com/%s' + WHERE field_name = 'phpbb_twitter'" + ); + } + + public function revert_youtube_profile_field(): void + { + $profile_fields = $this->table_prefix . 'profile_fields'; + $profile_fields_data = $this->table_prefix . 'profile_fields_data'; + + $old_field_validation = $this->db->sql_escape(profilefield_youtube_update::$youtube_url_matcher); + + $min_length = strlen('https://youtube.com/c/') + 1; + + $this->db->sql_query( + "UPDATE $profile_fields SET + field_length = '40', + field_minlen = '$min_length', + field_maxlen = '255', + field_validation = '$old_field_validation', + field_contact_url = '%s' + WHERE field_name = 'phpbb_youtube'" + ); + + $yt_profile_field = 'pf_phpbb_youtube'; + $prepend_legacy_youtube_url = $this->db->sql_concatenate( + "'https://youtube.com/'", $yt_profile_field + ); + $is_not_already_youtube_url = $this->db->sql_not_like_expression( + $this->db->get_any_char() + . 'youtube.com/' + . $this->db->get_any_char() + ); + + $this->db->sql_query( + "UPDATE $profile_fields_data SET + $yt_profile_field = $prepend_legacy_youtube_url + WHERE $yt_profile_field <> '' + AND $yt_profile_field $is_not_already_youtube_url" + ); + } + + public function revert_other_profile_fields(): void + { + $profile_fields = $this->table_prefix . 'profile_fields'; + + $this->db->sql_query( + "UPDATE $profile_fields + SET field_contact_url = 'http://facebook.com/%s/' + WHERE field_name = 'phpbb_facebook'" + ); + + $this->db->sql_query( + "UPDATE $profile_fields + SET field_contact_url = 'http://twitter.com/%s' + WHERE field_name = 'phpbb_twitter'" + ); + } + + protected function get_youtube_url_part(string $profile_field_string): string + { + return preg_replace('#^https://(?:www\.)?youtube\.com/(.+)$#iu', '$1', $profile_field_string); + } +}