Skip to content

Instantly share code, notes, and snippets.

@prototech
Created March 28, 2013 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prototech/44fef7b36e58d3922554 to your computer and use it in GitHub Desktop.
Save prototech/44fef7b36e58d3922554 to your computer and use it in GitHub Desktop.
<?php
/**
*
* @package install
* @version $Id$
* @copyright (c) 2006 phpBB Group
* @copyright (c) 2013 prototech
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* NOTE to potential convertor authors. Please use this file to get
* familiar with the structure since we added some bare explanations here.
*
* Since this file gets included more than once on one page you are not able to add functions to it.
* Instead use a functions_ file.
*
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
include($phpbb_root_path . 'config.' . $phpEx);
unset($dbpasswd);
/**
* $convertor_data provides some basic information about this convertor which is
* used on the initial list of convertors and to populate the default settings
*/
$convertor_data = array(
'forum_name' => 'PunBB 1.4.x',
'version' => '0.0.4',
'phpbb_version' => '3.0.11',
'author' => '<a href="https://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=304651">prototech</a>',
'dbms' => $dbms,
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbuser' => $dbuser,
'dbpasswd' => '',
'dbname' => $dbname,
'table_prefix' => '',
'forum_path' => '../forums',
'author_notes' => '',
);
/**
* $tables is a list of the tables (minus prefix) which we expect to find in the
* source forum. It is used to guess the prefix if the specified prefix is incorrect
*/
$tables = array(
'bans',
'categories',
'censoring',
'config',
'extensions',
'extension_hooks',
'forums',
'forum_perms',
'forum_subscriptions',
'groups',
'online',
'posts',
'ranks',
'reports',
'search_cache',
'search_matches',
'search_words',
'subscriptions',
'topics',
'users'
);
/**
* $config_schema details how the board configuration information is stored in the source forum.
*
* 'table_format' can take the value 'file' to indicate a config file. In this case array_name
* is set to indicate the name of the array the config values are stored in
* Example of using a file:
* $config_schema = array(
* 'table_format' => 'file',
* 'filename' => 'NAME OF FILE', // If the file is not in the root directory, the path needs to be added with no leading slash
* 'array_name' => 'NAME OF ARRAY', // Only used if the configuration file stores the setting in an array.
* 'settings' => array(
* 'board_email' => 'SUPPORT_EMAIL', // target config name => source target name
* )
* );
* 'table_format' can be an array if the values are stored in a table which is an assosciative array
* (as per phpBB 2.0.x)
* If left empty, values are assumed to be stored in a table where each config setting is
* a column (as per phpBB 1.x)
*
* In either of the latter cases 'table_name' indicates the name of the table in the database
*
* 'settings' is an array which maps the name of the config directive in the source forum
* to the config directive in phpBB3. It can either be a direct mapping or use a function.
* Please note that the contents of the old config value are passed to the function, therefore
* an in-built function requiring the variable passed by reference is not able to be used. Since
* empty() is such a function we created the function is_empty() to be used instead.
*/
$config_schema = array(
'table_name' => 'config',
'table_format' => array('conf_name' => 'conf_value'),
'settings' => array(
)
);
/**
* $test_file is the name of a file which is present on the source
* forum which can be used to check that the path specified by the
* user was correct
*/
$test_file = 'userlist.php';
/**
* If this is set then we are not generating the first page of information but getting the conversion information.
*/
if (!$get_info)
{
// Check for some extensions
$sql = "SELECT id
FROM {$convert->src_table_prefix}extensions
WHERE disabled = 0
AND (id = 'pun_pm' OR id = 'pun_attachment')";
$result = $src_db->sql_query($sql);
$extensions = array();
while ($row = $src_db->sql_fetchrow($result))
{
$extensions[] = $row['id'];
}
$src_db->sql_freeresult($result);
@define('PM_ENABLED', in_array('pun_pm', $extensions));
@define('ATTACH_ENABLED', in_array('pun_attachment', $extensions));
// Overwrite maximum avatar width/height
@define('DEFAULT_AVATAR_X_CUSTOM', get_config_value('o_avatars_width'));
@define('DEFAULT_AVATAR_Y_CUSTOM', get_config_value('o_avatars_height'));
// additional table used only during conversion
@define('USERCONV_TABLE', $table_prefix . 'userconv');
/**
* Description on how to use the convertor framework.
*
* 'schema' Syntax Description
* -> 'target' => Target Table. If not specified the next table will be handled
* -> 'primary' => Primary Key. If this is specified then this table is processed in batches
* -> 'query_first' => array('target' or 'src', Query to execute before beginning the process
* (if more than one then specified as array))
* -> 'function_first' => Function to execute before beginning the process (if more than one then specified as array)
* (This is mostly useful if variables need to be given to the converting process)
* -> 'test_file' => This is not used at the moment but should be filled with a file from the old installation
*
* // DB Functions
* 'distinct' => Add DISTINCT to the select query
* 'where' => Add WHERE to the select query
* 'group_by' => Add GROUP BY to the select query
* 'left_join' => Add LEFT JOIN to the select query (if more than one joins specified as array)
* 'having' => Add HAVING to the select query
*
* // DB INSERT array
* This one consist of three parameters
* First Parameter:
* The key need to be filled within the target table
* If this is empty, the target table gets not assigned the source value
* Second Parameter:
* Source value. If the first parameter is specified, it will be assigned this value.
* If the first parameter is empty, this only gets added to the select query
* Third Parameter:
* Custom Function. Function to execute while storing source value into target table.
* The functions return value get stored.
* The function parameter consist of the value of the second parameter.
*
* types:
* - empty string == execute nothing
* - string == function to execute
* - array == complex execution instructions
*
* Complex execution instructions:
* @todo test complex execution instructions - in theory they will work fine
*
* By defining an array as the third parameter you are able to define some statements to be executed. The key
* is defining what to execute, numbers can be appended...
*
* 'function' => execute function
* 'execute' => run code, whereby all occurrences of {VALUE} get replaced by the last returned value.
* The result *must* be assigned/stored to {RESULT}.
* 'typecast' => typecast value
*
* The returned variables will be made always available to the next function to continue to work with.
*
* example (variable inputted is an integer of 1):
*
* array(
* 'function1' => 'increment_by_one', // returned variable is 2
* 'typecast' => 'string', // typecast variable to be a string
* 'execute' => '{RESULT} = {VALUE} . ' is good';', // returned variable is '2 is good'
* 'function2' => 'replace_good_with_bad', // returned variable is '2 is bad'
* ),
*
*/
$convertor = array(
'test_file' => 'moderate.php',
'avatar_path' => get_config_value('o_avatars_dir') . '/',
'smilies_path' => 'img/smilies/', // Smilies are hard-coded in the code
'upload_path' => 'extensions/pun_attachment/attachments/',
'thumbnails' => '',
// We empty some tables to have clean data available
'query_first' => array(
array('target', $convert->truncate_statement . PRIVMSGS_TABLE),
array('target', $convert->truncate_statement . PRIVMSGS_FOLDER_TABLE),
array('target', $convert->truncate_statement . PRIVMSGS_RULES_TABLE),
array('target', $convert->truncate_statement . PRIVMSGS_TO_TABLE),
),
// phpBB2 allowed some similar usernames to coexist which would have the same
// username_clean in phpBB3 which is not possible, so we'll give the admin a list
// of user ids and usernames and let him deicde what he wants to do with them
'schema' => array(
array(
'target' => (PM_ENABLED) ? PRIVMSGS_TABLE : '',
'primary' => 'pun_pm_messages.id',
'autoincrement' => 'msg_id',
'execute_first' => '
$config["max_post_chars"] = 0;
$config["min_post_chars"] = 0;
$config["max_quote_depth"] = 0;
',
array('msg_id', 'pun_pm_messages.id', ''),
array('root_level', 0, ''),
array('author_id', 'pun_pm_messages.sender_id AS poster_id', ''),
array('icon_id', 0, ''),
array('author_ip', '', ''),
array('message_time', 'pun_pm_messages.lastedited_at', ''),
array('enable_bbcode', 1, ''),
array('enable_smilies', 1, ''),
array('enable_magic_url', 1, ''),
array('enable_sig', 1, ''),
array('message_subject', 'pun_pm_messages.subject', 'punbb_htmlspecialchars'),
array('message_attachment', 0, ''),
array('message_edit_reason', '', ''),
array('message_edit_user', 0, ''),
array('message_edit_time', 0, ''),
array('message_edit_count', 0, ''),
array('bbcode_uid', 'pun_pm_messages.lastedited_at AS post_time', 'make_uid'),
array('', '0 AS hide_smilies', ''),
array('message_text', 'pun_pm_messages.body', 'punbb_prepare_message'),
array('bbcode_bitfield', '', 'get_bbcode_bitfield'),
array('to_address', 'pun_pm_messages.receiver_id', 'punbb_pm_to_user'),
array('bcc_address', '', ''),
),
array(
'target' => (PM_ENABLED) ? PRIVMSGS_FOLDER_TABLE : '',
'primary' => 'users.id',
array('user_id', 'users.id', ''),
array('folder_name', $user->lang['CONV_SAVED_MESSAGES'], ''),
array('pm_count', 0, ''),
'where' => 'users.id <> 1',
),
// Inbox
array(
'target' => (PM_ENABLED) ? PRIVMSGS_TO_TABLE : '',
'primary' => 'pun_pm_messages.id',
array('msg_id', 'pun_pm_messages.id', ''),
array('user_id', 'pun_pm_messages.receiver_id', ''),
array('author_id', 'pun_pm_messages.sender_id', ''),
array('pm_deleted', 0, ''),
array('pm_new', 'pun_pm_messages.read_at', 'is_empty'),
array('pm_unread', 'pun_pm_messages.read_at', 'is_empty'),
array('pm_replied', 0, ''),
array('pm_marked', 0, ''),
array('pm_forwarded', 0, ''),
array('folder_id', PRIVMSGS_INBOX, ''),
),
// Outbox
array(
'target' => (PM_ENABLED) ? PRIVMSGS_TO_TABLE : '',
'primary' => 'pun_pm_messages.id',
array('msg_id', 'pun_pm_messages.id', ''),
array('user_id', 'pun_pm_messages.sender_id', ''),
array('author_id', 'pun_pm_messages.sender_id', ''),
array('pm_deleted', 0, ''),
array('pm_new', 0, ''),
array('pm_unread', 0, ''),
array('pm_replied', 0, ''),
array('pm_marked', 0, ''),
array('pm_forwarded', 0, ''),
array('folder_id', PRIVMSGS_OUTBOX, ''),
'where' => 'pun_pm_messages.read_at = 0',
),
// Sentbox
array(
'target' => (PM_ENABLED) ? PRIVMSGS_TO_TABLE : '',
'primary' => 'pun_pm_messages.id',
array('msg_id', 'pun_pm_messages.id', ''),
array('user_id', 'pun_pm_messages.sender_id', ''),
array('author_id', 'pun_pm_messages.sender_id', ''),
array('pm_deleted', 0, ''),
array('pm_new', 0, ''),
array('pm_unread', 0, ''),
array('pm_replied', 0, ''),
array('pm_marked', 0, ''),
array('pm_forwarded', 0, ''),
array('folder_id', PRIVMSGS_SENTBOX, ''),
'where' => 'pun_pm_messages.read_at <> 0',
),
),
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment