set_role_data   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A depends_on() 0 6 1
A update_data() 0 11 2
A role_exists() 0 10 1
1
<?php
2
/**
3
 *
4
 * 2FA extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015 Paul Sohier
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace paul999\tfa\migrations;
12
13
use phpbb\db\migration\migration;
14
15
class set_role_data extends migration
16
{
17
	static public function depends_on()
18
	{
19
		return array(
20
			'\paul999\tfa\migrations\initial_permissions',
21
		);
22
	}
23
24
	public function update_data()
25
	{
26
		$data = array();
27
28
		if ($this->role_exists('ROLE_ADMIN_FULL'))
29
		{
30
			$data[] = array('permission.permission_set', array('ROLE_ADMIN_FULL', 'a_tfa'));
31
		}
32
33
		return $data;
34
	}
35
36
	/**
37
	 * Checks whether the given role does exist or not.
38
	 *
39
	 * @param String $role the name of the role
40
	 * @return true if the role exists, false otherwise.
41
	 */
42
	protected function role_exists($role)
43
	{
44
		$sql = 'SELECT role_id
45
			FROM ' . ACL_ROLES_TABLE . "
46
			WHERE role_name = '" . $this->db->sql_escape($role) . "'";
47
		$result = $this->db->sql_query_limit($sql, 1);
48
		$role_id = $this->db->sql_fetchfield('role_id');
49
		$this->db->sql_freeresult($result);
50
		return $role_id;
51
	}
52
}
53