mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge pull request #6561 from marc1706/ticket/17209
[ticket/17209] Improve mentions migration and add fallback for permission role_exists
This commit is contained in:
commit
6710bba04a
4 changed files with 104 additions and 44 deletions
|
@ -1,43 +0,0 @@
|
|||
<?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\v330;
|
||||
|
||||
class add_mention_settings extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.add', array('allow_mentions', true)),
|
||||
array('config.add', array('mention_batch_size', 50)),
|
||||
array('config.add', array('mention_names_limit', 10)),
|
||||
|
||||
// Set up user permissions
|
||||
array('permission.add', array('u_mention', true)),
|
||||
array('permission.permission_set', array('ROLE_USER_FULL', 'u_mention')),
|
||||
array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_mention')),
|
||||
array('permission.permission_set', array('ROLE_USER_LIMITED', 'u_mention')),
|
||||
array('permission.permission_set', array('ROLE_USER_NOPM', 'u_mention')),
|
||||
array('permission.permission_set', array('ROLE_USER_NOAVATAR', 'u_mention')),
|
||||
|
||||
// Set up forum permissions
|
||||
array('permission.add', array('f_mention', false)),
|
||||
array('permission.permission_set', array('ROLE_FORUM_FULL', 'f_mention')),
|
||||
array('permission.permission_set', array('ROLE_FORUM_STANDARD', 'f_mention')),
|
||||
array('permission.permission_set', array('ROLE_FORUM_LIMITED', 'f_mention')),
|
||||
array('permission.permission_set', array('ROLE_FORUM_ONQUEUE', 'f_mention')),
|
||||
array('permission.permission_set', array('ROLE_FORUM_POLLS', 'f_mention')),
|
||||
array('permission.permission_set', array('ROLE_FORUM_LIMITED_POLLS', 'f_mention')),
|
||||
);
|
||||
}
|
||||
}
|
88
phpBB/phpbb/db/migration/data/v400/add_mention_settings.php
Normal file
88
phpBB/phpbb/db/migration/data/v400/add_mention_settings.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?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\v400;
|
||||
|
||||
class add_mention_settings extends \phpbb\db\migration\migration
|
||||
{
|
||||
public static function depends_on()
|
||||
{
|
||||
return ['\phpbb\db\migration\data\v400\dev'];
|
||||
}
|
||||
|
||||
public function effectively_installed(): bool
|
||||
{
|
||||
return $this->config->offsetExists('allow_mentions')
|
||||
&& $this->config->offsetExists('mention_batch_size')
|
||||
&& $this->config->offsetExists('mention_names_limit');
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['config.add', ['allow_mentions', true]],
|
||||
['config.add', ['mention_batch_size', 50]],
|
||||
['config.add', ['mention_names_limit', 10]],
|
||||
|
||||
// Set up user permissions
|
||||
['permission.add', ['u_mention', true]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_USER_FULL']],
|
||||
['permission.permission_set', ['ROLE_USER_FULL', 'u_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_USER_STANDARD']],
|
||||
['permission.permission_set', ['ROLE_USER_STANDARD', 'u_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_USER_LIMITED']],
|
||||
['permission.permission_set', ['ROLE_USER_LIMITED', 'u_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_USER_NOPM']],
|
||||
['permission.permission_set', ['ROLE_USER_NOPM', 'u_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_USER_NOAVATAR']],
|
||||
['permission.permission_set', ['ROLE_USER_NOAVATAR', 'u_mention']],
|
||||
]],
|
||||
|
||||
// Set up forum permissions
|
||||
['permission.add', ['f_mention', false]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_FORUM_FULL']],
|
||||
['permission.permission_set', ['ROLE_FORUM_FULL', 'f_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_FORUM_STANDARD']],
|
||||
['permission.permission_set', ['ROLE_FORUM_STANDARD', 'f_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_FORUM_LIMITED']],
|
||||
['permission.permission_set', ['ROLE_FORUM_LIMITED', 'f_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_FORUM_ONQUEUE']],
|
||||
['permission.permission_set', ['ROLE_FORUM_ONQUEUE', 'f_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_FORUM_POLLS']],
|
||||
['permission.permission_set', ['ROLE_FORUM_POLLS', 'f_mention']],
|
||||
]],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_FORUM_LIMITED_POLLS']],
|
||||
['permission.permission_set', ['ROLE_FORUM_LIMITED_POLLS', 'f_mention']],
|
||||
]],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -43,7 +43,10 @@ class add_storage_permission extends migration
|
|||
['permission.add', ['a_storage']],
|
||||
|
||||
// Set permissions
|
||||
['permission.permission_set', ['ROLE_ADMIN_FULL', 'a_storage']],
|
||||
['if', [
|
||||
['permission.role_exists', ['ROLE_ADMIN_FULL']],
|
||||
['permission.permission_set', ['ROLE_ADMIN_FULL', 'a_storage']],
|
||||
]],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,6 +256,18 @@ class permission implements \phpbb\db\migration\tool\tool_interface
|
|||
$role_id = (int) $this->db->sql_fetchfield('role_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Try falling back to searching by role description for standard role titles
|
||||
if (!$role_id && preg_match('/ROLE_(?<title>([A-Z]+_?)+)/', $role_name, $matches))
|
||||
{
|
||||
$role_description = 'ROLE_DESCRIPTION_' . $matches['title'];
|
||||
$sql = 'SELECT role_id
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_description = '" . $this->db->sql_escape($role_description) . "'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$role_id = (int) $this->db->sql_fetchfield('role_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
return $role_id;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue