m12_u_phpbb_ads_permission::depends_on()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
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
0 ignored issues
show
Bug introduced by
The type phpbb\db\migration\container_aware_migration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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(array($this, 'set_u_phpbb_ads_permission'))),
37
			array('custom', array(array($this, 'update_ucp_module_permission'))),
38
		);
39
	}
40
41
	/**
42
	 * Find existing ad owners and assign them the new u_phpbb_ads permission
43
	 */
44
	public function set_u_phpbb_ads_permission()
45
	{
46
		if (!class_exists('auth_admin'))
47
		{
48
			include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext);
49
		}
50
		$auth_admin = new \auth_admin();
0 ignored issues
show
Bug introduced by
The type auth_admin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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