| ' . $txt['smf86'] . ' |
';
// We don't allow 0's in the IDs...
db_query("
UPDATE {$db_prefix}topics
SET ID_TOPIC = NULL
WHERE ID_TOPIC = 0", __FILE__, __LINE__);
db_query("
UPDATE {$db_prefix}messages
SET ID_MSG = NULL
WHERE ID_MSG = 0", __FILE__, __LINE__);
// Fix all messages that have a topic ID that cannot be found in the topics table.
$resultMsg = db_query("
SELECT
m.ID_TOPIC, MIN(m.ID_MSG) AS myID_FIRST_MSG, MAX(m.ID_MSG) AS myID_LAST_MSG,
COUNT(m.ID_MSG) - 1 AS myNumReplies
FROM {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = m.ID_TOPIC)
WHERE t.ID_TOPIC IS NULL
GROUP BY m.ID_TOPIC", __FILE__, __LINE__);
if (mysql_num_rows($resultMsg) > 0)
{
createSalvageArea();
while ($msgArray = mysql_fetch_assoc($resultMsg))
{
$memberStartedID = getMsgMemberID($msgArray['myID_FIRST_MSG']);
$memberUpdatedID = getMsgMemberID($msgArray['myID_LAST_MSG']);
db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numReplies)
VALUES ($salvageBoardID, $memberStartedID, $memberUpdatedID,
$msgArray[myID_FIRST_MSG], $msgArray[myID_LAST_MSG], $msgArray[myNumReplies])", __FILE__, __LINE__);
$newTopicID = db_insert_id();
db_query("
UPDATE {$db_prefix}messages
SET ID_TOPIC = $newTopicID, ID_BOARD = $salvageBoardID
WHERE ID_TOPIC = $msgArray[ID_TOPIC]", __FILE__, __LINE__);
$context['raw_data'] .= ' ';
}
}
mysql_free_result($resultMsg);
$context['raw_data'] .= ' ';
// Remove all topics that have zero messages in the messages table.
$resultTopic = db_query("
SELECT t.ID_TOPIC, COUNT(m.ID_MSG) AS numMsg
FROM {$db_prefix}topics AS t
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_TOPIC = t.ID_TOPIC)
GROUP BY t.ID_TOPIC
HAVING numMsg = 0", __FILE__, __LINE__);
if (mysql_num_rows($resultTopic) > 0)
{
$stupidTopics = array();
while ($topicArray = mysql_fetch_assoc($resultTopic))
$stupidTopics[] = $topicArray['ID_TOPIC'];
db_query("
DELETE FROM {$db_prefix}topics
WHERE ID_TOPIC IN (" . implode(',', $stupidTopics) . ')
LIMIT ' . count($stupidTopics), __FILE__, __LINE__);
$context['raw_data'] .= db_affected_rows() . ' ' . $txt['smf312'] . ' ';
}
mysql_free_result($resultTopic);
// Fix all ID_FIRST_MSG, ID_LAST_MSG and numReplies in the topic table.
$resultTopic = db_query("
SELECT
t.ID_TOPIC, MIN(m.ID_MSG) AS myID_FIRST_MSG, t.ID_FIRST_MSG,
MAX(m.ID_MSG) AS myID_LAST_MSG, t.ID_LAST_MSG, COUNT(m.ID_MSG) - 1 AS myNumReplies,
t.numReplies
FROM {$db_prefix}topics AS t
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_TOPIC = t.ID_TOPIC)
GROUP BY t.ID_TOPIC
HAVING ID_FIRST_MSG != myID_FIRST_MSG OR ID_LAST_MSG != myID_LAST_MSG OR numReplies != myNumReplies", __FILE__, __LINE__);
if (mysql_num_rows($resultTopic) > 0)
{
while ($topicArray = mysql_fetch_assoc($resultTopic))
{
$memberStartedID = getMsgMemberID($topicArray['myID_FIRST_MSG']);
$memberUpdatedID = getMsgMemberID($topicArray['myID_LAST_MSG']);
$result = db_query("
UPDATE {$db_prefix}topics
SET ID_FIRST_MSG = '$topicArray[myID_FIRST_MSG]',
ID_MEMBER_STARTED = '$memberStartedID', ID_LAST_MSG = $topicArray[myID_LAST_MSG],
ID_MEMBER_UPDATED = '$memberUpdatedID', numReplies = '$topicArray[myNumReplies]'
WHERE ID_TOPIC = $topicArray[ID_TOPIC]
LIMIT 1", __FILE__, __LINE__);
}
}
mysql_free_result($resultTopic);
// Fix all topics that have a board ID that cannot be found in the boards table.
$resultTopics = db_query("
SELECT t.ID_BOARD, COUNT(t.ID_TOPIC) AS myNumTopics, COUNT(m.ID_MSG) AS myNumPosts
FROM {$db_prefix}topics AS t
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_TOPIC = t.ID_TOPIC)
WHERE b.ID_BOARD IS NULL
GROUP BY t.ID_BOARD", __FILE__, __LINE__);
if (mysql_num_rows($resultTopics) > 0)
{
createSalvageArea();
while ($topicArray = mysql_fetch_assoc($resultTopics))
{
db_query("
INSERT INTO {$db_prefix}boards
(ID_CAT, name, numTopics, numPosts)
VALUES ($salvageCatID, 'Salvaged board', $topicArray[myNumTopics],
$topicArray[myNumPosts])", __FILE__, __LINE__);
$newBoardID = db_insert_id();
db_query("
UPDATE {$db_prefix}topics
SET ID_BOARD = $newBoardID
WHERE ID_BOARD = $topicArray[ID_BOARD]", __FILE__, __LINE__);
db_query("
UPDATE {$db_prefix}messages
SET ID_BOARD = $newBoardID
WHERE ID_BOARD = $topicArray[ID_BOARD]", __FILE__, __LINE__);
$context['raw_data'] .= $txt['smf311'] . ' ';
}
}
mysql_free_result($resultTopics);
// Fix all boards that have a cat ID that cannot be found in the cats table.
$resultBoards = db_query("
SELECT b.ID_CAT
FROM {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)
WHERE c.ID_CAT IS NULL
GROUP BY b.ID_CAT", __FILE__, __LINE__);
if (mysql_num_rows($resultBoards) > 0)
{
createSalvageArea();
while ($boardArray = mysql_fetch_assoc($resultBoards))
{
db_query("
UPDATE {$db_prefix}boards
SET ID_CAT = $salvageCatID
WHERE ID_CAT = $boardArray[ID_CAT]", __FILE__, __LINE__);
$context['raw_data'] .= $txt['smf311'] . ' ';
}
}
mysql_free_result($resultBoards);
// Fix all boards that have a parent ID that cannot be found in the boards table.
$resultParents = db_query("
SELECT b.ID_PARENT
FROM {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}boards AS p ON (p.ID_BOARD = b.ID_PARENT)
WHERE b.ID_PARENT != 0
AND (p.ID_BOARD IS NULL OR p.ID_BOARD = b.ID_BOARD)
GROUP BY b.ID_PARENT", __FILE__, __LINE__);
if (mysql_num_rows($resultParents) > 0)
{
createSalvageArea();
while ($parentArray = mysql_fetch_assoc($resultParents))
{
db_query("
UPDATE {$db_prefix}boards
SET ID_PARENT = $salvageBoardID, ID_CAT = $salvageCatID, childLevel = 1
WHERE ID_PARENT = $parentArray[ID_PARENT]", __FILE__, __LINE__);
$context['raw_data'] .= $txt['parent_repair_fixed'] . ' ';
}
}
mysql_free_result($resultParents);
// Last step-make sure all non-guest posters still exist.
$resultMsg = db_query("
SELECT m.ID_MSG
FROM {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MEMBER != 0
AND mem.ID_MEMBER IS NULL", __FILE__, __LINE__);
if (mysql_num_rows($resultMsg) > 0)
{
$guestMessages = array();
while ($msgArray = mysql_fetch_assoc($resultMsg))
$guestMessages[] = $msgArray['ID_MSG'];
db_query("
UPDATE {$db_prefix}messages
SET ID_MEMBER = 0
WHERE ID_MSG IN (" . implode(',', $guestMessages) . ')
LIMIT ' . count($guestMessages), __FILE__, __LINE__);
}
mysql_free_result($resultMsg);
$resultPolls = db_query("
SELECT t.ID_POLL
FROM {$db_prefix}topics AS t
LEFT JOIN {$db_prefix}polls AS p ON (p.ID_POLL = t.ID_POLL)
WHERE p.ID_POLL IS NULL
GROUP BY t.ID_POLL", __FILE__, __LINE__);
$polls = array();
while ($rowPolls = mysql_fetch_assoc($resultPolls))
$polls[] = $rowPolls['ID_POLL'];
mysql_free_result($resultPolls);
if (!empty($polls))
db_query("
UPDATE {$db_prefix}topics
SET ID_POLL = 0
WHERE ID_POLL IN (" . implode(', ', $polls) . ")
LIMIT " . count($polls), __FILE__, __LINE__);
updateStats('message');
updateStats('topic');
updateStats('calendar');
$context['raw_data'] .= '
' . $txt['smf92'] . '
' . $txt[137] . '
' . $txt[236] . ' ' . $txt[237] . '
|
|