punbb/admin_maintenance.php
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
--- a/punbb/admin_maintenance.php	Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_maintenance.php	Thu Jul 12 01:04:01 2007 -0400
@@ -28,12 +28,15 @@
 // Tell common.php that we don't want output buffering
 define('PUN_DISABLE_BUFFERING', 1);
 
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
+
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
 require PUN_ROOT.'include/common_admin.php';
 
 
-if ($pun_user['g_id'] > PUN_ADMIN)
+if ($pun_user['g_id'] < PUN_ADMIN)
 	message($lang_common['No permission']);
 
 
@@ -53,19 +56,19 @@
 		confirm_referrer('admin_maintenance.php');
 
 		$truncate_sql = ($db_type != 'sqlite' && $db_type != 'pgsql') ? 'TRUNCATE TABLE ' : 'DELETE FROM ';
-		$db->query($truncate_sql.$db->prefix.'search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error());
-		$db->query($truncate_sql.$db->prefix.'search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error());
+		$pun_db->query($truncate_sql.$pun_db->prefix.'search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $pun_db->error());
+		$pun_db->query($truncate_sql.$pun_db->prefix.'search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $pun_db->error());
 
 		// Reset the sequence for the search words (not needed for SQLite)
 		switch ($db_type)
 		{
 			case 'mysql':
 			case 'mysqli':
-				$result = $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error());
+				$result = $pun_db->query('ALTER TABLE '.$pun_db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $pun_db->error());
 				break;
 
 			case 'pgsql';
-				$result = $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error());
+				$result = $pun_db->query('SELECT setval(\''.$pun_db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $pun_db->error());
 		}
 	}
 
@@ -95,16 +98,16 @@
 	require PUN_ROOT.'include/search_idx.php';
 
 	// Fetch posts to process
-	$result = $db->query('SELECT DISTINCT t.id, p.id, p.message FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id WHERE t.id>='.$start_at.' AND t.id<'.$end_at.' ORDER BY t.id') or error('Unable to fetch topic/post info', __FILE__, __LINE__, $db->error());
+	$result = $pun_db->query('SELECT DISTINCT t.id, p.id, p.message FROM '.$pun_db->prefix.'topics AS t INNER JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id WHERE t.id>='.$start_at.' AND t.id<'.$end_at.' ORDER BY t.id') or error('Unable to fetch topic/post info', __FILE__, __LINE__, $pun_db->error());
 
 	$cur_topic = 0;
-	while ($cur_post = $db->fetch_row($result))
+	while ($cur_post = $pun_db->fetch_row($result))
 	{
 		if ($cur_post[0] <> $cur_topic)
 		{
 			// Fetch subject and ID of first post in topic
-			$result2 = $db->query('SELECT p.id, t.subject, MIN(p.posted) AS first FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE t.id='.$cur_post[0].' GROUP BY p.id, t.subject ORDER BY first LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
-			list($first_post, $subject) = $db->fetch_row($result2);
+			$result2 = $pun_db->query('SELECT p.id, t.subject, MIN(p.posted) AS first FROM '.$pun_db->prefix.'posts AS p INNER JOIN '.$pun_db->prefix.'topics AS t ON t.id=p.topic_id WHERE t.id='.$cur_post[0].' GROUP BY p.id, t.subject ORDER BY first LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error());
+			list($first_post, $subject) = $pun_db->fetch_row($result2);
 
 			$cur_topic = $cur_post[0];
 		}
@@ -118,21 +121,21 @@
 	}
 
 	// Check if there is more work to do
-	$result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE id>'.$end_at) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
+	$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'topics WHERE id>'.$end_at) or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error());
 
-	$query_str = ($db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$end_at : '';
+	$query_str = ($pun_db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$end_at : '';
 
-	$db->end_transaction();
-	$db->close();
+	$pun_db->end_transaction();
+	$pun_db->close();
 
 	exit('<script type="text/javascript">window.location="admin_maintenance.php'.$query_str.'"</script><br />JavaScript redirect unsuccessful. Click <a href="admin_maintenance.php'.$query_str.'">here</a> to continue.');
 }
 
 
 // Get the first post ID from the db
-$result = $db->query('SELECT id FROM '.$db->prefix.'topics ORDER BY id LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
-if ($db->num_rows($result))
-	$first_id = $db->result($result);
+$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'topics ORDER BY id LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error());
+if ($pun_db->num_rows($result))
+	$first_id = $pun_db->result($result);
 
 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Maintenance';
 require PUN_ROOT.'header.php';