Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Import from U 232 V5

darkalchemy edited this page Sep 19, 2019 · 20 revisions

This script is intended to import a stock U-232 V5 database to a fully installed Pu-239 database.

Disable or remove cronjob running jobby.php prior to importing.

All users will have to reset their password and download any torrents they were seeding. Users can mass download torrents from userdetails.php.

In order for the user to reset their password, the user must have a valid email already in the database and your site must have valid email credentials in config.php.

To use this script, you will need to edit the first few lines. Both databases must exist and be populated, in the database. This script does not create any databases or read from any sql files. This script works solely with databases in the database already created. The user/pass below must have access to both databases.

All users will be imported as user class they were.

All users status will be set according to their current status, including enabled, parked or suspended.

All users email is automatically set to verified, else they would not be able to reset their password.

Save the file below as import_v5.php and run php import_v5.php. This will import most tables, but a few have been removed and others are too different to import.

<?php

$start = microtime(true);
$user = "Database Username";
$pass = "Database Password";
$pu239_db = "Pu-239 Database Name";
$u232v5_db = "U-232 V5 Database Name";
$host = "localhost";
$bot_id = 2; // must match the userid of your system bot
$limit = '1000'; // if mysql errors with max packet or similar, decrease this by 100 until the errors go away

if ($user === 'Database Username' || $pass === 'Database Password') {
    die("please edit this file\n");
}

$pdo = new PDO("mysql:host={$host};dbname={$pu239_db}", "$user", "$pass");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$pdo->setAttribute(PDO::ATTR_PERSISTENT, true);

$sql = "SHOW DATABASES LIKE '{$pu239_db}'";
$exists = $pdo->query($sql)
              ->fetchAll();
if (empty($exists)) {
    die($pu239_db . ' does not exist in the database. Please create and populate the database before using this script.');
}
$sql = "SHOW DATABASES LIKE '{$u232v5_db}'";
$exists = $pdo->query($sql)
              ->fetchAll();
if (empty($exists)) {
    die($u232v5_db . ' does not exist in the database. Please create and populate the database before using this script.');
}

$sql = "SET FOREIGN_KEY_CHECKS = 0;";
$pdo->exec($sql);

$tables = [
    'announcement_main',
    'attachments',
    'avps',
    'bans',
    'casino',
    'casino_bets',
    'cheaters',
    'class_promo',
    'countries',
    'happyhour',
    'happylog',
    'hit_and_run_settings',
    'infolog',
    'lottery_config',
    'modscredits',
    'moods',
    'notconnectablepmlog',
    'offer_votes',
    'over_forums',
    'pmboxes',
    'promo',
    'read_posts',
    'reports',
    'now_viewing',
    'shit_list',
    'reputationlevel',
    'subtitles',
    'tickets',
    'uploadapp',
    'files',
    'request_votes',
    'friends',
    'achievements',
    'funds',
    'thanks',
    'thankyou',
    'rating',
    'wiki',
    'subscriptions',
    'reputation',
    'freeleech',
    'freeslots',
    'bookmarks',
];

foreach ($tables as $table) {
    echo "Truncating '{$pu239_db}.{$table}' table\n";
    $sql = "TRUNCATE TABLE {$pu239_db}.{$table}";
    $pdo->exec($sql);

    echo "Populating '{$pu239_db}.{$table}' table\n";
    $sql = "INSERT INTO {$pu239_db}.{$table} SELECT * FROM {$u232v5_db}.{$table}";
    $pdo->exec($sql);

    compare_counts($table, 0);
}

echo "Truncating '{$pu239_db}.users' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.users";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.users' table\n";
$iter = get_count("{$u232v5_db}.users");
$bad = 0;
for ($x = 0; $x < $iter; $x++) {
    $values = $emails = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.users WHERE username != 'NULL' ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'ip',
            'snow',
            'pin_code',
            'ignore_list',
            'pm_forced',
            'forums_mod',
            'forum_mod',
            'altnick',
            'sidebar',
            'torrent_pass_version',
            'offavatar',
            'secret',
            'editsecret',
            'passkey',
            'show_shout',
            'show_staffshout',
            'shoutboxbg',
            'support_lang',
            'hash1',
            'uclass',
            'view_uclass',
            'passhash',
            'added',
            'av_w',
            'av_h',
            'enabled',
            'anonymous',
            'sig_w',
            'sig_h',
            'parked',
            'passhint',
            'hintanswer',
            'language_new',
            'ssluse',
            'google_talk',
            'msn',
            'aim',
            'yahoo',
            'icq',
            'suspended',
            'pm_on_delete',
            'split',
            'got_moods',
            'show_pm_avatar',
            'anonymous',
            'altnick',
            'snow',
            'seedbonus',
            'signature',
            'website',
            'time_offset',
            'birthday',
            'avatar',
            'gender',
        ];
        if (in_array($row['email'], $emails)) {
            $bad++;
            continue;
        }
        $emails[] = $row['email'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $status = $row['enabled'] === 'yes' ? 0 : 2;
        $status = $row['parked'] === 'yes' ? 1 : $status;
        $status = $row['suspended'] === 'yes' ? 5 : $status;
        $values[$i]['status'] = $status;
        $values[$i]['password'] = bin2hex(random_bytes(32));
        $values[$i]['torrent_pass'] = bin2hex(random_bytes(32));
        $values[$i]['auth'] = bin2hex(random_bytes(32));
        $values[$i]['apikey'] = bin2hex(random_bytes(32));
        $values[$i]['registered'] = $row['added'];
        $values[$i]['offensive_avatar'] = $row['offavatar'];
        $values[$i]['seedbonus'] = (float) $row['seedbonus'];
        $values[$i]['signature'] = empty($row['signature']) ? '' : $row['signature'];
        $values[$i]['website'] = empty($row['website']) ? '' : $row['website'];
        $values[$i]['time_offset'] = empty($row['time_offset']) ? 0 : str_replace("'", '', $row['time_offset']);
        $values[$i]['birthday'] = $row['birthday'] === '0000-00-00' ? '1970-01-01' : $row['birthday'];
        $values[$i]['avatar'] = empty($row['avatar']) ? '' : $row['avatar'];
        $values[$i]['gender'] = empty($row['gender']) ? 'NA' : $row['gender'];
        $values[$i]['stylesheet'] = 1;
        $values[$i]['verified'] = 1;
        $values[$i]['username'] = str_replace(' ', '_', trim($values[$i]['username']));
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.users (" . implode(', ', array_keys($values[0])) . ")", $values);
    unset($values);
}
compare_counts('users', $bad);

echo "Updating '{$pu239_db}.site_config' table\n";
$iter = get_count("{$u232v5_db}.site_config");
for ($x = 0; $x < $iter; $x++) {
    $sql = "SELECT * FROM {$u232v5_db}.site_config";
    foreach ($pdo->query($sql) as $row) {
        foreach ($row as $key => $value) {
            if ($key === 'bonus_per_duration') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_duration'";
            } elseif ($key === 'bonus_per_download') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_download'";
            } elseif ($key === 'bonus_per_comment') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_comment'";
            } elseif ($key === 'bonus_per_upload') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_upload'";
            } elseif ($key === 'bonus_per_rating') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_rating'";
            } elseif ($key === 'bonus_per_topic') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_topic'";
            } elseif ($key === 'bonus_per_post') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_post'";
            } elseif ($key === 'bonus_per_delete') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_delete'";
            } elseif ($key === 'bonus_per_thanks') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'per_thanks'";
            } elseif ($key === 'seedbonus_on') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'bonus' AND name = 'on'";
            } elseif ($key === 'autoshout_on') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'site' AND name = 'autoshout_chat'";
            } elseif ($key === 'openreg') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = " . ($value === 'true' ? 1 : 0) . " WHERE parent = 'openreg' AND name = 'open'";
            } elseif ($key === 'openreg_invites') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = " . ($value === 'true' ? 1 : 0) . " WHERE parent = 'openreg' AND name = 'invites_only'";
            } elseif ($key === 'ratio_free') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = " . ($value === 'true' ? 1 : 0) . " WHERE parent = 'site' AND name = 'ratio_free'";
            } elseif ($key === 'dupeip_check_on') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = " . ($value === 'true' ? 1 : 0) . " WHERE parent = 'signup' AND name = 'dupeip_check_on'";
            } elseif ($key === 'forums_online') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'forum_config' AND name = 'online'";
            } elseif ($key === 'maxusers') {
                $sqls[] = "UPDATE {$pu239_db}.site_config SET value = {$value} WHERE parent = 'site' AND name = 'maxusers'";
            }
        }
    }
    if (!empty($sqls)) {
        foreach ($sqls as $sql) {
            $pdo->exec($sql);
        }
    }
    $sql = "UPDATE {$pu239_db}.site_config SET value = {$bot_id} WHERE parent = 'chatbot' AND name = 'id'";
    $pdo->exec($sql);
    $sql = "SELECT username FROM {$pu239_db}.users WHERE id = {$bot_id}";
    $botname = $pdo->query($sql)
                   ->fetchColumn();
    $sql = "UPDATE {$pu239_db}.site_config SET value = '{$botname}' WHERE parent = 'chatbot' AND name = 'name'";
    $pdo->exec($sql);
}
echo "Updated '{$pu239_db}.site_config' table\n";

echo "Truncating '{$pu239_db}.ips' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.ips";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.ips' table\n";
$iter = get_count("{$u232v5_db}.ips");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.ips ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['id'];
        $merge = [
            'lastbrowse',
            'lastlogin',
            'lastannounce',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if (in_array($key, $merge)) {
                    $values[$i]['last_access'] = date("Y-m-d H:i:s", $value);
                } else {
                    $values[$i][$key] = $value;
                }
            }
        }
        $values[$i]['ip'] = '';
        if (filter_var($row['ip'], FILTER_VALIDATE_IP) !== false) {
            $values[$i]['ip'] = inet_pton($row['ip']);
        }
        $i++;
    }
    insertMultiple("INSERT IGNORE INTO {$pu239_db}.ips (" . implode(', ', array_keys($values[0])) . ")", $values);
    unset($values);
}
echo "Ignoring duplicate entries\n\n";

echo "Truncating '{$pu239_db}.forums' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.forums";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.forums' table\n";
$iter = get_count("{$u232v5_db}.forums");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.forums ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['place'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.forums (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('forums', 0);

echo "Truncating '{$pu239_db}.topics' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.topics";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.topics' table\n";
$iter = get_count("{$u232v5_db}.topics");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.topics ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['user_likes'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'anonymous') {
                    if ($value === 'yes') {
                        $values[$i][$key] = 1;
                    } else {
                        $values[$i][$key] = 0;
                    }
                } else {
                    $values[$i][$key] = $value;
                }
            }
        }
        $values[$i]['added'] = time();
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.topics (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('topics', 0);

echo "Truncating '{$pu239_db}.posts' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.posts";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.posts' table\n";
$iter = get_count("{$u232v5_db}.posts");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.posts ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'ip',
            'user_likes',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'anonymous') {
                    if ($value === 'yes') {
                        $values[$i][$key] = 1;
                    } else {
                        $values[$i][$key] = 0;
                    }
                } else {
                    $values[$i][$key] = $value;
                }
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.posts (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('posts', 0);

echo "Truncating '{$pu239_db}.torrents' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.torrents";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.torrents' table\n";
$iter = get_count("{$u232v5_db}.torrents");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT t.*, u.id AS checked_id FROM {$u232v5_db}.torrents AS t LEFT JOIN {$u232v5_db}.users AS u ON t.checked_by = u.id ORDER BY t.id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'user_likes',
            'temp_info_hash',
            'username',
            'type',
            'motw',
            'seedbox',
            'tf_points',
            'checked_by',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'last_action') {
                    $values[$i]['last_action'] = date("Y-m-d H:i:s", $value);
                } elseif ($key === 'checked_id') {
                    $value = empty($value) ? 0 : $value;
                    $values[$i]['checked_by'] = $value;
                } elseif ($key === 'anonymous') {
                    if ($value === 'yes') {
                        $values[$i][$key] = 1;
                    } else {
                        $values[$i][$key] = 0;
                    }
                } else {
                    $values[$i][$key] = $value;
                }
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.torrents (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('torrents', 0);

echo "Truncating '{$pu239_db}.ajax_chat_messages' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.ajax_chat_messages";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.ajax_chat_messages' table\n";
$iter = get_count("{$u232v5_db}.shoutbox");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT s.*, u.class, u.ip, u.username as userName FROM {$u232v5_db}.shoutbox AS s INNER JOIN {$u232v5_db}.users AS u ON u.id = s.userid WHERE s.to_user = 0 ORDER BY s.id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['ip'];
        foreach ($row as $key => $value) {
            $values[$i]['id'] = $row['id'];
            $values[$i]['userID'] = $row['userid'];
            $values[$i]['userName'] = $row['userName'];
            $values[$i]['userRole'] = $row['class'];
            $values[$i]['dateTime'] = date('Y-m-d G:i:s', $row['date']);
            $values[$i]['text'] = str_replace('#', '', $row['text']);
            $values[$i]['ttl'] = 0;
            $values[$i]['channel'] = 0;
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.ajax_chat_messages (" . implode(', ', array_keys($values[0])) . ")", $values);
}
echo "Ignoring private and staff messages\n\n";

echo "Truncating '{$pu239_db}.messages' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.messages";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.messages' table\n";
$iter = get_count("{$u232v5_db}.messages");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.messages ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['staff_id'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['sender'] = empty($value) ? $bot_id : $value;
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.messages (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('messages', 0);


echo "Truncating '{$pu239_db}.staffmessages' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.staffmessages";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.staffmessages' table\n";
$iter = get_count("{$u232v5_db}.staffmessages");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.staffmessages ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.staffmessages (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('staffmessages', 0);

echo "Truncating '{$pu239_db}.comments' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.comments";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.comments' table\n";
$iter = get_count("{$u232v5_db}.comments");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.comments ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'scheck',
            'edit_name',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'anonymous') {
                    if ($value === 'yes') {
                        $values[$i][$key] = 1;
                    } else {
                        $values[$i][$key] = 0;
                    }
                } elseif ($key === 'user_likes') {
                    $value = empty($value) ? 0 : $value;
                } else {
                    $values[$i][$key] = $value;
                }
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.comments (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('comments', 0);

echo "Truncating '{$pu239_db}.usercomments' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.usercomments";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.usercomments' table\n";
$iter = get_count("{$u232v5_db}.usercomments");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.usercomments ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'edit_name',
            'user_likes',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.usercomments (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('usercomments', 0);

echo "Truncating '{$pu239_db}.categories' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.categories";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.categories' table\n";
$iter = get_count("{$u232v5_db}.categories");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.categories ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'min_class',
            'parent_id',
            'tabletype',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.categories (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('categories', 0);

echo "Truncating '{$pu239_db}.usersachiev' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.usersachiev";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.usersachiev' table\n";
$iter = get_count("{$u232v5_db}.usersachiev");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.usersachiev ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['username'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'id') {
                    $key = 'userid';
                }
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.usersachiev (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('usersachiev', 0);

echo "Truncating '{$pu239_db}.user_blocks' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.user_blocks";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.user_blocks' table\n";
$iter = get_count("{$u232v5_db}.user_blocks");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.user_blocks ORDER BY userid LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'index_page') {
                    $value = 8323071;
                }
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.user_blocks (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('user_blocks', 0);

echo "Truncating '{$pu239_db}.bonuslog' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.bonuslog";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.bonuslog' table\n";
$iter = get_count("{$u232v5_db}.bonuslog");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.bonuslog ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['id'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['user_id'] = $row['id'];
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.bonuslog (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('bonuslog', 0);

echo "Truncating '{$pu239_db}.bugs' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.bugs";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.bugs' table\n";
$iter = get_count("{$u232v5_db}.bugs");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.bugs ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['comment'] = '';
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.bugs (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('bugs', 0);


echo "Truncating '{$pu239_db}.class_config' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.class_config";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.class_config' table\n";
$iter = get_count("{$u232v5_db}.class_config");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.class_config ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['template'] = 1;
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.class_config (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('class_config', 0);

echo "Truncating '{$pu239_db}.coins' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.coins";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.coins' table\n";
$iter = get_count("{$u232v5_db}.coins");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.coins ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['tf_points'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.coins (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('coins', 0);

echo "Truncating '{$pu239_db}.invite_codes' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.invite_codes";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.invite_codes' table\n";
$iter = get_count("{$u232v5_db}.invite_codes");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.invite_codes ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'invite_added',
            'receiver',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['added'] = $row['invite_added'];
        $values[$i]['receiver'] = empty($row['receiver']) ? 0 : $row['receiver'];
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.invite_codes (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('invite_codes', 0);

echo "Truncating '{$pu239_db}.news' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.news";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.news' table\n";
$iter = get_count("{$u232v5_db}.news");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.news ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                if ($key === 'anonymous') {
                    if ($value === 'yes') {
                        $values[$i][$key] = 1;
                    } else {
                        $values[$i][$key] = 0;
                    }
                } else {
                    $values[$i][$key] = $value;
                }
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.news (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('news', 0);

echo "Truncating '{$pu239_db}.referrers' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.referrers";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.referrers' table\n";
$iter = get_count("{$u232v5_db}.referrers");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.referrers ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['ip'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.referrers (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('referrers', 0);

echo "Truncating '{$pu239_db}.searchcloud' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.searchcloud";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.searchcloud' table\n";
$iter = get_count("{$u232v5_db}.searchcloud");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.searchcloud ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = ['ip'];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['search_column'] = 'name';
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.searchcloud (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('searchcloud', 0);

echo "Truncating '{$pu239_db}.offers' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.offers";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.offers' table\n";
$iter = get_count("{$u232v5_db}.offers");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.offers ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.offers (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('offers', 0);

echo "Truncating '{$pu239_db}.requests' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.requests";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.requests' table\n";
$iter = get_count("{$u232v5_db}.requests");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.requests ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.requests (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('requests', 0);

echo "Truncating '{$pu239_db}.snatched' table\n";
$sql = "TRUNCATE TABLE {$pu239_db}.snatched";
$pdo->exec($sql);

echo "Populating '{$pu239_db}.snatched' table\n";
$iter = get_count("{$u232v5_db}.snatched");
for ($x = 0; $x < $iter; $x++) {
    $values = [];
    $y = $x + 1;
    $a = $y === 1 ? 0 : ($x * $limit);
    $sql = "SELECT * FROM {$u232v5_db}.snatched ORDER BY id LIMIT $a, $limit";
    $i = 0;
    foreach ($pdo->query($sql) as $row) {
        $ignore = [
            'ip',
            'port',
            'connectable',
            'agent',
            'peer_id',
        ];
        foreach ($row as $key => $value) {
            if (!in_array($key, $ignore)) {
                $values[$i][$key] = $value;
            }
        }
        $values[$i]['real_uploaded'] = $row['uploaded'];
        $values[$i]['real_downloaded'] = $row['downloaded'];
        $i++;
    }
    insertMultiple("INSERT INTO {$pu239_db}.snatched (" . implode(', ', array_keys($values[0])) . ")", $values);
}
compare_counts('snatched', 0);

$sql = "SET FOREIGN_KEY_CHECKS = 1;";
$pdo->exec($sql);

$end = (microtime(true) - $start);
echo "Completed in " . gmdate("H:i:s", $end) . "\n\n";

/**
 * @param string $table
 * @param int    $ignored
 */
function compare_counts(string $table, int $ignored)
{
    global $u232v5_db, $pu239_db, $pdo;

    echo "Comparing table counts ";
    $users = $table === 'users' ? "WHERE username != 'NULL'" : '';

    $sql = "SELECT COUNT(*) FROM {$u232v5_db}.{$table} $users";
    $stmt1 = $pdo->query($sql)
                 ->fetchColumn();

    $sql = "SELECT COUNT(*) FROM {$pu239_db}.{$table} $users";
    $stmt2 = $pdo->query($sql)
                 ->fetchColumn();
    $stmt2 = $stmt2 + $ignored;
    if ((int) $stmt1 === (int) $stmt2) {
        echo "$stmt1 === $stmt2\n\n";
    } else {
        die("\n$stmt1 !== $stmt2\n");
    }
}


/**
 * @param string $query
 * @param array  $rows
 */
function insertMultiple(string $query, array $rows)
{
    global $pdo;
    if (count($rows) > 0) {
        $args = array_fill(0, count($rows[0]), '?');

        $params = [];
        foreach ($rows as $row) {
            $values[] = "(" . implode(',', $args) . ")";
            foreach ($row as $value) {
                $params[] = $value;
            }
        }

        $query = $query . " VALUES " . implode(',', $values);
        $stmt = $pdo->prepare($query);
        $stmt->execute($params);
    }
}

/**
 * @param string $table
 *
 * @return float
 */
function get_count(string $table)
{
    global $pdo, $limit;

    $sql = "SELECT COUNT(*) FROM {$table}";
    $count = $pdo->query($sql)
                 ->fetchColumn();
    return ceil($count / $limit);
}

After importing, you may need to copy images from your old site to the new site. You will need to copy torrent files to torrents/.

You should probably clear the cache by running php bin/clear_cache.php.

If the classes are different, at all, then you will also need to run php bin/uglify.php.

Reenable the cronjob for jobby.php.

Tables not imported: polls, poll_voters, announcement_process, events, likes, manage_likes, paypal_config, ustatus, userhits.

As Pu-239 is continually changing and improving, the database also changes. As of this writing it is current and is working. Should you have errors when you run this script, simply post a bug report and I will update it to work with the current Pu-239 database.