1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package Quick Title Edition Extension |
5
|
|
|
* @copyright (c) 2015 ABDev |
6
|
|
|
* @copyright (c) 2015 PastisD |
7
|
|
|
* @copyright (c) 2015 Geolim4 <http://geolim4.com> |
8
|
|
|
* @copyright (c) 2015 Zoddo <[email protected]> |
9
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace ernadoo\qte\migrations\v200; |
14
|
|
|
|
15
|
|
|
use phpbb\db\migration\container_aware_migration; |
16
|
|
|
|
17
|
|
|
class convert_old_permissions extends container_aware_migration |
18
|
|
|
{ |
19
|
|
|
static public function depends_on() |
20
|
|
|
{ |
21
|
|
|
return array( |
22
|
|
|
'\ernadoo\qte\migrations\v200\alpha1', |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function update_data() |
27
|
|
|
{ |
28
|
|
|
return array( |
29
|
|
|
array('permission.add', array('m_qte_attr_del', false)), |
30
|
|
|
array('permission.add', array('m_qte_attr_edit', false)), |
31
|
|
|
|
32
|
|
|
array('custom', array(array(&$this, 'convert_permissions'))), |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function revert_data() |
37
|
|
|
{ |
38
|
|
|
return array( |
39
|
|
|
|
40
|
|
|
array('custom', array(array(&$this, 'remove_permissions'))), |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function convert_permissions() |
45
|
|
|
{ |
46
|
|
|
$attr_permissions_array = $groups_array = array(); |
47
|
|
|
|
48
|
|
|
$migrator_tool_permission = $this->container->get('migrator.tool.permission'); |
49
|
|
|
|
50
|
|
|
$sql = 'SELECT * FROM ' . $this->table_prefix . 'topics_attr'; |
51
|
|
|
$result = $this->db->sql_query($sql); |
52
|
|
|
|
53
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
54
|
|
|
{ |
55
|
|
|
$auth_option = 'f_qte_attr_'.$row['attr_id']; |
56
|
|
|
$migrator_tool_permission->add($auth_option, false); |
57
|
|
|
|
58
|
|
|
$attr_permissions_array[$auth_option] = json_decode($row['attr_auths'], true); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!class_exists('auth_admin')) |
62
|
|
|
{ |
63
|
|
|
include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); |
64
|
|
|
} |
65
|
|
|
$auth_admin = new \auth_admin(); |
66
|
|
|
|
67
|
|
|
foreach ($attr_permissions_array as $auth_option => $attr_permissions) |
68
|
|
|
{ |
69
|
|
|
foreach ($attr_permissions as $attr_permission) |
70
|
|
|
{ |
71
|
|
|
if (sizeof($attr_permission['forums_ids']) && sizeof($attr_permission['groups_ids'])) |
72
|
|
|
{ |
73
|
|
|
$auth_option_arry = array(); |
74
|
|
|
$auth_option_arry[$auth_option] = ACL_YES; |
75
|
|
|
$auth_admin->acl_set('group', $attr_permission['forums_ids'], $attr_permission['groups_ids'], $auth_option_arry); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . |
81
|
|
|
(!$this->config['coppa_enable'] ? " WHERE group_name <> 'REGISTERED_COPPA'" : ''); |
82
|
|
|
$result = $this->db->sql_query($sql); |
83
|
|
|
|
84
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
85
|
|
|
{ |
86
|
|
|
$groups_array[] = $row['group_id']; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$sql = 'SELECT forum_id, hide_attr FROM ' . FORUMS_TABLE . ' |
90
|
|
|
WHERE hide_attr <> ""'; |
91
|
|
|
$result = $this->db->sql_query($sql); |
92
|
|
|
|
93
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
94
|
|
|
{ |
95
|
|
|
$result_diff = array_diff($groups_array, unserialize($row['hide_attr'])); |
96
|
|
|
|
97
|
|
|
if (sizeof($result_diff)) |
98
|
|
|
{ |
99
|
|
|
$auth_option_arry = array(); |
100
|
|
|
$auth_option_arry['m_qte_attr_del'] = ACL_YES; |
101
|
|
|
$auth_admin->acl_set('group', $row['forum_id'], $result_diff, $auth_option_arry); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function remove_permissions() |
107
|
|
|
{ |
108
|
|
|
$migrator_tool_permission = $this->container->get('migrator.tool.permission'); |
109
|
|
|
|
110
|
|
|
$sql = 'SELECT auth_option FROM ' . ACL_OPTIONS_TABLE . ' |
111
|
|
|
WHERE auth_option ' . $this->db->sql_like_expression('f_qte_attr_' . $this->db->get_any_char()); |
112
|
|
|
$result = $this->db->sql_query($sql); |
113
|
|
|
|
114
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
115
|
|
|
{ |
116
|
|
|
$migrator_tool_permission->remove($row['auth_option'], false); |
117
|
|
|
} |
118
|
|
|
$this->db->sql_freeresult($result); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|