Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
remove_orphaned_roles.php
01 <?php
02 /**
03 *
04 * This file is part of the phpBB Forum Software package.
05 *
06 * @copyright (c) phpBB Limited <https://www.phpbb.com>
07 * @license GNU General Public License, version 2 (GPL-2.0)
08 *
09 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14 namespace phpbb\db\migration\data\v33x;
15
16 class remove_orphaned_roles extends \phpbb\db\migration\migration
17 {
18 static public function depends_on()
19 {
20 return ['\phpbb\db\migration\data\v33x\v335'];
21 }
22
23 public function update_data()
24 {
25 return [
26 ['custom', [[$this, 'acl_remove_orphaned_roles']]],
27 ];
28 }
29
30 public function acl_remove_orphaned_roles()
31 {
32 $role_ids = [];
33 $auth_role_ids = [];
34
35 $sql = 'SELECT auth_role_id
36 FROM ' . ACL_GROUPS_TABLE . '
37 WHERE auth_role_id <> 0
38 AND forum_id = 0';
39 $result = $this->db->sql_query($sql);
40 while ($row = $this->db->sql_fetchrow($result))
41 {
42 $auth_role_ids[] = $row['auth_role_id'];
43 }
44 $this->db->sql_freeresult($result);
45
46 if (count($auth_role_ids))
47 {
48 $sql = 'SELECT role_id
49 FROM ' . ACL_ROLES_TABLE . '
50 WHERE ' . $this->db->sql_in_set('role_id', $auth_role_ids);
51 $result = $this->db->sql_query($sql);
52 while ($row = $this->db->sql_fetchrow($result))
53 {
54 $role_ids[] = $row['role_id'];
55 }
56 $this->db->sql_freeresult($result);
57 }
58
59 $non_existent_role_ids = array_diff($auth_role_ids, $role_ids);
60
61 // Nothing to do, there are no non-existent roles assigned to groups
62 if (empty($non_existent_role_ids))
63 {
64 return true;
65 }
66
67 // Remove assigned non-existent roles from users and groups
68 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
69 WHERE ' . $this->db->sql_in_set('auth_role_id', $non_existent_role_ids);
70 $this->db->sql_query($sql);
71
72 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
73 WHERE ' . $this->db->sql_in_set('auth_role_id', $non_existent_role_ids);
74 $this->db->sql_query($sql);
75
76 $auth = new \phpbb\auth\auth();
77 $auth->acl_clear_prefetch();
78
79 return true;
80 }
81 }
82