|
| 1 | +<?php |
| 2 | + /** |
| 3 | + * |
| 4 | + * Pastebin extension for the phpBB Forum Software package. |
| 5 | + * |
| 6 | + * @copyright (c) 2020 Crizzo <https://www.phpBB.de> |
| 7 | + * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | + namespace phpbbde\pastebin\migrations; |
| 12 | + |
| 13 | + class v204 extends \phpbb\db\migration\migration |
| 14 | + { |
| 15 | + static public function depends_on() |
| 16 | + { |
| 17 | + return array( |
| 18 | + '\phpbbde\pastebin\migrations\v_0_0_1', |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + public function update_data() |
| 23 | + { |
| 24 | + $data = array( |
| 25 | + array('config.update', array('pastebin_version', '2.0.4')), |
| 26 | + ); |
| 27 | + |
| 28 | + // Check if user role exists and assign permission to user standard role |
| 29 | + if ($this->role_exists('ROLE_USER_STANDARD')) |
| 30 | + { |
| 31 | + $data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_post', 'role', true)); |
| 32 | + $data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_edit', 'role', true)); |
| 33 | + $data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_delete', 'role', true)); |
| 34 | + $data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_post_novc', 'role', true)); |
| 35 | + $data[] = array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_pastebin_view', 'role', true)); |
| 36 | + } |
| 37 | + // Check if moderator role exists and assign permission to moderator standard role |
| 38 | + if ($this->role_exists('ROLE_MOD_STANDARD')) |
| 39 | + { |
| 40 | + $data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_delete', 'role', true)); |
| 41 | + $data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_edit', 'role', true)); |
| 42 | + $data[] = array('permission.permission_set', array('ROLE_MOD_STANDARD', 'm_pastebin_post_notlim', 'role', true)); |
| 43 | + } |
| 44 | + // Check if moderator role exists and assign permission to moderator full role |
| 45 | + if ($this->role_exists('ROLE_MOD_FULL')) |
| 46 | + { |
| 47 | + $data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_delete', 'role', true)); |
| 48 | + $data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_edit', 'role', true)); |
| 49 | + $data[] = array('permission.permission_set', array('ROLE_MOD_FULL', 'm_pastebin_post_notlim', 'role', true)); |
| 50 | + } |
| 51 | + |
| 52 | + return $data; |
| 53 | + } |
| 54 | + /** |
| 55 | + * Checks whether the given role does exist or not. |
| 56 | + * |
| 57 | + * @param String $role the name of the role |
| 58 | + * @return true if the role exists, false otherwise |
| 59 | + * Source: https://github.com/paul999/mention/ |
| 60 | + */ |
| 61 | + private function role_exists($role) |
| 62 | + { |
| 63 | + $sql = 'SELECT role_id |
| 64 | + FROM ' . ACL_ROLES_TABLE . " |
| 65 | + WHERE role_name = '" . $this->db->sql_escape($role) . "'"; |
| 66 | + $result = $this->db->sql_query_limit($sql, 1); |
| 67 | + $role_id = $this->db->sql_fetchfield('role_id'); |
| 68 | + $this->db->sql_freeresult($result); |
| 69 | + return $role_id; |
| 70 | + } |
| 71 | + } |
0 commit comments