From dd6e11021022348f02242d1fa9aa43c60155daf1 Mon Sep 17 00:00:00 2001 From: lionel-rowe Date: Fri, 29 Apr 2022 17:08:23 +0100 Subject: [PATCH 1/2] [ticket/13859] Allow up-to-date format for Youtube profile field URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per the tracker issue: > In 3.1 a youtube profilefield was added in which we can insert our youtube > username to link to it.... There is just one major problem though... > > New youtube members no longer get an username. So I think we should decide on > providing different ways to access their profile. This PR will allow users to use any valid YouTube-domain URL, which allows for all 3 formats (`/channel/...`, `/c/...`, and the now-legacy `/user/...`). Per [YouTube's docs](https://support.google.com/youtube/answer/6180214?hl=en): > ## Channel URL (ID-based) > Example: youtube.com/channel/UCUZHFZ9jIKrLroW8LcyJEQQ > > This is the standard URL that YouTube channels use. > > ... > > ## Custom URL > Example: youtube.com/c/YouTubeCreators > > A custom URL is a shorter, easy-to-remember URL that you can share with your > audience. > > ... > > ## Legacy username URL > Example: youtube.com/user/YouTube > > Depending on when your channel was created, it may have a username. Usernames > are no longer required for channels today, but you can still use this URL to > direct to your channel — even if your channel name has changed since you chose > your username. Existing usernames can't be changed. PHPBB3-13859 --- .../data/v33x/profilefield_youtube_update.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php diff --git a/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php b/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php new file mode 100644 index 0000000000..cfa31df891 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php @@ -0,0 +1,82 @@ + +* @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 profilefield_youtube_update extends \phpbb\db\migration\migration +{ + protected $youtube_url_matcher = 'https:\\/\\/(www\\.)?youtube\\.com\\/.+'; + + public function effectively_installed() + { + $profile_fields = $this->table_prefix . 'profile_fields'; + + $result = $this->db->sql_query( + "SELECT field_validation + FROM $profile_fields + WHERE field_name = 'phpbb_youtube'" + ); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + return $row['field_validation'] === $this->youtube_url_matcher; + } + + static public function depends_on() + { + return ['\phpbb\db\migration\data\v33x\v337']; + } + + public function update_data() + { + return [['custom', [[$this, 'update_youtube_profile_field']]]]; + } + + public function update_youtube_profile_field() + { + $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); + + $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 = '$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/user/'", $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" + ); + } +} From 60af39b38cbfb9560b38a9fbd64edac4c702a9d7 Mon Sep 17 00:00:00 2001 From: lionel-rowe Date: Sun, 1 May 2022 21:09:21 +0100 Subject: [PATCH 2/2] [ticket/13859] Reorder static & public in migration PHPBB3-13859 --- .../db/migration/data/v33x/profilefield_youtube_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cfa31df891..8436f1bd89 100644 --- a/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php +++ b/phpBB/phpbb/db/migration/data/v33x/profilefield_youtube_update.php @@ -33,7 +33,7 @@ class profilefield_youtube_update extends \phpbb\db\migration\migration return $row['field_validation'] === $this->youtube_url_matcher; } - static public function depends_on() + public static function depends_on() { return ['\phpbb\db\migration\data\v33x\v337']; }