Exemple #1
0
/**
 * Run the updates that are needed after changing the display_name for a user.
 *
 * The display_name for users is stored redundant at several places
 * in the database (this improves the speed of the system, because joins
 * with the user table do not have to be made). This function will update
 * that redundant information to match the active display_name field in
 * the user data.
 *
 * @param array $userdata
 *     A userdata array containing at least the fields "user_id" and
 *     "display_name".
 */
function phorum_db_user_display_name_updates($userdata)
{
    $PHORUM = $GLOBALS['PHORUM'];
    if (!isset($userdata['user_id'])) {
        trigger_error('phorum_db_user_display_name_updates(): Missing user_id field in ' . 'the $userdata parameter', E_USER_ERROR);
    }
    if (!isset($userdata['display_name'])) {
        trigger_error('phorum_db_user_display_name_updates(): Missing display_name field ' . 'in the $userdata parameter', E_USER_ERROR);
    }
    $author = phorum_db_interact(DB_RETURN_QUOTED, $userdata['display_name']);
    $user_id = (int) $userdata['user_id'];
    // Update forum message authors.
    phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['message_table']}\n         SET    author = '{$author}'\n         WHERE  user_id = {$user_id}", NULL, DB_GLOBALQUERY | DB_MASTERQUERY);
    // Update recent forum reply authors.
    phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['message_table']}\n         SET    recent_author = '{$author}'\n         WHERE  recent_user_id = {$user_id}", NULL, DB_GLOBALQUERY | DB_MASTERQUERY);
    // Update PM author data.
    phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['pm_messages_table']}\n         SET    author = '{$author}'\n         WHERE  user_id = {$user_id}", NULL, DB_MASTERQUERY);
    // Update PM recipient data.
    $res = phorum_db_interact(DB_RETURN_RES, "SELECT m.pm_message_id AS pm_message_id, meta\n         FROM   {$PHORUM['pm_messages_table']} AS m,\n                {$PHORUM['pm_xref_table']} AS x\n         WHERE  m.pm_message_id = x.pm_message_id AND\n                x.user_id = {$user_id} AND\n                special_folder != 'outbox'", NULL, DB_MASTERQUERY);
    while ($row = phorum_db_fetch_row($res, DB_RETURN_ASSOC)) {
        $meta = unserialize($row['meta']);
        $meta['recipients'][$user_id]['display_name'] = $author;
        $meta = phorum_db_interact(DB_RETURN_QUOTED, serialize($meta));
        phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['pm_messages_table']}\n             SET    meta='{$meta}'\n             WHERE  pm_message_id = {$row['pm_message_id']}", NULL, DB_MASTERQUERY);
    }
}
    return;
}
define('phorum_page', 'rebuild_thread_info');
define('PHORUM_ADMIN', 1);
chdir(dirname(__FILE__) . "/..");
require_once './common.php';
include './include/thread_info.php';
// Make sure that the output is not buffered.
phorum_ob_clean();
if (!ini_get('safe_mode')) {
    set_time_limit(0);
    ini_set("memory_limit", "128M");
}
print "\nRebuilding thread info meta data ...\n";
$count_total = phorum_db_interact(DB_RETURN_VALUE, "SELECT count(*)\n     FROM   {$PHORUM["message_table"]}\n     WHERE  parent_id = 0 AND\n            message_id = thread");
$res = phorum_db_interact(DB_RETURN_RES, "SELECT message_id, forum_id\n     FROM   {$PHORUM["message_table"]}\n     WHERE  parent_id = 0 AND\n            message_id = thread");
$size = strlen($count_total);
$count = 0;
while ($row = phorum_db_fetch_row($res, DB_RETURN_ROW)) {
    $PHORUM['forum_id'] = $row[1];
    phorum_update_thread_info($row[0]);
    $count++;
    $perc = floor($count / $count_total * 100);
    $barlen = floor(20 * ($perc / 100));
    $bar = "[";
    $bar .= str_repeat("=", $barlen);
    $bar .= str_repeat(" ", 20 - $barlen);
    $bar .= "]";
    printf("updating %{$size}d / %{$size}d  %s (%d%%)\r", $count, $count_total, $bar, $perc);
}
print "\n\n";
Exemple #3
0
<?php

if (!defined("PHORUM_ADMIN")) {
    return;
}
// Create tables for the new PM system.
$upgrade_queries[] = "CREATE TABLE {$PHORUM["pm_messages_table"]} (\n    pm_message_id int(10) unsigned NOT NULL auto_increment,\n    from_user_id int(10) unsigned NOT NULL default '0',\n    from_username varchar(50) NOT NULL default '',\n    subject varchar(100) NOT NULL default '',\n    message text NOT NULL,\n    datestamp int(10) unsigned NOT NULL default '0',\n    meta mediumtext NOT NULL,\n    PRIMARY KEY (pm_message_id)\n) TYPE=MyISAM";
$upgrade_queries[] = "CREATE TABLE {$PHORUM["pm_folders_table"]} (\n    pm_folder_id int(10) unsigned NOT NULL auto_increment,\n    user_id int(10) unsigned NOT NULL default '0',\n    foldername varchar(20) NOT NULL default '',\n    KEY user_id (user_id),\n    PRIMARY KEY (pm_folder_id)\n) TYPE=MyISAM";
$upgrade_queries[] = "CREATE TABLE {$PHORUM["pm_xref_table"]} (\n    pm_xref_id int(10) unsigned NOT NULL auto_increment,\n    user_id int(10) unsigned NOT NULL default '0',\n    pm_folder_id int(10) unsigned NOT NULL default '0',\n    special_folder varchar(10),\n    pm_message_id int(10) unsigned NOT NULL default '0',\n    read_flag tinyint(1) NOT NULL default '0',\n    reply_flag tinyint(1) NOT NULL default '0',\n    PRIMARY KEY (pm_xref_id),\n    KEY xref (user_id,pm_folder_id,pm_message_id),\n    KEY read_flag (read_flag)\n) TYPE=MyISAM";
// converting the old PM system to the new one.
$old_table = "{$PHORUM['DBCONFIG']['table_prefix']}_private_messages";
$res = phorum_db_interact(DB_RETURN_RES, "SELECT *\n     FROM   {$old_table}", NULL, DB_MASTERQUERY);
while ($row = phorum_db_fetch_row($res, DB_RETURN_ASSOC)) {
    // Put the message in the message table.
    $meta = serialize(array('recipients' => array($row["to_user_id"] => array('user_id' => $row["to_user_id"], 'username' => $row["to_username"], 'read_flag' => $row["read_flag"]))));
    $sql = "INSERT INTO {$PHORUM["pm_messages_table"]} SET " . "pm_message_id = {$row["private_message_id"]}, " . "from_user_id = {$row["from_user_id"]}, " . "from_username = '******', " . "subject = '" . addslashes($row['subject']) . "', " . "message = '" . addslashes($row['message']) . "', " . "datestamp = {$row["datestamp"]}, " . "meta = '" . addslashes($meta) . "'";
    $upgrade_queries[] = $sql;
    // Link message to recipient inbox.
    if (!$row["to_del_flag"]) {
        $sql = "INSERT INTO {$PHORUM["pm_xref_table"]} SET " . "user_id = {$row["to_user_id"]}, " . "pm_folder_id = 0, " . "special_folder = '" . PHORUM_PM_INBOX . "', " . "pm_message_id = {$row["private_message_id"]}, " . "read_flag = {$row["read_flag"]}, " . "reply_flag = {$row["reply_flag"]}";
        $upgrade_queries[] = $sql;
    }
    // Link message to sender outbox.
    if (!$row["from_del_flag"]) {
        $sql = "INSERT INTO {$PHORUM["pm_xref_table"]} SET " . "user_id = {$row["from_user_id"]}, " . "pm_folder_id = 0, " . "special_folder = '" . PHORUM_PM_OUTBOX . "', " . "pm_message_id = {$row["private_message_id"]}, " . "read_flag = 1, " . "reply_flag = 0";
        $upgrade_queries[] = $sql;
    }
}