function d3forum_sync_post_votes($mydirname, $post_id, $sync_also_topic_votes = true) { $db =& Database::getInstance(); $post_id = intval($post_id); $sql = "SELECT topic_id FROM " . $db->prefix($mydirname . "_posts") . " WHERE post_id={$post_id}"; if (!($result = $db->query($sql))) { die("ERROR SELECT post in sync post_votes"); } list($topic_id) = $db->fetchRow($result); $sql = "SELECT COUNT(*),SUM(vote_point) FROM " . $db->prefix($mydirname . "_post_votes") . " WHERE post_id={$post_id}"; if (!($result = $db->query($sql))) { die("ERROR SELECT post_votes in sync post_votes"); } list($votes_count, $votes_sum) = $db->fetchRow($result); if (!$db->queryF("UPDATE " . $db->prefix($mydirname . "_posts") . " SET votes_count=" . intval($votes_count) . ",votes_sum=" . intval($votes_sum) . " WHERE post_id={$post_id}")) { die(_MD_D3FORUM_ERR_SQL . __LINE__); } if ($sync_also_topic_votes) { return d3forum_sync_topic_votes($mydirname, $topic_id); } else { return true; } }
if (!empty($_POST['do_synctopics'])) { set_time_limit(0); $synctopics_start = intval(@$_POST['synctopics_start']); $synctopics_num = empty($_POST['synctopics_num']) ? 100 : intval($_POST['synctopics_num']); // sync topics $trs = $db->query("SELECT topic_id FROM " . $db->prefix($mydirname . "_topics") . " WHERE topic_id>={$synctopics_start} AND topic_id<" . ($synctopics_start + $synctopics_num)); $topic_counter = 0; while (list($topic_id) = $db->fetchRow($trs)) { $topic_counter++; $topic_id = intval($topic_id); // sync posts from post_votes $prs = $db->query("SELECT post_id FROM " . $db->prefix($mydirname . "_posts") . " WHERE topic_id={$topic_id}"); while (list($post_id) = $db->fetchRow($prs)) { d3forum_sync_post_votes($mydirname, $post_id, false); } d3forum_sync_topic_votes($mydirname, $topic_id, false); d3forum_sync_topic($mydirname, $topic_id, false); } $_SESSION[$mydirname . '_synctopics_start'] = $synctopics_start + $synctopics_num; $_SESSION[$mydirname . '_synctopics_num'] = $synctopics_num; redirect_header(XOOPS_URL . "/modules/{$mydirname}/admin/index.php?page=advanced_admin", 3, sprintf(_MD_A_D3FORUM_FMT_SYNCTOPICSDONE, $topic_counter)); exit; } if (!empty($_POST['do_syncforums'])) { set_time_limit(0); // sync all forums $result = $db->query("SELECT forum_id FROM " . $db->prefix($mydirname . "_forums")); while (list($forum_id) = $db->fetchRow($result)) { d3forum_sync_forum($mydirname, $forum_id, false); } redirect_header(XOOPS_URL . "/modules/{$mydirname}/admin/index.php?page=advanced_admin", 3, _MD_A_D3FORUM_MSG_SYNCTABLESDONE);