set_role_data   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B update_data() 0 30 5
A role_exists() 0 10 1
1
<?php
2
/**
3
 *
4
 * Ajax Shoutbox extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2014 Paul Sohier <http://www.ajax-shoutbox.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
namespace paul999\ajaxshoutbox\migrations;
11
12
use phpbb\db\migration\migration;
13
14
class set_role_data extends migration
15
{
16
	public function update_data()
17
	{
18
		$data = array();
19
20
		if ($this->role_exists('ROLE_MOD_FULL'))
21
		{
22
			$data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_shoutbox_delete'));
23
		}
24
		if ($this->role_exists('ROLE_MOD_STANDARD'))
25
		{
26
			$data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_shoutbox_delete'));
27
		}
28
29
		if ($this->role_exists('ROLE_FORUM_FULL'))
30
		{
31
			$data[] = array('permission.permission_set', array('ROLE_FORUM_FULL', 'u_shoutbox_view'));
32
			$data[] = array('permission.permission_set', array('ROLE_FORUM_FULL', 'u_shoutbox_post'));
33
			$data[] = array('permission.permission_set', array('ROLE_FORUM_FULL', 'u_shoutbox_bbcode'));
34
			$data[] = array('permission.permission_set', array('ROLE_FORUM_FULL', 'u_shoutbox_delete'));
35
		}
36
37
		if ($this->role_exists('ROLE_FORUM_STANDARD'))
38
		{
39
			$data[] = array('permission.permission_set', array('ROLE_FORUM_STANDARD', 'u_shoutbox_view'));
40
			$data[] = array('permission.permission_set', array('ROLE_FORUM_STANDARD', 'u_shoutbox_post'));
41
			$data[] = array('permission.permission_set', array('ROLE_FORUM_STANDARD', 'u_shoutbox_bbcode'));
42
		}
43
44
		return $data;
45
	}
46
47
	/**
48
	 * Checks whether the given role does exist or not.
49
	 *
50
	 * @param String $role the name of the role
51
	 * @return true if the role exists, false otherwise.
52
	 */
53
	protected function role_exists($role)
54
	{
55
		$sql = 'SELECT role_id
56
		FROM ' . ACL_ROLES_TABLE . "
57
		WHERE role_name = '" . $this->db->sql_escape($role) . "'";
58
		$result = $this->db->sql_query_limit($sql, 1);
59
		$role_id = $this->db->sql_fetchfield('role_id');
60
		$this->db->sql_freeresult($result);
61
		return $role_id;
62
	}
63
}
64