diff options
Diffstat (limited to 'phpBB/develop')
-rw-r--r-- | phpBB/develop/create_schema_files.php | 41 | ||||
-rw-r--r-- | phpBB/develop/create_search_index.php | 137 |
2 files changed, 161 insertions, 17 deletions
diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index efe8837b26..7f37b94453 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -12,11 +12,7 @@ * If you overwrite the original schema files please make sure you save the file with UNIX linefeeds. */ -die("Please read the first lines of this script for instructions on how to enable it"); - -@set_time_limit(0); - -$schema_path = './../install/schemas/'; +$schema_path = dirname(__FILE__) . '/../install/schemas/'; if (!is_writable($schema_path)) { @@ -242,7 +238,7 @@ $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', ' foreach ($supported_dbms as $dbms) { - $fp = fopen($schema_path . '_' . $dbms . '_schema.sql', 'wt'); + $fp = fopen($schema_path . $dbms . '_schema.sql', 'wt'); $line = ''; @@ -251,32 +247,43 @@ foreach ($supported_dbms as $dbms) { case 'mysql_40': case 'mysql_41': - $line = "#\n# \$I" . "d: $\n#\n\n"; + case 'firebird': + case 'sqlite': + fwrite($fp, "# DO NOT EDIT THIS FILE, IT IS GENERATED\n"); + fwrite($fp, "#\n"); + fwrite($fp, "# To change the contents of this file, edit\n"); + fwrite($fp, "# phpBB/develop/create_schema_files.php and\n"); + fwrite($fp, "# run it.\n"); break; + case 'mssql': + case 'oracle': + case 'postgres': + fwrite($fp, "/*\n"); + fwrite($fp, " * DO NOT EDIT THIS FILE, IT IS GENERATED\n"); + fwrite($fp, " *\n"); + fwrite($fp, " * To change the contents of this file, edit\n"); + fwrite($fp, " * phpBB/develop/create_schema_files.php and\n"); + fwrite($fp, " * run it.\n"); + fwrite($fp, " */\n\n"); + break; + } + + switch ($dbms) + { case 'firebird': - $line = "#\n# \$I" . "d: $\n#\n\n"; $line .= custom_data('firebird') . "\n"; break; case 'sqlite': - $line = "#\n# \$I" . "d: $\n#\n\n"; $line .= "BEGIN TRANSACTION;\n\n"; break; - case 'mssql': - $line = "/*\n\n \$I" . "d: $\n\n*/\n\n"; - // no need to do this, no transaction support for schema changes - //$line .= "BEGIN TRANSACTION\nGO\n\n"; - break; - case 'oracle': - $line = "/*\n\n \$I" . "d: $\n\n*/\n\n"; $line .= custom_data('oracle') . "\n"; break; case 'postgres': - $line = "/*\n\n \$I" . "d: $\n\n*/\n\n"; $line .= "BEGIN;\n\n"; $line .= custom_data('postgres') . "\n"; break; diff --git a/phpBB/develop/create_search_index.php b/phpBB/develop/create_search_index.php new file mode 100644 index 0000000000..374a4cf0a1 --- /dev/null +++ b/phpBB/develop/create_search_index.php @@ -0,0 +1,137 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +if (php_sapi_name() != 'cli') +{ + die("This program must be run from the command line.\n"); +} + +if ($argc < 2) +{ + echo 'Usage: php ' . basename(__FILE__) . " index_type [batch_size]\n"; + exit(1); +} + +$class_name = basename($argv[1]); + +define('IN_PHPBB', true); +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../'; +$phpEx = substr(strrchr(__FILE__, '.'), 1); +require($phpbb_root_path . 'common.' . $phpEx); +require($phpbb_root_path . 'includes/acp/acp_search.' . $phpEx); +require($phpbb_root_path . 'includes/search/' . $class_name . '.' . $phpEx); + +$user->session_begin(); +$auth->acl($user->data); +$user->setup('acp/search'); + +$search_name = ucfirst(strtolower(str_replace('_', ' ', $class_name))); +$search_errors = array(); +$search = new $class_name($search_errors); + +$batch_size = isset($argv[2]) ? $argv[2] : 2000; +$time = time(); + +if (method_exists($search, 'create_index')) +{ + if ($error = $search->create_index(null, '')) + { + var_dump($error); + exit(1); + } +} +else +{ + $sql = 'SELECT forum_id, enable_indexing + FROM ' . FORUMS_TABLE; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $forums[$row['forum_id']] = (bool) $row['enable_indexing']; + } + $db->sql_freeresult($result); + + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + ORDER BY post_id DESC'; + $result = $db->sql_query_limit($sql, 1); + $max_post_id = (int) $db->sql_fetchfield('post_id'); + + $post_counter = 0; + while ($post_counter <= $max_post_id) + { + $row_count = 0; + + printf("Processing posts with %d <= post_id <= %d\n", + $post_counter + 1, + $post_counter + $batch_size + ); + + $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id + FROM ' . POSTS_TABLE . ' + WHERE post_id >= ' . (int) ($post_counter + 1) . ' + AND post_id <= ' . (int) ($post_counter + $batch_size); + $result = $db->sql_query($sql); + + $buffer = $db->sql_buffer_nested_transactions(); + + if ($buffer) + { + $rows = $db->sql_fetchrowset($result); + $rows[] = false; // indicate end of array for while loop below + + $db->sql_freeresult($result); + } + + $i = 0; + while ($row = ($buffer ? $rows[$i++] : $db->sql_fetchrow($result))) + { + // Indexing enabled for this forum or global announcement? + // Global announcements get indexed by default. + if (!$row['forum_id'] || !empty($forums[$row['forum_id']])) + { + ++$row_count; + + $search->index('post', + $row['post_id'], + $row['post_text'], + $row['post_subject'], + $row['poster_id'], + $row['forum_id'] + ); + + if ($row_count % 10 == 0) + { + echo '.'; + } + } + } + + $delta = (time() - $time); + $delta = $delta <= 0 ? 1 : $delta; + printf(" %d posts/sec\n", $row_count / $delta); + + if (!$buffer) + { + $db->sql_freeresult($result); + } + + $post_counter += $batch_size; + } +} + +$search->tidy(); + +add_log('admin', 'LOG_SEARCH_INDEX_CREATED', $search_name); + +echo $user->lang['SEARCH_INDEX_CREATED'] . "\n"; +echo 'Peak Memory Usage: ' . get_formatted_filesize(memory_get_peak_usage()) . "\n"; + +exit(0); |