1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Advertisement management. An extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2017 phpBB Limited <https://www.phpbb.com> |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace phpbb\ads\migrations\v10x; |
12
|
|
|
|
13
|
|
|
class m12_u_phpbb_ads_permission extends \phpbb\db\migration\container_aware_migration |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritDoc} |
17
|
|
|
*/ |
18
|
|
|
public static function depends_on() |
19
|
|
|
{ |
20
|
|
|
return array( |
21
|
|
|
'\phpbb\ads\migrations\v10x\m1_initial_schema', |
22
|
|
|
'\phpbb\ads\migrations\v10x\m10_ad_owner_schema', |
23
|
|
|
'\phpbb\ads\migrations\v10x\m11_ad_owner_data', |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Add new permission |
29
|
|
|
* |
30
|
|
|
* @return array Array of data update instructions |
31
|
|
|
*/ |
32
|
|
|
public function update_data() |
33
|
|
|
{ |
34
|
|
|
return array( |
35
|
|
|
array('permission.add', array('u_phpbb_ads')), |
36
|
|
|
array('custom', array( |
37
|
|
|
array($this, 'set_u_phpbb_ads_permission'), |
38
|
|
|
array($this, 'update_ucp_module_permission'), |
39
|
|
|
)), |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function set_u_phpbb_ads_permission() |
44
|
|
|
{ |
45
|
|
|
// get u_phpbb_ads ID |
46
|
|
|
$sql = 'SELECT auth_option_id |
47
|
|
|
FROM ' . $this->container->getParameter('tables.acl_options') . ' |
48
|
|
|
WHERE auth_option = "u_phpbb_ads"'; |
49
|
|
|
$this->db->sql_query($sql); |
50
|
|
|
$auth_option_id = $this->db->sql_fetchfield('auth_option_id'); |
51
|
|
|
|
52
|
|
|
// set u_phpbb_ads to true for ad owners |
53
|
|
|
$sql_ary = array(); |
54
|
|
|
$sql = 'SELECT ad_owner |
55
|
|
|
FROM ' . $this->table_prefix . 'ads |
56
|
|
|
WHERE ad_owner != 0 |
57
|
|
|
GROUP BY ad_owner'; |
58
|
|
|
$result = $this->db->sql_query($sql); |
59
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
60
|
|
|
{ |
61
|
|
|
$sql_ary[] = array( |
62
|
|
|
'user_id' => (int) $row['ad_owner'], |
63
|
|
|
'forum_id' => 0, |
64
|
|
|
'auth_option_id' => (int) $auth_option_id, |
65
|
|
|
'auth_setting' => 1, |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
$this->db->sql_freeresult($result); |
69
|
|
|
|
70
|
|
|
$this->db->sql_multi_insert($this->container->getParameter('tables.acl_users'), $sql_ary); |
71
|
|
|
$this->container->get('auth')->acl_clear_prefetch(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Update module auth manually, because "module.remove" tool causes problems when deleting extension. |
76
|
|
|
*/ |
77
|
|
|
public function update_ucp_module_permission() |
78
|
|
|
{ |
79
|
|
|
$sql = 'UPDATE ' . $this->container->getParameter('tables.modules') . ' |
80
|
|
|
SET module_auth = "ext_phpbb/ads && acl_u_phpbb_ads" |
81
|
|
|
WHERE module_langname = "UCP_PHPBB_ADS_STATS"'; |
82
|
|
|
$this->db->sql_query($sql); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|