1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

EONE-1 (Bug): Attachment migration is hopefully fully working now.

This commit is contained in:
mcfly
2010-03-21 00:19:46 +00:00
parent b99a2ad06e
commit 3ddd1859c5
2 changed files with 57 additions and 30 deletions

View File

@@ -76,11 +76,11 @@ class forum_shortcodes
//if image has a thumb, show it and link to main //if image has a thumb, show it and link to main
if(isset($info[2])) if(isset($info[2]))
{ {
$txt .= "<a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'><img src='".e_PLUGIN_ABS."forum/attachments/thumb/{$info[2]}' alt='' /></a>"; $txt .= "<a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'><img src='".e_PLUGIN_ABS."forum/attachments/thumb/{$info[2]}' alt='' /></a><br />";
} }
else else
{ {
$txt .= "<img src='".e_PLUGIN_ABS."forum/attachments/{$info[1]}' alt='' />"; $txt .= "<img src='".e_PLUGIN_ABS."forum/attachments/{$info[1]}' alt='' /><br />";
} }
} }
} }

View File

@@ -32,6 +32,7 @@ if (!getperms('P'))
header('location:'.e_BASE.'index.php'); header('location:'.e_BASE.'index.php');
exit; exit;
} }
error_reporting(E_ALL);
require_once(e_PLUGIN.'forum/forum_class.php'); require_once(e_PLUGIN.'forum/forum_class.php');
require_once(e_ADMIN.'auth.php'); require_once(e_ADMIN.'auth.php');
$forum = new e107forum; $forum = new e107forum;
@@ -253,10 +254,12 @@ function step4()
$old_prefs = array(); $old_prefs = array();
foreach($pref as $k => $v) foreach($pref as $k => $v)
{ {
if(substr($key, 0, 6) == 'forum_') if(substr($k, 0, 6) == 'forum_')
{ {
$old_prefs[substr($key,6)] = $v; $nk = substr($k, 6);
$coreConfig->remove($key); echo "Converting $k to $nk<br />";
$old_prefs[$nk] = $v;
$coreConfig->remove($k);
} }
} }
$old_prefs['reported_post_email'] = $coreConfig->get('reported_post_email'); $old_prefs['reported_post_email'] = $coreConfig->get('reported_post_email');
@@ -466,6 +469,7 @@ function step6()
echo "error: Unable to determine last thread id"; echo "error: Unable to determine last thread id";
exit; exit;
} }
$done = false;
$qry = " $qry = "
SELECT thread_id FROM `#forum_t` SELECT thread_id FROM `#forum_t`
@@ -512,8 +516,16 @@ function step6()
"; ";
$e107->ns->tablerender($stepCaption, $text); $e107->ns->tablerender($stepCaption, $text);
} }
else
{
$done = true;
}
} }
else else
{
$done = true;
}
if($done)
{ {
$text .= " $text .= "
Thread migration is complete!! Thread migration is complete!!
@@ -701,22 +713,9 @@ function step10()
foreach($postList as $post) foreach($postList as $post)
{ {
$attachments = array(); $attachments = array();
//<div class=&#039;spacer&#039;>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div> $foundFiles = array();
//Check for attached full-size images
if(preg_match_all('#<div.*?>\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]</div>#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) // echo $post['post_entry']."<br /><br />";
{
foreach($matches as $match)
{
print_a($matches);
$att = array();
$att['thread_id'] = $post['thread_id'];
$att['type'] = 'img';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
//[link={e_FILE}public/1230091080_1_FT0_julia.jpg][img:width=60&height=45]{e_FILE}public/1230091080_1_FT0_julia_.jpg[/img][/link][br] //[link={e_FILE}public/1230091080_1_FT0_julia.jpg][img:width=60&height=45]{e_FILE}public/1230091080_1_FT0_julia_.jpg[/img][/link][br]
//Check for images with thumbnails linking to full size //Check for images with thumbnails linking to full size
@@ -732,9 +731,33 @@ function step10()
$att['name'] = $match[1]; $att['name'] = $match[1];
$att['thumb'] = $match[2]; $att['thumb'] = $match[2];
$attachments[] = $att; $attachments[] = $att;
$foundFiles[] = $match[1];
$foundFiles[] = $match[2];
} }
} }
//<div class=&#039;spacer&#039;>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div>
//Check for attached full-size images
if(preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
//Ensure it hasn't already been handled above
if(!in_array($match[1], $foundFiles))
{
// print_a($matches);
$att = array();
$att['thread_id'] = $post['thread_id'];
$att['type'] = 'img';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
}
//[file={e_FILE}public/1230090820_1_FT0_julia.zip]julia.zip[/file] //[file={e_FILE}public/1230090820_1_FT0_julia.zip]julia.zip[/file]
//Check for attached file (non-images) //Check for attached file (non-images)
if(preg_match_all('#\[file=({e_FILE}.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) if(preg_match_all('#\[file=({e_FILE}.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
@@ -751,12 +774,15 @@ function step10()
$attachments[] = $att; $attachments[] = $att;
} }
} }
if(count($attachments)) if(count($attachments))
{ {
$newValues = array(); $newValues = array();
$info = array(); $info = array();
$info['post_entry'] = $post['post_entry'];
foreach($attachments as $attachment) foreach($attachments as $attachment)
{ {
// var_dump($attachment);
$error = ''; $error = '';
if($f->moveAttachment($attachment, $error)) if($f->moveAttachment($attachment, $error))
{ {
@@ -769,26 +795,27 @@ function step10()
$newval .= '*'.$_file[1]; $newval .= '*'.$_file[1];
} }
$newValues[] = $newval; $newValues[] = $newval;
$info['post_entry'] = str_replace($attachment['html'], '', $post['post_entry']); // echo "Removing from post:".htmlentities($attachment['html'])."<br />";
$info['post_entry'] = str_replace($attachment['html'], '', $info['post_entry']);
} }
else else
{ {
$errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']}<br />{$error}<br />"; $errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']}<br />{$error}<br />";
} }
} }
echo $errorText."<br />";
// Did we make any changes at all? // Did we make any changes at all?
if(count($newValues)) if(count($newValues))
{ {
$info['WHERE'] = 'post_id = '.$post['post_id']; $info['WHERE'] = 'post_id = '.$post['post_id'];
$infot['post_attachments'] = implode(',', $newValues); $info['post_attachments'] = implode(',', $newValues);
$info['_FILE_TYPES']['post_attachments'] = 'escape'; // print_a($info);
$info['_FILE_TYPES']['post_entry'] = 'escape';
print_a($info);
} }
echo $post['thread_thread']."<br />"; // echo $post['thread_thread']."<br />";
// print_a($newValues); // print_a($newValues);
echo $info['newpost']."<br />--------------------------------------<br />"; // echo $info['newpost']."<br />--------------------------------------<br />";
$e107->sql->db_Update('forum_post', $info);
// Update db values now // Update db values now
} }
} }
@@ -1041,9 +1068,9 @@ class forumUpgrade
if($attachment['thumb']) if($attachment['thumb'])
{ {
$tmp = split('/', $attachment['thumb']); $tmp = split('/', $attachment['thumb']);
$oldThumb = str_replace('{e_FILE}', e_FILE, $attachments['thumb']).$tmp[1]; $oldThumb = str_replace('{e_FILE}', e_FILE, $attachment['thumb']);
$newThumb = e_PLUGIN.'forum/attachments/thumb/'.$tmp[1]; $newThumb = e_PLUGIN.'forum/attachments/thumb/'.$tmp[1];
if(!file_exists($new)) if(!file_exists($newThumb))
{ {
$r = copy($oldThumb, $newThumb); $r = copy($oldThumb, $newThumb);
// $r = true; // $r = true;