Skip to content

Commit

Permalink
Merge pull request #101 from Spuds/updates
Browse files Browse the repository at this point in the history
Additional updates and fixes
  • Loading branch information
eurich committed Feb 6, 2016
2 parents 8c4a5f6 + be056a8 commit d5eaf64
Show file tree
Hide file tree
Showing 23 changed files with 796 additions and 166 deletions.
66 changes: 43 additions & 23 deletions importer/Importers/SmfCommonSource.php
Expand Up @@ -230,7 +230,7 @@ public function specialAttachments($force = false)
$this->db->free_result($result);

if (empty($this->avatarUploadDir))
$this->avatarUploadDir = null;
$this->avatarUploadDir = '';

if (empty($this->id_attach))
$this->id_attach = 1;
Expand Down Expand Up @@ -353,7 +353,6 @@ public function removeAttachments()
*/
protected function createAttachFoldersStructure($folders)
{

$source_base = $this->guessBase($folders);
$destination_base = $this->guessBase($this->config->destination->getAllAttachDirs());

Expand Down Expand Up @@ -528,10 +527,10 @@ public function substep1()
$to_prefix = $this->config->to_prefix;

$request = $this->db->query("
SELECT id_board, MAX(id_msg) AS id_last_msg, MAX(modified_time) AS last_edited
SELECT
id_board, MAX(id_msg) AS id_last_msg, MAX(modified_time) AS last_edited
FROM {$to_prefix}messages
GROUP BY id_board");

$modifyData = array();
$modifyMsg = array();
while ($row = $this->db->fetch_assoc($request))
Expand Down Expand Up @@ -607,7 +606,8 @@ public function substep2()
$to_prefix = $this->config->to_prefix;

$request = $this->db->query("
SELECT id_group
SELECT
id_group
FROM {$to_prefix}membergroups
WHERE min_posts = -1");

Expand All @@ -617,7 +617,8 @@ public function substep2()
$this->db->free_result($request);

$request = $this->db->query("
SELECT id_board, member_groups
SELECT
id_board, member_groups
FROM {$to_prefix}boards
WHERE FIND_IN_SET(0, member_groups)");

Expand All @@ -629,20 +630,25 @@ public function substep2()
$this->db->free_result($request);
}

/**
* Fix various system totals
*/
public function substep3()
{
$to_prefix = $this->config->to_prefix;

// Get the number of messages...
$result = $this->db->query("
SELECT COUNT(*) AS totalMessages, MAX(id_msg) AS maxMsgID
SELECT
COUNT(*) AS totalMessages, MAX(id_msg) AS maxMsgID
FROM {$to_prefix}messages");
$row = $this->db->fetch_assoc($result);
$this->db->free_result($result);

// Update the latest member. (Highest ID_MEMBER)
$result = $this->db->query("
SELECT id_member AS latestMember, real_name AS latestreal_name
SELECT
id_member AS latestMember, real_name AS latestreal_name
FROM {$to_prefix}members
ORDER BY id_member DESC
LIMIT 1");
Expand All @@ -660,14 +666,16 @@ public function substep3()

// Update the member count.
$result = $this->db->query("
SELECT COUNT(*) AS totalMembers
SELECT
COUNT(*) AS totalMembers
FROM {$to_prefix}members");
$row += $this->db->fetch_assoc($result);
$this->db->free_result($result);

// Get the number of topics.
$result = $this->db->query("
SELECT COUNT(*) AS totalTopics
SELECT
COUNT(*) AS totalTopics
FROM {$to_prefix}topics");
$row += $this->db->fetch_assoc($result);
$this->db->free_result($result);
Expand All @@ -692,7 +700,8 @@ public function substep4()
$to_prefix = $this->config->to_prefix;

$request = $this->db->query("
SELECT id_group, min_posts
SELECT
id_group, min_posts
FROM {$to_prefix}membergroups
WHERE min_posts != -1
ORDER BY min_posts DESC");
Expand Down Expand Up @@ -731,7 +740,8 @@ public function substep5()
$to_prefix = $this->config->to_prefix;

$result_topics = $this->db->query("
SELECT id_board, COUNT(*) as num_topics
SELECT
id_board, COUNT(*) as num_topics
FROM {$to_prefix}topics
GROUP BY id_board");

Expand All @@ -744,7 +754,8 @@ public function substep5()

// Find how many messages are in the board.
$result_posts = $this->db->query("
SELECT id_board, COUNT(*) as num_posts
SELECT
id_board, COUNT(*) as num_posts
FROM {$to_prefix}messages
GROUP BY id_board");

Expand All @@ -766,7 +777,8 @@ public function substep6()
while (true)
{
$resultTopic = $this->db->query("
SELECT t.id_topic, COUNT(m.id_msg) AS num_msg
SELECT
t.id_topic, COUNT(m.id_msg) AS num_msg
FROM {$to_prefix}topics AS t
LEFT JOIN {$to_prefix}messages AS m ON (m.id_topic = t.id_topic)
GROUP BY t.id_topic
Expand Down Expand Up @@ -845,9 +857,8 @@ public function substep7()
/**
*
* Get the id_member associated with the specified message.
* @global type $to_prefix
* @global type $db
* @param type $messageID
*
* @param int $messageID
* @return int
*/
protected function getMsgMemberID($messageID)
Expand All @@ -856,7 +867,8 @@ protected function getMsgMemberID($messageID)

// Find the topic and make sure the member still exists.
$result = $this->db->query("
SELECT IFNULL(mem.id_member, 0)
SELECT
IFNULL(mem.id_member, 0)
FROM {$to_prefix}messages AS m
LEFT JOIN {$to_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_msg = " . (int) $messageID . "
Expand All @@ -882,7 +894,8 @@ public function substep8()

// First, let's get an array of boards and parents.
$request = $this->db->query("
SELECT id_board, id_parent, id_cat
SELECT
id_board, id_parent, id_cat
FROM {$to_prefix}boards");

$child_map = array();
Expand Down Expand Up @@ -952,7 +965,8 @@ protected function fixInexistentCategories($cat_map)

// Last check: any boards not in a good category?
$request = $this->db->query("
SELECT id_cat
SELECT
id_cat
FROM {$to_prefix}categories");
$real_cats = array();
while ($row = $this->db->fetch_assoc($request))
Expand Down Expand Up @@ -986,7 +1000,8 @@ public function substep9()
$to_prefix = $this->config->to_prefix;

$request = $this->db->query("
SELECT c.id_cat, c.cat_order, b.id_board, b.board_order
SELECT
c.id_cat, c.cat_order, b.id_board, b.board_order
FROM {$to_prefix}categories AS c
LEFT JOIN {$to_prefix}boards AS b ON (b.id_cat = c.id_cat)
ORDER BY c.cat_order, b.child_level, b.board_order, b.id_board");
Expand All @@ -1011,20 +1026,25 @@ public function substep9()
$this->db->free_result($request);
}

/**
* Fix attachment size, W & H values
*/
public function substep11()
{
$to_prefix = $this->config->to_prefix;

$request = $this->db->query("
SELECT COUNT(*)
SELECT
COUNT(*)
FROM {$to_prefix}attachments");
list ($attachments) = $this->db->fetch_row($request);
$this->db->free_result($request);

while ($_REQUEST['start'] < $attachments)
{
$request = $this->db->query("
SELECT id_attach, filename, attachment_type, id_folder
SELECT
id_attach, filename, attachment_type, id_folder
FROM {$to_prefix}attachments
WHERE id_thumb = 0
AND (RIGHT(filename, 4) IN ('.gif', '.jpg', '.png', '.bmp') OR RIGHT(filename, 5) = '.jpeg')
Expand Down
6 changes: 3 additions & 3 deletions importer/Importers/elkarte1.0/UBB75_importer.xml
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<importer xmlns="http://www.elkarte.net/xml/importer" xmlns:smf="http://www.elkarte.net/">
<importer xmlns="http://www.elkarte.net/xml/importer" xmlns:elkarte="http://www.elkarte.net/">
<general>
<name>UBB Threads 7.5.x</name>
<version>ElkArte 1.0</version>
Expand Down Expand Up @@ -73,7 +73,7 @@
SELECT
FORUM_ID AS id_board, CATEGORY_ID as id_cat, SUBSTRING(FORUM_TITLE, 1, 255) AS name,
SUBSTRING(FORUM_DESCRIPTION, 1, 65534) AS description, FORUM_SORT_ORDER AS board_order,
FORUM_POSTS AS num_posts, IFNULL(FORUM_PARENT, 0) as id_parent, FORUM_POSTS_COUNT AS count_posts,
FORUM_POSTS AS num_posts, IFNULL(FORUM_PARENT, 0) as id_parent, FORUM_POSTS_COUNT AS count_posts,
'' AS member_groups
FROM {$from_prefix}FORUMS;
</query>
Expand Down Expand Up @@ -331,7 +331,7 @@
copy_smileys($smf_smileys_dir, $smileys_dir);
</code>
</step>

<step>
<title>Importing statistics (activity log)</title>
<detect>{$from_prefix}log_activity</detect>
Expand Down
27 changes: 22 additions & 5 deletions importer/Importers/elkarte1.0/elkarte1.0_importer.php
Expand Up @@ -39,13 +39,17 @@ class elkarte1_0_importer_step1 extends Importers\SmfCommonSourceStep1

class elkarte1_0_importer_step2 extends Importers\SmfCommonSourceStep2
{
/**
* Repair any wrong number of personal messages
*/
public function substep0()
{
$to_prefix = $this->config->to_prefix;

// Get all members with wrong number of personal messages and fix it
$request = $this->db->query("
SELECT mem.id_member, COUNT(pmr.id_pm) AS real_num, mem.personal_messages
SELECT
mem.id_member, COUNT(pmr.id_pm) AS real_num, mem.personal_messages
FROM {$to_prefix}members AS mem
LEFT JOIN {$to_prefix}pm_recipients AS pmr ON (mem.id_member = pmr.id_member AND pmr.deleted = 0)
GROUP BY mem.id_member
Expand All @@ -63,7 +67,8 @@ public function substep0()
$this->db->free_result($request);

$request = $this->db->query("
SELECT mem.id_member, COUNT(pmr.id_pm) AS real_num, mem.unread_messages
SELECT
mem.id_member, COUNT(pmr.id_pm) AS real_num, mem.unread_messages
FROM {$to_prefix}members AS mem
LEFT JOIN {$to_prefix}pm_recipients AS pmr ON (mem.id_member = pmr.id_member AND pmr.deleted = 0 AND pmr.is_read = 0)
GROUP BY mem.id_member
Expand All @@ -81,13 +86,17 @@ public function substep0()
$this->db->free_result($request);
}

/**
* Count the topic likes based on first message id
*/
public function substep100()
{
$to_prefix = $this->config->to_prefix;

// Set the number of topic likes based on likes to the first message in the topic
$request = $this->db->query("
SELECT COUNT(*) AS count, t.id_topic
SELECT
COUNT(*) AS count, t.id_topic
FROM {$to_prefix}message_likes AS ml
INNER JOIN {$to_prefix}topics AS t ON (t.id_first_msg = ml.id_msg)
GROUP BY t.id_topic");
Expand All @@ -104,13 +113,17 @@ public function substep100()
$this->db->free_result($request);
}

/**
* Validate / Update member likes received
*/
public function substep101()
{
$to_prefix = $this->config->to_prefix;

// Update the likes each member has received based on liked messages
$request = $this->db->query("
SELECT COUNT(*) AS count, id_poster
SELECT
COUNT(*) AS count, id_poster
FROM {$to_prefix}message_likes
GROUP BY id_poster");
while ($row = $this->db->fetch_assoc($request))
Expand All @@ -126,13 +139,17 @@ public function substep101()
$this->db->free_result($request);
}

/**
* Validate / Update likes given by a member
*/
public function substep102()
{
$to_prefix = $this->config->to_prefix;

// Update the likes each member has given
$request = $this->db->query("
SELECT COUNT(*) AS count, id_member
SELECT
COUNT(*) AS count, id_member
FROM {$to_prefix}message_likes
GROUP BY id_member");
while ($row = $this->db->fetch_assoc($request))
Expand Down
60 changes: 60 additions & 0 deletions importer/Importers/elkarte1.0/mybb18_importer.php
Expand Up @@ -43,4 +43,64 @@ public function getTableTest()
{
return 'users';
}

/**
* Copy attachment files
*
* @param string g$dir
* @param array $row
* @param int $id_attach
* @param string $destination_path
* @param bool $thumb
*
* @return array
*/
public function mybb_copy_files($dir, $row, $id_attach, $destination_path, $thumb = false)
{
// Some extra details
list($ext, $basename, $mime_type) = attachment_type($row['filename']);

// Prepare for the copy
$file = $thumb ? $row['thumbnail'] : $row['attachname'];
$source = $dir . '/' . $file;
$file_hash = createAttachmentFileHash($file);
$destination = $destination_path . '/' . $id_attach . '_' . $file_hash . '.elk';
$width = 0;
$height = 0;
$type = 0;

// Copy it over
copy_file($source, $destination);

// If its an image, then make sure it has legit width/height
if (!empty($ext))
{
list ($width, $height) = getimagesize($destination);
if (empty($width))
{
$width = 0;
$height = 0;
}
else
{
$type = ($thumb) ? 3 : 0;
}
}

// Prepare our insert
return array(
'id_attach' => $id_attach,
'id_thumb' => !$thumb && !empty($row['thumbnail']) ? ++$id_attach : 0,
'size' => file_exists($destination) ? filesize($destination) : 0,
'filename' => $basename . '.' . ($thumb ? $ext . '_thumb' : $ext),
'file_hash' => $file_hash,
'file_ext' => $ext,
'mime_type' => $mime_type,
'attachment_type' => $type,
'id_msg' => $row['id_msg'],
'downloads' => $row['downloads'],
'width' => $width,
'height' => $height,
);
}
}

0 comments on commit d5eaf64

Please sign in to comment.