@@ -51,9 +51,35 @@ public function update_data()
5151 array ('config_text.add ' , array ('tou_custom_pp_uid ' , '' )),
5252 array ('config_text.add ' , array ('tou_custom_pp_bitfield ' , '' )),
5353 array ('config_text.add ' , array ('tou_custom_pp_flags ' , OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS )),
54-
54+ // Add permissions
55+ array ('permission.add ' , array ('a_tou_manage ' , true )),
56+ // Add config version
5557 array ('config.add ' , array ('tou_ext_version ' , '1.1.0 ' )),
5658 );
59+
60+ // Check if admin role exists and assign permission to admin role
61+ if ($ this ->role_exists ('ROLE_ADMIN_FULL ' ))
62+ {
63+ $ data [] = array ('permission.permission_set ' , array ('ROLE_ADMIN_FULL ' , 'a_tou_manage ' , 'role ' , true ));
64+ }
5765 return $ data ;
5866 }
67+
68+ /**
69+ * Checks whether the given role does exist or not.
70+ *
71+ * @param String $role the name of the role
72+ * @return true if the role exists, false otherwise
73+ * Source: https://github.com/paul999/mention/
74+ */
75+ private function role_exists ($ role )
76+ {
77+ $ sql = 'SELECT role_id
78+ FROM ' . ACL_ROLES_TABLE . "
79+ WHERE role_name = ' " . $ this ->db ->sql_escape ($ role ) . "' " ;
80+ $ result = $ this ->db ->sql_query_limit ($ sql , 1 );
81+ $ role_id = $ this ->db ->sql_fetchfield ('role_id ' );
82+ $ this ->db ->sql_freeresult ($ result );
83+ return $ role_id ;
84+ }
5985}
0 commit comments