mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge pull request #6481 from marc1706/ticket/17129
[ticket/17129] Update youtube profile field to support latest URLs
This commit is contained in:
commit
dd790b41eb
5 changed files with 208 additions and 9 deletions
|
@ -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', '20', '3', '60', '', '', '[a-zA-Z][\w\.,\-_]+', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 12, 1, 'VIEW_YOUTUBE_CHANNEL', 'http://youtube.com/user/%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', '20', '3', '60', '', '', '(@[a-zA-Z0-9_.-]{3,30}|c/[a-zA-Z][\w\.,\-_]+|(channel|user)/[a-zA-Z][\w\.,\-_]+)', 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 12, 1, 'VIEW_YOUTUBE_PROFILE', 'https://youtube.com/%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');
|
||||
|
|
|
@ -149,5 +149,5 @@ $lang = array_merge($lang, array(
|
|||
'VIEW_FACEBOOK_PROFILE' => 'View Facebook Profile',
|
||||
'VIEW_SKYPE_PROFILE' => 'View Skype Profile',
|
||||
'VIEW_TWITTER_PROFILE' => 'View Twitter Profile',
|
||||
'VIEW_YOUTUBE_CHANNEL' => 'View YouTube Channel',
|
||||
'VIEW_YOUTUBE_PROFILE' => 'View YouTube Profile',
|
||||
));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
194
phpBB/phpbb/db/migration/data/v33x/profilefields_update.php
Normal file
194
phpBB/phpbb/db/migration/data/v33x/profilefields_update.php
Normal file
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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|user)/[a-zA-Z][\w\.,\-_]+)';
|
||||
|
||||
public static function depends_on(): array
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v33x\v3310',
|
||||
'\phpbb\db\migration\data\v33x\profilefield_youtube_update',
|
||||
];
|
||||
}
|
||||
|
||||
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 = 'https://youtube.com/%s'
|
||||
field_contact_desc = 'VIEW_YOUTUBE_PROFILE'
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case
|
|||
public function test_submitting_profile_info()
|
||||
{
|
||||
$this->add_lang('ucp');
|
||||
$this->add_lang('memberlist');
|
||||
$this->login();
|
||||
|
||||
$crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=profile_info');
|
||||
|
@ -29,7 +30,7 @@ class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case
|
|||
'pf_phpbb_location' => 'Bertie´s Empire',
|
||||
'pf_phpbb_skype' => 'phpbb.skype.account',
|
||||
'pf_phpbb_twitter' => 'phpbb_twitter',
|
||||
'pf_phpbb_youtube' => 'phpbb.youtube',
|
||||
'pf_phpbb_youtube' => 'user/phpbb.youtube',
|
||||
));
|
||||
|
||||
$crawler = self::submit($form);
|
||||
|
@ -42,7 +43,11 @@ class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case
|
|||
$this->assertEquals('Bertie´s Empire', $form->get('pf_phpbb_location')->getValue());
|
||||
$this->assertEquals('phpbb.skype.account', $form->get('pf_phpbb_skype')->getValue());
|
||||
$this->assertEquals('phpbb_twitter', $form->get('pf_phpbb_twitter')->getValue());
|
||||
$this->assertEquals('phpbb.youtube', $form->get('pf_phpbb_youtube')->getValue());
|
||||
$this->assertEquals('user/phpbb.youtube', $form->get('pf_phpbb_youtube')->getValue());
|
||||
|
||||
$crawler = self::request('GET', 'memberlist.php?mode=viewprofile&un=admin');
|
||||
$link = $crawler->selectLink($this->lang('VIEW_YOUTUBE_PROFILE'));
|
||||
$this->assertSame('https://youtube.com/user/phpbb.youtube', $link->attr('href'));
|
||||
}
|
||||
|
||||
public function test_submitting_emoji()
|
||||
|
|
Loading…
Add table
Reference in a new issue