Skip to content

Commit

Permalink
Vanilla fixes, and improved UTF-8 handling (#270)
Browse files Browse the repository at this point in the history
* Vanilla fixes, and improved UTF-8 handling.

* Handle private messages with no contributors

* Handle S3 avatars as URL based avatars instead of trying to download them.

* Exclude conversations with empty contributors.

* Fix debug log logic.
  • Loading branch information
euantorano authored Mar 16, 2021
1 parent 2a478c2 commit 21175e3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
18 changes: 15 additions & 3 deletions boards/vanilla/avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function import()

function convert_data($data)
{
global $import_session;
global $mybb, $import_session;

$insert_data = array();

Expand All @@ -49,8 +49,20 @@ function convert_data($data)
$insert_data['avatar'] = $this->get_upload_avatar_name($insert_data['uid'], $data['Photo']);
$insert_data['avatartype'] = AVATAR_TYPE_UPLOAD;

$img_size = getimagesize($import_session['avatarspath'].$this->generate_raw_filename($data));
$insert_data['avatardimensions'] = "{$img_size[1]}|{$img_size[0]}";
if (stripos($data['Photo'], 's3://') === 0) {
$insert_data['avatartype'] = AVATAR_TYPE_URL;
$insert_data['avatar'] = $data['Photo'];

if(!$mybb->settings['maxavatardims'])
{
$mybb->settings['maxavatardims'] = '100x100'; // Hard limit of 100 if there are no limits
}
list($maxwidth, $maxheight) = explode("x", my_strtolower($mybb->settings['maxavatardims']));
$insert_data['avatardimensions'] = "{$maxheight}|{$maxwidth}";
} else {
$img_size = getimagesize($import_session['avatarspath'].$this->generate_raw_filename($data));
$insert_data['avatardimensions'] = "{$img_size[1]}|{$img_size[0]}";
}

return $insert_data;
}
Expand Down
2 changes: 1 addition & 1 deletion boards/vanilla/forums.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function cleanup()
$query = $db->query("
SELECT f.fid, f2.fid as updatefid, f.import_fid
FROM ".TABLE_PREFIX."forums f
LEFT JOIN ".TABLE_PREFIX."forums f2 ON (f2.import_fid=f.import_pid)
INNER JOIN ".TABLE_PREFIX."forums f2 ON (f2.import_fid=f.import_pid)
WHERE f.import_pid != 0 AND f.pid = 0
");
while($forum = $db->fetch_array($query))
Expand Down
8 changes: 6 additions & 2 deletions boards/vanilla/privatemessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function import()

$query = $this->old_db->query("SELECT m.*, pm.Subject, pm.Contributors AS recips
FROM ".OLD_TABLE_PREFIX."conversationmessage m
LEFT JOIN ".OLD_TABLE_PREFIX."conversation pm ON(pm.ConversationID=m.ConversationID)
INNER JOIN ".OLD_TABLE_PREFIX."conversation pm ON(pm.ConversationID=m.ConversationID)
WHERE pm.Contributors <> '' AND pm.Contributors IS NOT NULL
LIMIT {$this->trackers['start_privatemessages']}, {$import_session['privatemessages_per_screen']}");
while($privatemessage = $this->old_db->fetch_array($query))
{
Expand Down Expand Up @@ -143,7 +144,10 @@ function fetch_total()
// Get number of private messages
if(!isset($import_session['total_privatemessages']))
{
$query = $this->old_db->simple_select("conversationmessage", "COUNT(*) as count");
$query = $this->old_db->query("SELECT COUNT(*) AS count
FROM ".OLD_TABLE_PREFIX."conversationmessage m
INNER JOIN ".OLD_TABLE_PREFIX."conversation pm ON(pm.ConversationID=m.ConversationID)
WHERE pm.Contributors <> '' AND pm.Contributors IS NOT NULL");
$import_session['total_privatemessages'] = $this->old_db->fetch_field($query, 'count');
$this->old_db->free_result($query);
}
Expand Down
15 changes: 14 additions & 1 deletion resources/class_debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,20 @@ private function write($type, $message)
// This looks ugly and it is, but otherwise we'll produce SQL errors...
if(strlen($log_insert['message']) > 65535)
{
$log_insert['message'] = substr($log_insert['message'], 0, 65531)."...";
$log_insert['message'] = substr($log_insert['message'], 0, 65531);

// check that the content is valid UTF-8 - we may have sliced part-way into a unicode codepoint
if (!preg_match('//u', $log_insert['message'])) {
if (function_exists('mb_convert_encoding')) {
$log_insert['message'] = mb_convert_encoding($log_insert['message'], 'UTF-8', 'UTF-8');
} else {
while (!empty($log_insert['message']) && !preg_match('//u', $log_insert['message'])) {
$log_insert['message'] = substr($log_insert['message'], 0, strlen($log_insert['message']) - 1);
}
}
}

$log_insert['message'] .= "...";
}

// If we caused an error and the message we're trying to insert isn't the SQL error we'll skip the message
Expand Down

0 comments on commit 21175e3

Please sign in to comment.