Exemplo n.º 1
0
function mysupport_upgrade()
{
    global $mybb, $db, $cache;
    $mysupport_cache = $cache->read("mysupport");
    $old_version = $mysupport_cache['version'];
    // legacy
    if (!$old_version) {
        $old_version = $cache->read("mysupport_version");
    }
    // only need to run through this if the version has actually changed
    if (!empty($old_version) && $old_version < MYSUPPORT_VERSION) {
        // reimport the settings to add any new ones and refresh the current ones
        mysupport_import_settings();
        // remove the current templates, but only the master versions
        mysupport_do_templates(0, true);
        // re-import the master templates
        mysupport_do_templates(1);
        // add any new table columns that don't already exist
        mysupport_table_columns(1);
        mysupport_stylesheet(2);
        $deleted_settings = array();
        $deleted_templates = array();
        // go through each upgrade process; versions are only listed here if there were changes FROM that version to the next
        // it will go through the ones it needs to and make the changes it needs
        if ($old_version <= 0.3) {
            // made some mistakes with the original table column additions, 3 of the fields weren't long enough... I do apologise
            $db->modify_column("threads", "statusuid", "INT(10) NOT NULL DEFAULT '0'");
            $db->modify_column("users", "deniedsupportreason", "INT(5) NOT NULL DEFAULT '0'");
            $db->modify_column("users", "deniedsupportuid", "INT(10) NOT NULL DEFAULT '0'");
            // maybe 255 isn't big enough for this after all
            $db->modify_column("mysupport", "description", "VARCHAR(500) NOT NULL");
        }
        if ($old_version <= 0.4) {
            mysupport_insert_task();
            mysupport_stylesheet(1);
            mysupport_recount_technical_threads();
            $query = $db->simple_select("threads", "DISTINCT assign", "assign != '0'");
            while ($user = $db->fetch_field($query, "assign")) {
                mysupport_recount_assigned_threads($user);
            }
            // there's just a 'mysupport' cache now with other things in it
            $db->delete_query("datacache", "title = 'mysupport_version'");
            // cache priorities and support denial reasons
            mysupport_cache("priorities");
            mysupport_cache("deniedreasons");
            // we need to update the setting of what to log, to include putting threads on hold, but don't change which actions may have logging disabled
            if ($mybb->settings['mysupportmodlog']) {
                $mybb->settings['mysupportmodlog'] .= ",";
            }
            $mybb->settings['mysupportmodlog'] .= "12";
            $update = array("value" => $db->escape_string($mybb->settings['mysupportmodlog']));
            $db->update_query("settings", $update, "name = 'mysupportmodlog'");
            rebuild_settings();
        }
        if (!empty($deleted_settings)) {
            $deleted_settings = "'" . implode("','", array_map($db->escape_string, $deleted_settings)) . "'";
            // have to use $db->escape_string above instead of around $deleted_settings directly because otherwise it escapes the ' around the names, which are important
            $db->delete_query("settings", "name IN ({$deleted_settings})");
            mysupport_update_setting_orders();
            rebuild_settings();
        }
        if (!empty($deleted_templates)) {
            $deleted_templates = "'" . implode("','", array_map($db->escape_string, $deleted_templates)) . "'";
            // have to use $db->escape_string above instead of around $deleted_templates directly because otherwise it escapes the ' around the names, which are important
            $db->delete_query("templates", "title IN ({$deleted_templates})");
        }
        // now we can update the cache with the new version
        mysupport_cache("version");
        // rebuild the forums and usergroups caches in case anything's changed
        $cache->update_forums();
        $cache->update_usergroups();
    }
}
Exemplo n.º 2
0
/**
 * Change the status of a thread.
 *
 * @param array Information about the thread.
 * @param int The new status.
 * @param bool If this is changing the status of multiple threads.
**/
function mysupport_change_status($thread_info, $status = 0, $multiple = false)
{
    global $mybb, $db, $lang, $cache;
    $status = intval($status);
    if ($status == 3) {
        // if it's 3, we're solving and closing, but we'll just check for regular solving in the list of things to log
        // saves needing to have a 3, for the solving and closing option, in the setting of what to log
        // then below it'll check if 1 is in the list of things to log; 1 is normal solving, so if that's in the list, it'll log this too
        $log_status = 1;
    } else {
        $log_status = $status;
    }
    if ($multiple) {
        $tid = -1;
        $old_status = -1;
    } else {
        $tid = intval($thread_info['tid']);
        $old_status = intval($thread_info['status']);
    }
    $move_fid = "";
    $forums = $cache->read("forums");
    foreach ($forums as $forum) {
        if (!empty($forum['mysupportmove']) && $forum['mysupportmove'] != 0) {
            $move_fid = intval($forum['fid']);
            break;
        }
    }
    // are we marking it as solved and is it being moved??
    if (!empty($move_fid) && ($status == 1 || $status == 3)) {
        if ($mybb->settings['mysupportmoveredirect'] == "none") {
            $move_type = "move";
            $redirect_time = 0;
        } else {
            $move_type = "redirect";
            if ($mybb->settings['mysupportmoveredirect'] == "forever") {
                $redirect_time = 0;
            } else {
                $redirect_time = intval($mybb->settings['mysupportmoveredirect']);
            }
        }
        if ($multiple) {
            $move_tids = $thread_info;
        } else {
            $move_tids = array($thread_info['tid']);
        }
        require_once MYBB_ROOT . "inc/class_moderation.php";
        $moderation = new Moderation();
        // the reason it loops through using move_thread is because move_threads doesn't give the option for a redirect
        // if it's not a multiple thread it will just loop through once as there'd only be one value in the array
        foreach ($move_tids as $move_tid) {
            $moderation->move_thread($move_tid, $move_fid, $move_type, $redirect_time);
        }
    }
    if ($multiple) {
        $tids = implode(",", array_map("intval", $thread_info));
        $where_sql = "tid IN (" . $db->escape_string($tids) . ")";
    } else {
        $where_sql = "tid = '" . intval($tid) . "'";
    }
    // we need to build an array of users who have been assigned threads before the assignment is removed
    if ($status == 1 || $status == 3) {
        $query = $db->simple_select("threads", "DISTINCT assign", $where_sql . " AND assign != '0'");
        $assign_users = array();
        while ($user = $db->fetch_field($query, "assign")) {
            $assign_users[] = $user;
        }
    }
    if ($status == 3 || $status == 1 && $mybb->settings['mysupportclosewhensolved'] == "always") {
        // the bit after || here is for if we're marking as solved via marking a post as the best answer, it will close if it's set to always close
        // the incoming status would be 1 but we need to close it if necessary
        $status_update = array("closed" => 1, "status" => 1, "statusuid" => intval($mybb->user['uid']), "statustime" => TIME_NOW, "assign" => 0, "assignuid" => 0, "priority" => 0, "closedbymysupport" => 1, "onhold" => 0);
    } elseif ($status == 0) {
        // if we're marking it as unsolved, a post may have been marked as the best answer when it was originally solved, best remove it, as well as rest everything else
        $status_update = array("status" => 0, "statusuid" => 0, "statustime" => 0, "bestanswer" => 0);
    } elseif ($status == 4) {
        /** if it's 4, it's because it was marked as being not technical after being marked technical
         ** basically put back to the original status of not solved (0)
         ** however it needs to be 4 so we can differentiate between this action (technical => not technical), and a user marking it as not solved
         ** because both of these options eventually set it back to 0
         ** so the mod log entry will say the correct action as the status was 4 and it used that
         ** now that the log has been inserted we can set it to 0 again for the thread update query so it's marked as unsolved **/
        $status_update = array("status" => 0, "statusuid" => 0, "statustime" => 0);
    } elseif ($status == 2) {
        $status_update = array("status" => 2, "statusuid" => intval($mybb->user['uid']), "statustime" => TIME_NOW);
    } else {
        $status_update = array("status" => 1, "statusuid" => intval($mybb->user['uid']), "statustime" => TIME_NOW, "assign" => 0, "assignuid" => 0, "priority" => 0, "onhold" => 0);
    }
    $db->update_query("threads", $status_update, $where_sql);
    // if the thread is being marked as technical, being marked as something else after being marked technical, or we're changing the status of multiple threads, recount the number of technical threads
    if ($status == 2 || $old_status == 2 || $multiple) {
        mysupport_recount_technical_threads();
    }
    // if the thread is being marked as solved, recount the number of assigned threads for any users who were assigned threads that are now being marked as solved
    if ($status == 1 || $status == 3) {
        foreach ($assign_users as $user) {
            mysupport_recount_assigned_threads($user);
        }
    }
    if ($status == 0) {
        // if we're marking a thread(s) as unsolved, re-open any threads that were closed when they were marked as solved, but not any that were closed by denying support
        $update = array("closed" => 0, "closedbymysupport" => 0);
        $db->update_query("threads", $update, $where_sql . " AND closed = '1' AND closedbymysupport = '1'");
    }
    // get the friendly version of the status for the redirect message and mod log
    $friendly_old_status = "'" . mysupport_get_friendly_status($old_status) . "'";
    $friendly_new_status = "'" . mysupport_get_friendly_status($status) . "'";
    if ($multiple) {
        mysupport_mod_log_action($log_status, $lang->sprintf($lang->status_change_mod_log_multi, count($thread_info), $friendly_new_status));
        mysupport_redirect_message($lang->sprintf($lang->status_change_success_multi, count($thread_info), htmlspecialchars_uni($friendly_new_status)));
    } else {
        mysupport_mod_log_action($log_status, $lang->sprintf($lang->status_change_mod_log, $friendly_new_status));
        mysupport_redirect_message($lang->sprintf($lang->status_change_success, htmlspecialchars_uni($friendly_old_status), htmlspecialchars_uni($friendly_new_status)));
    }
}