本文整理汇总了PHP中phpbb\db\driver\driver_interface::sql_multi_insert方法的典型用法代码示例。如果您正苦于以下问题:PHP driver_interface::sql_multi_insert方法的具体用法?PHP driver_interface::sql_multi_insert怎么用?PHP driver_interface::sql_multi_insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpbb\db\driver\driver_interface
的用法示例。
在下文中一共展示了driver_interface::sql_multi_insert方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: like
/**
* Like a post by first adding an entry into the likes table
* and then updating the like counter in the post table.
*
* @param int @post_id The post to be edited.
*
* @return int @likes_count The new likes count.
*/
public function like($post_id)
{
// Insert into likes table.
$sql_ary[] = array('post_id' => $post_id, 'user_id' => $this->user->data['user_id']);
$this->db->sql_multi_insert($this->table_prefix . 'likes', $sql_ary);
$likes_count = $this->inc_likes_count($post_id);
return $likes_count;
}
示例2: flush
/**
* Flushes the buffer content to the DB and clears the buffer.
*
* @return bool True when some data was flushed to the database.
* False otherwise.
*/
public function flush()
{
if (!empty($this->buffer)) {
$this->db->sql_multi_insert($this->table_name, $this->buffer);
$this->buffer = array();
return true;
}
return false;
}
示例3: insert_page_links
/**
* Insert page link location data for a page
*
* @param int $page_id Page identifier
* @param array $link_ids Page link location identifiers
* @return page_interface $this object for chaining calls
* @throws \phpbb\pages\exception\out_of_bounds
* @access public
*/
public function insert_page_links($page_id, $link_ids)
{
// First remove any existing page link data for this page
$this->remove_page_links($page_id);
$sql_ary = array();
foreach ($link_ids as $link_id) {
$sql_ary[] = array('page_id' => (int) $page_id, 'page_link_id' => (int) $link_id);
}
if (sizeof($sql_ary)) {
// Insert the new page link data for this page
$this->db->sql_multi_insert($this->pages_pages_links_table, $sql_ary);
}
return $this;
}
示例4: setStartAssets
public function setStartAssets($user_id, $country)
{
$sql = 'SELECT id
FROM ' . $this->container->getParameter('tables.consim.assets') . '
WHERE type_id = ' . self::CURRENCY_TYPE . ' or type_id = ' . self::BOND_TYPE;
$result = $this->db->sql_query($sql);
$insert = array();
while ($row = $this->db->sql_fetchrow($result)) {
$value = 0;
//set start value for country of birth
if ($row['id'] == 1 && $country == 'bak' || $row['id'] == 2 && $country == 'sur' || $row['id'] == 3 && $country == 'frt') {
$value = 50;
}
$insert[] = array('user_id' => (int) $user_id, 'asset_id' => (int) $row['id'], 'value' => $value);
/**$this->container->get('consim.core.entity.inventory_item')
->insert($user_id, $row['id'], $value);*/
}
$this->db->sql_freeresult($result);
$this->db->sql_multi_insert($this->container->getParameter('tables.consim.users_assets'), $insert);
}
示例5: create_missing_tags
/**
* Finds whether the given tags already exist and if not creates them in the db.
*/
private function create_missing_tags($tags)
{
// we will get all existing tags of $tags
// and then substract these from $tags
// result contains the tags that needs to be created
// to_create = $tags - exting
// ensure that there isn't a tag twice in the array
$tags = array_unique($tags);
$existing_tags = $this->get_existing_tags($tags);
// find all tags that are not in $existing_tags and add them to $sql_ary_new_tags
$sql_ary_new_tags = array();
foreach ($tags as $tag) {
if (!$this->in_array_r($tag, $existing_tags)) {
// tag needs to be created
$sql_ary_new_tags[] = array('tag' => $tag, 'tag_lowercase' => utf8_strtolower($tag));
}
}
// create the new tags
$this->db->sql_multi_insert($this->table_prefix . tables::TAGS, $sql_ary_new_tags);
}
示例6: phpbb_cache_moderators
//.........这里部分代码省略.........
function phpbb_cache_moderators($db, $cache, $auth)
{
// Remove cached sql results
$cache->destroy('sql', MODERATOR_CACHE_TABLE);
// Clear table
switch ($db->get_sql_layer()) {
case 'sqlite':
case 'sqlite3':
$db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE);
break;
default:
$db->sql_query('TRUNCATE TABLE ' . MODERATOR_CACHE_TABLE);
break;
}
// We add moderators who have forum moderator permissions without an explicit ACL_NEVER setting
$sql_ary = array();
// Grab all users having moderative options...
$hold_ary = $auth->acl_user_raw_data(false, 'm_%', false);
// Add users?
if (sizeof($hold_ary)) {
// At least one moderative option warrants a display
$ug_id_ary = array_keys($hold_ary);
// Remove users who have group memberships with DENY moderator permissions
$sql_ary_deny = array('SELECT' => 'a.forum_id, ug.user_id, g.group_id', 'FROM' => array(ACL_OPTIONS_TABLE => 'o', USER_GROUP_TABLE => 'ug', GROUPS_TABLE => 'g', ACL_GROUPS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => '(o.auth_option_id = a.auth_option_id OR o.auth_option_id = r.auth_option_id)
AND ((a.auth_setting = ' . ACL_NEVER . ' AND r.auth_setting IS NULL)
OR r.auth_setting = ' . ACL_NEVER . ')
AND a.group_id = ug.group_id
AND g.group_id = ug.group_id
AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . "\n\t\t\t\tAND ug.user_pending = 0\n\t\t\t\tAND o.auth_option " . $db->sql_like_expression('m_' . $db->get_any_char()));
$sql = $db->sql_build_query('SELECT', $sql_ary_deny);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
if (isset($hold_ary[$row['user_id']][$row['forum_id']])) {
unset($hold_ary[$row['user_id']][$row['forum_id']]);
}
}
$db->sql_freeresult($result);
if (sizeof($hold_ary)) {
// Get usernames...
$sql = 'SELECT user_id, username
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_id', array_keys($hold_ary));
$result = $db->sql_query($sql);
$usernames_ary = array();
while ($row = $db->sql_fetchrow($result)) {
$usernames_ary[$row['user_id']] = $row['username'];
}
$db->sql_freeresult($result);
foreach ($hold_ary as $user_id => $forum_id_ary) {
// Do not continue if user does not exist
if (!isset($usernames_ary[$user_id])) {
continue;
}
foreach ($forum_id_ary as $forum_id => $auth_ary) {
$sql_ary[] = array('forum_id' => (int) $forum_id, 'user_id' => (int) $user_id, 'username' => (string) $usernames_ary[$user_id], 'group_id' => 0, 'group_name' => '');
}
}
}
}
// Now to the groups...
$hold_ary = $auth->acl_group_raw_data(false, 'm_%', false);
if (sizeof($hold_ary)) {
$ug_id_ary = array_keys($hold_ary);
// Make sure not hidden or special groups are involved...
$sql = 'SELECT group_name, group_id, group_type
FROM ' . GROUPS_TABLE . '
WHERE ' . $db->sql_in_set('group_id', $ug_id_ary);
$result = $db->sql_query($sql);
$groupnames_ary = array();
while ($row = $db->sql_fetchrow($result)) {
if ($row['group_type'] == GROUP_HIDDEN || $row['group_type'] == GROUP_SPECIAL) {
unset($hold_ary[$row['group_id']]);
}
$groupnames_ary[$row['group_id']] = $row['group_name'];
}
$db->sql_freeresult($result);
foreach ($hold_ary as $group_id => $forum_id_ary) {
// If there is no group, we do not assign it...
if (!isset($groupnames_ary[$group_id])) {
continue;
}
foreach ($forum_id_ary as $forum_id => $auth_ary) {
$flag = false;
foreach ($auth_ary as $auth_option => $setting) {
// Make sure at least one ACL_YES option is set...
if ($setting == ACL_YES) {
$flag = true;
break;
}
}
if (!$flag) {
continue;
}
$sql_ary[] = array('forum_id' => (int) $forum_id, 'user_id' => 0, 'username' => '', 'group_id' => (int) $group_id, 'group_name' => (string) $groupnames_ary[$group_id]);
}
}
}
$db->sql_multi_insert(MODERATOR_CACHE_TABLE, $sql_ary);
}
示例7: index
/**
* Updates wordlist and wordmatch tables when a message is posted or changed
*
* @param string $mode Contains the post mode: edit, post, reply, quote
* @param int $post_id The id of the post which is modified/created
* @param string &$message New or updated post content
* @param string &$subject New or updated post subject
* @param int $poster_id Post author's user id
* @param int $forum_id The id of the forum in which the post is located
*/
public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
if (!$this->config['fulltext_native_load_upd'])
{
/**
* The search indexer is disabled, return
*/
return;
}
// Split old and new post/subject to obtain array of 'words'
$split_text = $this->split_message($message);
$split_title = $this->split_message($subject);
$cur_words = array('post' => array(), 'title' => array());
$words = array();
if ($mode == 'edit')
{
$words['add']['post'] = array();
$words['add']['title'] = array();
$words['del']['post'] = array();
$words['del']['title'] = array();
$sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m
WHERE m.post_id = $post_id
AND w.word_id = m.word_id";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$which = ($row['title_match']) ? 'title' : 'post';
$cur_words[$which][$row['word_text']] = $row['word_id'];
}
$this->db->sql_freeresult($result);
$words['add']['post'] = array_diff($split_text, array_keys($cur_words['post']));
$words['add']['title'] = array_diff($split_title, array_keys($cur_words['title']));
$words['del']['post'] = array_diff(array_keys($cur_words['post']), $split_text);
$words['del']['title'] = array_diff(array_keys($cur_words['title']), $split_title);
}
else
{
$words['add']['post'] = $split_text;
$words['add']['title'] = $split_title;
$words['del']['post'] = array();
$words['del']['title'] = array();
}
unset($split_text);
unset($split_title);
// Get unique words from the above arrays
$unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title']));
// We now have unique arrays of all words to be added and removed and
// individual arrays of added and removed words for text and title. What
// we need to do now is add the new words (if they don't already exist)
// and then add (or remove) matches between the words and this post
if (sizeof($unique_add_words))
{
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '
WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words);
$result = $this->db->sql_query($sql);
$word_ids = array();
while ($row = $this->db->sql_fetchrow($result))
{
$word_ids[$row['word_text']] = $row['word_id'];
}
$this->db->sql_freeresult($result);
$new_words = array_diff($unique_add_words, array_keys($word_ids));
$this->db->sql_transaction('begin');
if (sizeof($new_words))
{
$sql_ary = array();
foreach ($new_words as $word)
{
$sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0);
}
$this->db->sql_return_on_error(true);
$this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
$this->db->sql_return_on_error(false);
}
unset($new_words, $sql_ary);
}
else
//.........这里部分代码省略.........
示例8: main
function main($checked_user)
{
// Get all values
$sql = 'SELECT *
FROM ' . $this->points_values_table;
$result = $this->db->sql_query($sql);
$points_values = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
// Get all point config names and config values
$sql = 'SELECT config_name, config_value
FROM ' . $this->points_config_table;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) {
$points_config[$row['config_name']] = $row['config_value'];
}
$this->db->sql_freeresult($result);
// Set some variables
$start = $this->request->variable('start', 0);
$number = $points_values['number_show_per_page'];
add_form_key('lottery_tickets');
// Check, if lottery is enabled
if (!$points_config['lottery_enable']) {
$message = $this->user->lang['LOTTERY_DISABLED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
// Check, if user is allowed to use the lottery
if (!$this->auth->acl_get('u_use_lottery')) {
$message = $this->user->lang['NOT_AUTHORISED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
// Add part to bar
$this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'FORUM_NAME' => $points_values['lottery_name']));
// Add lottery base amount in description
$this->template->assign_vars(array('L_LOTTERY_BASE_AMOUNT' => sprintf($this->user->lang['LOTTERY_DESCRIPTION'], sprintf($this->functions_points->number_format_points($points_values['lottery_base_amount'])), $this->config['points_name'])));
// Recheck, if lottery was run, for those boards only having one user per day and which don't call the index page first
if ($points_values['lottery_draw_period'] != 0 && time() > $points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period']) {
$this->functions_points->run_lottery();
}
// Check, if user has purchased tickets
if ($this->request->variable('purchase_ticket', false) && $this->user->data['user_id'] != ANONYMOUS) {
if (!check_form_key('lottery_tickets')) {
trigger_error('FORM_INVALID');
}
// How many tickets have been bought?
$total_tickets_bought = $this->request->variable('total_tickets', 0);
// Check, if user already bought tickets
$sql_array = array('SELECT' => 'COUNT(ticket_id) AS number_of_tickets', 'FROM' => array($this->points_lottery_tickets_table => 't'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query($sql);
$number_tickets = $this->db->sql_fetchfield('number_of_tickets');
$this->db->sql_freeresult($result);
// Check, if the user tries to buy more tickets than allowed
if ($total_tickets_bought > $points_values['lottery_max_tickets']) {
$message = sprintf($this->user->lang['LOTTERY_MAX_TICKETS_REACH'], $points_values['lottery_max_tickets']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
// Check in user try to buy negative tickets
if ($total_tickets_bought <= 0) {
$message = $this->user->lang['LOTTERY_NEGATIVE_TICKETS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
// Check, if the already bought tickets and the new request are higher than the max set number of tickets
if ($number_tickets + $total_tickets_bought > $points_values['lottery_max_tickets']) {
$message = sprintf($this->user->lang['LOTTERY_MAX_TICKETS_LEFT'], $points_values['lottery_max_tickets'] - $number_tickets) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
// Check, if the user sent an empty value
if (!$total_tickets_bought) {
$message = $this->user->lang['LOTTERY_INVALID_INPUT'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
// Check. if lottery is enabled
if ($points_config['lottery_enable'] != 0 && $points_values['lottery_ticket_cost'] != 0) {
// Grab users total cash
$sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query($sql);
$purchaser = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
// Check, if the user has enough cash to buy tickets
if ($points_values['lottery_ticket_cost'] * $total_tickets_bought > $purchaser['user_points']) {
$message = $this->user->lang['LOTTERY_LACK_FUNDS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
}
}
// Loop through total purchased tickets and create insert array
for ($i = 0, $total_tickets_bought; $i < $total_tickets_bought; $i++) {
$sql_insert_ary[] = array('user_id' => $this->user->data['user_id']);
}
$this->db->sql_multi_insert($this->points_lottery_tickets_table, $sql_insert_ary);
// Check again, if lottery is enabled
if ($points_config['lottery_enable'] != 0) {
// Deduct cost
$viewer_cash = $purchaser['user_points'] - $points_values['lottery_ticket_cost'] * $total_tickets_bought;
$this->functions_points->set_points($this->user->data['user_id'], $viewer_cash);
// Update jackpot
$this->functions_points->set_points_values('lottery_jackpot', $points_values['lottery_jackpot'] + $points_values['lottery_ticket_cost'] * $total_tickets_bought);
}
$message = $this->user->lang['LOTTERY_TICKET_PURCHASED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
trigger_error($message);
//.........这里部分代码省略.........
示例9: activedate_set
public function activedate_set(\Symfony\Component\EventDispatcher\Event $event)
{
$topic_data = $event['topic_data'];
$first_post = intval($topic_data['topic_first_post_id']);
if (0 == $event['set_active']) {
$sql = 'DELETE FROM ' . $this->cal_table . ' WHERE post_id = ' . $first_post;
$this->db->sql_query($sql);
$sql = 'DELETE FROM ' . $this->cal_participants_table . ' WHERE post_id = ' . $first_post;
$this->db->sql_query($sql);
} else {
// Copy Date & entries
if ($this->hookup->topic_id != $event['topic_id']) {
if ($this->hookup->topic_id != 0) {
$this->hookup = new hookup();
}
$this->hookup->load_hookup($event['topic_id']);
}
$set_date = isset($this->hookup->hookup_dates[$event['set_active']]) ? isset($this->hookup->hookup_dates[$event['set_active']]['date_time']) ? $this->hookup->hookup_dates[$event['set_active']]['date_time'] : 0 : 0;
if (!$set_date) {
// We can't enter a text without date
return;
}
// Quick & dirty: The event
$sql = 'SELECT id FROM ' . $this->cal_event_table . ' WHERE event = \'hookup\'';
$result = $this->db->sql_query_limit($sql, 1);
$event_id = $this->db->sql_fetchfield('id');
$this->db->sql_freeresult($result);
if (!$event_id) {
$sql_ary = array('event' => 'hookup', 'participants' => 1);
$sql = 'INSERT INTO ' . $this->cal_event_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql);
$event_id = $this->db->sql_nextid();
}
$sql = 'SELECT count(*) as cnt FROM ' . $this->cal_table . ' WHERE post_id = ' . $topic_data['topic_first_post_id'];
$result = $this->db->sql_query($sql);
$cnt = $this->db->sql_fetchfield('cnt');
$this->db->sql_freeresult($result);
$sql_ary = array('post_id' => $topic_data['topic_first_post_id'], 'event_id' => $event_id, 'event_name' => $topic_data['topic_title'], 'date_from' => date('Y-m-d', $set_date));
if ($cnt) {
$sql = 'UPDATE ' . $this->cal_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE post_id = ' . $topic_data['topic_first_post_id'];
} else {
$sql = 'INSERT INTO ' . $this->cal_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
}
$this->db->sql_query($sql);
// Participants
$part_ary = $this->part_ary;
// Already entered?
$entered_users = array();
if ($cnt) {
$sql = 'SELECT user_id FROM ' . $this->cal_participants_table . ' WHERE ' . $this->db->sql_in_set('user_id', array_keys($this->hookup->hookup_users));
$result = $this->db->sql_query($sql);
$entered_users = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
}
$sql_ary = array();
foreach ($this->hookup->hookup_users as $user_id => $userdata) {
// Did the user enter anything for this date?
if (!isset($this->hookup->hookup_availables[$user_id][$event['set_active']]) || $this->hookup->hookup_availables[$user_id][$event['set_active']] == hookup::HOOKUP_UNSET) {
continue;
}
if (in_array($user_id, $entered_users)) {
// Update instead:
$sql = 'UPDATE ' . $this->cal_participants_table . ' SET ' . $this->db->sql_build_array('UPDATE', array('participants' => $part_ary[$this->hookup->hookup_availables[$user_id][$event['set_active']]], 'comment' => $userdata['comment'], 'date' => date('Y-m-d-H-i'))) . " WHERE user_id = {$user_id} AND post_id = {$topic_data['topic_first_post_id']}";
$this->db->sql_query($sql);
continue;
}
$sql_ary[] = array('post_id' => $topic_data['topic_first_post_id'], 'user_id' => $user_id, 'participants' => $part_ary[$this->hookup->hookup_availables[$user_id][$event['set_active']]], 'comments' => $userdata['comment'], 'date' => date('Y-m-d-H-i'));
}
$this->db->sql_multi_insert($this->cal_participants_table, $sql_ary);
}
}
示例10: permission_set
//.........这里部分代码省略.........
if (!is_array($auth_option)) {
$auth_option = array($auth_option);
}
$new_auth = array();
$sql = 'SELECT auth_option_id
FROM ' . ACL_OPTIONS_TABLE . '
WHERE ' . $this->db->sql_in_set('auth_option', $auth_option);
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) {
$new_auth[] = (int) $row['auth_option_id'];
}
$this->db->sql_freeresult($result);
if (empty($new_auth)) {
return;
}
$current_auth = array();
$type = (string) $type;
// Prevent PHP bug.
switch ($type) {
case 'role':
$sql = 'SELECT role_id
FROM ' . ACL_ROLES_TABLE . "\n\t\t\t\t\tWHERE role_name = '" . $this->db->sql_escape($name) . "'";
$this->db->sql_query($sql);
$role_id = (int) $this->db->sql_fetchfield('role_id');
if (!$role_id) {
throw new \phpbb\db\migration\exception('ROLE_NOT_EXIST', $name);
}
$sql = 'SELECT auth_option_id, auth_setting
FROM ' . ACL_ROLES_DATA_TABLE . '
WHERE role_id = ' . $role_id;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) {
$current_auth[$row['auth_option_id']] = $row['auth_setting'];
}
$this->db->sql_freeresult($result);
break;
case 'group':
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "\n\t\t\t\t\tWHERE group_name = '" . $this->db->sql_escape($name) . "'";
$this->db->sql_query($sql);
$group_id = (int) $this->db->sql_fetchfield('group_id');
if (!$group_id) {
throw new \phpbb\db\migration\exception('GROUP_NOT_EXIST', $name);
}
// If the group has a role set for them we will add the requested permissions to that role.
$sql = 'SELECT auth_role_id
FROM ' . ACL_GROUPS_TABLE . '
WHERE group_id = ' . $group_id . '
AND auth_role_id <> 0
AND forum_id = 0';
$this->db->sql_query($sql);
$role_id = (int) $this->db->sql_fetchfield('auth_role_id');
if ($role_id) {
$sql = 'SELECT role_name, role_type
FROM ' . ACL_ROLES_TABLE . '
WHERE role_id = ' . $role_id;
$this->db->sql_query($sql);
$role_data = $this->db->sql_fetchrow();
$role_name = $role_data['role_name'];
$role_type = $role_data['role_type'];
// Filter new auth options to match the role type: a_ | f_ | m_ | u_
// Set new auth options to the role only if options matching the role type were found
$auth_option = array_filter($auth_option, function ($option) use($role_type) {
return strpos($option, $role_type) === 0;
});
if (sizeof($auth_option)) {
return $this->permission_set($role_name, $auth_option, 'role', $has_permission);
}
}
$sql = 'SELECT auth_option_id, auth_setting
FROM ' . ACL_GROUPS_TABLE . '
WHERE group_id = ' . $group_id;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) {
$current_auth[$row['auth_option_id']] = $row['auth_setting'];
}
$this->db->sql_freeresult($result);
break;
}
$sql_ary = array();
switch ($type) {
case 'role':
foreach ($new_auth as $auth_option_id) {
if (!isset($current_auth[$auth_option_id])) {
$sql_ary[] = array('role_id' => $role_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission);
}
}
$this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);
break;
case 'group':
foreach ($new_auth as $auth_option_id) {
if (!isset($current_auth[$auth_option_id])) {
$sql_ary[] = array('group_id' => $group_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission);
}
}
$this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary);
break;
}
$this->auth->acl_clear_prefetch();
}