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
|
|
|
if (!class_exists('auth_admin')) |
46
|
|
|
{ |
47
|
|
|
include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); |
48
|
|
|
} |
49
|
|
|
$auth_admin = new \auth_admin(); |
50
|
|
|
|
51
|
|
|
$sql = 'SELECT ad_owner |
52
|
|
|
FROM ' . $this->table_prefix . 'ads |
53
|
|
|
WHERE ad_owner != 0 |
54
|
|
|
GROUP BY ad_owner'; |
55
|
|
|
$result = $this->db->sql_query($sql); |
56
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
57
|
|
|
{ |
58
|
|
|
$auth_admin->acl_set('user', 0, $row['ad_owner'], array('u_phpbb_ads' => 1)); |
59
|
|
|
} |
60
|
|
|
$this->db->sql_freeresult($result); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Update module auth manually, because "module.remove" tool causes problems when deleting extension. |
65
|
|
|
*/ |
66
|
|
|
public function update_ucp_module_permission() |
67
|
|
|
{ |
68
|
|
|
$sql = 'UPDATE ' . $this->container->getParameter('tables.modules') . ' |
69
|
|
|
SET module_auth = "ext_phpbb/ads && acl_u_phpbb_ads" |
70
|
|
|
WHERE module_langname = "UCP_PHPBB_ADS_STATS"'; |
71
|
|
|
$this->db->sql_query($sql); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|