aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorPaul S. Owen <psotfx@users.sourceforge.net>2001-09-01 16:08:24 +0000
committerPaul S. Owen <psotfx@users.sourceforge.net>2001-09-01 16:08:24 +0000
commitd48ebf9e048fcd581f73349a42c4ff9d55f24694 (patch)
tree65913f120166147b5cd63cc88f3458ccb056b847 /phpBB/includes/functions.php
parent0316d0a4902bcd9b3231c59a634cb37d4c028f1c (diff)
downloadforums-d48ebf9e048fcd581f73349a42c4ff9d55f24694.tar
forums-d48ebf9e048fcd581f73349a42c4ff9d55f24694.tar.gz
forums-d48ebf9e048fcd581f73349a42c4ff9d55f24694.tar.bz2
forums-d48ebf9e048fcd581f73349a42c4ff9d55f24694.tar.xz
forums-d48ebf9e048fcd581f73349a42c4ff9d55f24694.zip
Tidied up the sync functions
git-svn-id: file:///svn/phpbb/trunk@961 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php200
1 files changed, 100 insertions, 100 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 1b47e1a8f3..d283b8c07e 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -567,109 +567,109 @@ function validate_username($username)
function sync($type, $id)
{
global $db;
+
+ switch($type)
+ {
+ case 'all forums':
+ $sql = "SELECT forum_id
+ FROM " . FORUMS_TABLE;
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get forum IDs", "Error", __LINE__, __FILE__, $sql);
+ }
+ $rowset = $db->sql_fetchrowset($result);
+
+ for($i = 0; $i < count($rowset); $i++)
+ {
+ sync($row[$i]['forum_id'], "forum");
+ }
+ break;
+
+ case 'all topics':
+ $sql = "SELECT topic_id
+ FROM " . TOPICS_TABLE;
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get topic ID's", "Error", __LINE__, __FILE__, $sql);
+ }
+ $rowset = $db->sql_fetchrowset($result);
- switch($type)
- {
- case 'forum':
- $sql = "SELECT max(p.post_id) AS last_post FROM ".POSTS_TABLE." p, ".TOPICS_TABLE." t WHERE p.forum_id = $id AND p.topic_id = t.topic_id AND t.topic_status <> ".TOPIC_MOVED;
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not get post ID", "Error", __LINE__, __FILE__, $sql);
- }
- if($rowset = $db->sql_fetchrowset($result))
- {
- $last_post = $rowset[0]['last_post'];
- }
- if($last_post == "")
- {
- $last_post = 0;
- }
+ for($i = 0; $i < count($rowset); $i++)
+ {
+ sync($row[$i]['topic_id'], "topic");
+ }
+ break;
+
+ case 'forum':
+ $sql = "SELECT MAX(p.post_id) AS last_post
+ FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
+ WHERE p.forum_id = $id
+ AND p.topic_id = t.topic_id
+ AND t.topic_status <> " . TOPIC_MOVED;
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get post ID", "Error", __LINE__, __FILE__, $sql);
+ }
+ $last_post = ( $row = $db->sql_fetchrow($result) ) ? $row['last_post'] : 0;
+
+ $sql = "SELECT COUNT(post_id) AS total
+ FROM " . POSTS_TABLE . "
+ WHERE forum_id = $id";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get post count", "Error", __LINE__, __FILE__, $sql);
+ }
+ $total_posts = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
+
+ $sql = "SELECT COUNT(topic_id) AS total
+ FROM " . TOPICS_TABLE . "
+ WHERE forum_id = $id";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get topic count", "Error", __LINE__, __FILE__, $sql);
+ }
+ $total_topics = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
+
+ $sql = "UPDATE " . FORUMS_TABLE . "
+ SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
+ WHERE forum_id = $id";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not update forum $id", "Error", __LINE__, __FILE__, $sql);
+ }
+ break;
+
+ case 'topic':
+ $sql = "SELECT MAX(post_id) AS last_post
+ FROM " . POSTS_TABLE . "
+ WHERE topic_id = $id";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get post ID", "Error", __LINE__, __FILE__, $sql);
+ }
+ $last_post = ( $row = $db->sql_fetchrow($result) ) ? $row['last_post'] : 0;
+
+ $sql = "SELECT COUNT(post_id) AS total
+ FROM " . POSTS_TABLE . "
+ WHERE topic_id = $id";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not get post count", "Error", __LINE__, __FILE__, $sql);
+ }
+ $total_posts = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] - 1 : 0;
+
+ $sql = "UPDATE " . TOPICS_TABLE . "
+ SET topic_replies = $total_posts, topic_last_post_id = $last_post
+ WHERE topic_id = $id";
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Could not update topic $id", "Error", __LINE__, __FILE__, $sql);
+ }
+ break;
+ }
- $sql = "SELECT count(post_id) AS total FROM ".POSTS_TABLE." WHERE forum_id = $id";
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not get post count", "Error", __LINE__, __FILE__, $sql);
- }
- if($rowset = $db->sql_fetchrowset($result))
- {
- $total_posts = $rowset[0]['total'];
- }
-
- $sql = "SELECT count(topic_id) AS total FROM ".TOPICS_TABLE." WHERE forum_id = $id";
- if(!$result = $db->sql_query($sql, $db))
- {
- message_die(GENERAL_ERROR, "Could not get topic count", "Error", __LINE__, __FILE__, $sql);
- }
- if($rowset = $db->sql_fetchrowset($result))
- {
- $total_topics = $rowset[0]['total'];
- }
-
- $sql = "UPDATE ".FORUMS_TABLE." SET forum_last_post_id = '$last_post', forum_posts = $total_posts, forum_topics = $total_topics WHERE forum_id = $id";
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not update forum $id", "Error", __LINE__, __FILE__, $sql);
- }
- break;
-
- case 'topic':
- $sql = "SELECT max(post_id) AS last_post FROM ".POSTS_TABLE." WHERE topic_id = $id";
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not get post ID", "Error", __LINE__, __FILE__, $sql);
- }
- if($row = $db->sql_fetchrowset($result))
- {
- $last_post = $row[0]["last_post"];
- }
-
- $sql = "SELECT count(post_id) AS total FROM ".POSTS_TABLE." WHERE topic_id = $id";
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not get post count", "Error", __LINE__, __FILE__, $sql);
- }
- if($row = $db->sql_fetchrowset($result))
- {
- $total_posts = $row[0]["total"];
- }
- $total_posts -= 1;
- $sql = "UPDATE ".TOPICS_TABLE." SET topic_replies = $total_posts, topic_last_post_id = $last_post WHERE topic_id = $id";
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not update topic $id", "Error", __LINE__, __FILE__, $sql);
- }
- break;
-
- case 'all forums':
- $sql = "SELECT forum_id FROM ".FORUMS_TABLE;
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not get forum IDs", "Error", __LINE__, __FILE__, $sql);
- }
- $rowset = $db->sql_fetchrowset($result);
- $count = $db->sql_numrows($result);
- for($i = 0; $i < $count; $i++)
- {
- $id = $row[$i]['forum_id'];
- sync($db, $id, "forum");
- }
- break;
- case 'all topics':
- $sql = "SELECT topic_id FROM topics";
- if(!$result = $db->sql_query($sql))
- {
- message_die(GENERAL_ERROR, "Could not get topic ID's", "Error", __LINE__, __FILE__, $sql);
- }
- $rowset = $db->sql_fetchrowset($result);
- $count = $db->sql_numrows($result);
- for($i = 0; $i < $count; $i++)
- {
- $id = $row[$i]['topic_id'];
- sync($db, $id, "topic");
- }
- break;
- }
return(TRUE);
+
}
function language_select($default, $dirname="language/")