mirror of
https://github.com/e107inc/e107.git
synced 2025-08-04 13:47:31 +02:00
EONE-1 (Bug): More progress with forum upgrade routine.
This commit is contained in:
@@ -61,6 +61,7 @@ class forum_shortcodes
|
|||||||
{
|
{
|
||||||
if($this->postInfo['post_attachments'])
|
if($this->postInfo['post_attachments'])
|
||||||
{
|
{
|
||||||
|
$baseDir = e_MEDIA_ABS.'files/plugins/forum/attachments/';
|
||||||
$attachments = explode(',', $this->postInfo['post_attachments']);
|
$attachments = explode(',', $this->postInfo['post_attachments']);
|
||||||
$txt = '';
|
$txt = '';
|
||||||
foreach($attachments as $a)
|
foreach($attachments as $a)
|
||||||
@@ -69,18 +70,18 @@ class forum_shortcodes
|
|||||||
switch($info[0])
|
switch($info[0])
|
||||||
{
|
{
|
||||||
case 'file':
|
case 'file':
|
||||||
$txt .= IMAGE_attachment." <a href='".e_PLUGIN_ABS."forum/attachments/{$info[1]}'>{$info[2]}</a><br />";
|
$txt .= IMAGE_attachment." <a href='{$baseDir}{$info[1]}'>{$info[2]}</a><br />";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'img':
|
case 'img':
|
||||||
//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><br />";
|
$txt .= "<a href='{$baseDir}{$info[1]}'><img src='{$baseDir}thumb/{$info[2]}' alt='' /></a><br />";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$txt .= "<img src='".e_PLUGIN_ABS."forum/attachments/{$info[1]}' alt='' /><br />";
|
$txt .= "<img src='{$baseDir}{$info[1]}' alt='' /><br />";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -709,8 +709,13 @@ function step10()
|
|||||||
$postList[] = $row;
|
$postList[] = $row;
|
||||||
}
|
}
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
$pcount = 0;
|
||||||
|
$f->log("Found ".count($postList). " posts with attachments");
|
||||||
foreach($postList as $post)
|
foreach($postList as $post)
|
||||||
{
|
{
|
||||||
|
// echo htmlentities($post['post_entry'])."<br />";
|
||||||
|
$i++;
|
||||||
|
// if($pcount++ > 10) { die('here 10'); }
|
||||||
$attachments = array();
|
$attachments = array();
|
||||||
$foundFiles = array();
|
$foundFiles = array();
|
||||||
|
|
||||||
@@ -722,7 +727,6 @@ function step10()
|
|||||||
{
|
{
|
||||||
foreach($matches as $match)
|
foreach($matches as $match)
|
||||||
{
|
{
|
||||||
// print_a($matches);
|
|
||||||
$att = array();
|
$att = array();
|
||||||
$att['thread_id'] = $post['thread_id'];
|
$att['thread_id'] = $post['thread_id'];
|
||||||
$att['type'] = 'img';
|
$att['type'] = 'img';
|
||||||
@@ -735,6 +739,23 @@ function step10()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preg_match_all('#\[link=(.*?)\]\[img.*?\](\.\./\.\./e107_files/public/.*?)\[/img\]\[/link\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
|
||||||
|
{
|
||||||
|
foreach($matches as $match)
|
||||||
|
{
|
||||||
|
$att = array();
|
||||||
|
$att['thread_id'] = $post['thread_id'];
|
||||||
|
$att['type'] = 'img';
|
||||||
|
$att['html'] = $match[0];
|
||||||
|
$att['name'] = $match[1];
|
||||||
|
$att['thumb'] = $match[2];
|
||||||
|
$attachments[] = $att;
|
||||||
|
$foundFiles[] = $match[1];
|
||||||
|
$foundFiles[] = $match[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//<div class='spacer'>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div>
|
//<div class='spacer'>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div>
|
||||||
//Check for attached full-size images
|
//Check for attached full-size images
|
||||||
if(preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
|
if(preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
|
||||||
@@ -744,7 +765,6 @@ function step10()
|
|||||||
//Ensure it hasn't already been handled above
|
//Ensure it hasn't already been handled above
|
||||||
if(!in_array($match[1], $foundFiles))
|
if(!in_array($match[1], $foundFiles))
|
||||||
{
|
{
|
||||||
// print_a($matches);
|
|
||||||
$att = array();
|
$att = array();
|
||||||
$att['thread_id'] = $post['thread_id'];
|
$att['thread_id'] = $post['thread_id'];
|
||||||
$att['type'] = 'img';
|
$att['type'] = 'img';
|
||||||
@@ -756,6 +776,23 @@ function step10()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preg_match_all('#\[img.*?\](\.\./\.\./e107_files/public/.*?_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))
|
||||||
|
{
|
||||||
|
$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)
|
||||||
@@ -763,7 +800,20 @@ function step10()
|
|||||||
{
|
{
|
||||||
foreach($matches as $match)
|
foreach($matches as $match)
|
||||||
{
|
{
|
||||||
// print_a($matches);
|
$att = array();
|
||||||
|
$att['thread_id'] = $post['thread_id'];
|
||||||
|
$att['type'] = 'file';
|
||||||
|
$att['html'] = $match[0];
|
||||||
|
$att['name'] = $match[1];
|
||||||
|
$att['thumb'] = '';
|
||||||
|
$attachments[] = $att;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(preg_match_all('#\[file=(\.\./\.\./e107_files/public/.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
|
||||||
|
{
|
||||||
|
foreach($matches as $match)
|
||||||
|
{
|
||||||
$att = array();
|
$att = array();
|
||||||
$att['thread_id'] = $post['thread_id'];
|
$att['thread_id'] = $post['thread_id'];
|
||||||
$att['type'] = 'file';
|
$att['type'] = 'file';
|
||||||
@@ -776,21 +826,24 @@ function step10()
|
|||||||
|
|
||||||
if(count($attachments))
|
if(count($attachments))
|
||||||
{
|
{
|
||||||
|
$f->log("found ".count($attachments)." attachments");
|
||||||
$newValues = array();
|
$newValues = array();
|
||||||
$info = array();
|
$info = array();
|
||||||
$info['post_entry'] = $post['post_entry'];
|
$info['post_entry'] = $post['post_entry'];
|
||||||
foreach($attachments as $attachment)
|
foreach($attachments as $attachment)
|
||||||
{
|
{
|
||||||
$error = '';
|
$error = '';
|
||||||
if($f->moveAttachment($attachment, $error))
|
$f->log($attachment['name']);
|
||||||
|
if($f->moveAttachment($attachment, $post['post_id'], $error))
|
||||||
{
|
{
|
||||||
$_file = split('/', $attachment['name']);
|
$fInfo = pathinfo($attachment['name']);
|
||||||
$newval = $attachment['type'].'*'.$_file[1];
|
// $_file = split('/', $attachment['name']);
|
||||||
|
$newval = $attachment['type'].'*'.$fInfo['basename'];
|
||||||
switch($attachment['type'])
|
switch($attachment['type'])
|
||||||
{
|
{
|
||||||
//If file, add real name to entry
|
//If file, add real name to entry
|
||||||
case 'file':
|
case 'file':
|
||||||
$tmp = split('_', $_file[1], 4);
|
$tmp = split('_', $fInfo['basename'], 4);
|
||||||
$newval .= '*'.$tmp[3];
|
$newval .= '*'.$tmp[3];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -798,8 +851,8 @@ function step10()
|
|||||||
case 'img':
|
case 'img':
|
||||||
if($attachment['thumb'])
|
if($attachment['thumb'])
|
||||||
{
|
{
|
||||||
$_file = split('/', $attachment['thumb']);
|
$fInfo = pathinfo($attachment['thumb']);
|
||||||
$newval .= '*'.$_file[1];
|
$newval .= '*'.$fInfo['basename'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -811,9 +864,10 @@ function step10()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}<br />";
|
$errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}<br />";
|
||||||
|
$f->log("Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo $errorText."<br />";
|
// echo $errorText."<br />";
|
||||||
|
|
||||||
// Did we make any changes at all?
|
// Did we make any changes at all?
|
||||||
if(count($newValues))
|
if(count($newValues))
|
||||||
@@ -992,10 +1046,24 @@ class forumUpgrade
|
|||||||
var $newVersion = '2.0';
|
var $newVersion = '2.0';
|
||||||
var $error = array();
|
var $error = array();
|
||||||
public $updateInfo;
|
public $updateInfo;
|
||||||
|
private $attachmentData;
|
||||||
|
private $logf;
|
||||||
|
|
||||||
public function __initialize()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->updateInfo['lastThread'] = 0;
|
$this->updateInfo['lastThread'] = 0;
|
||||||
|
$this->attachmentData = array();
|
||||||
|
$this->logf = e_MEDIA.'files/forum_upgrade.txt';
|
||||||
|
$this->getUpdateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function log($msg, $append=true)
|
||||||
|
{
|
||||||
|
// echo "logf = ".$this->logf."<br />";
|
||||||
|
$txt = sprintf("%s - %s\n", date('m/d/Y H:i:s'), $msg);
|
||||||
|
// echo $txt."<br />";
|
||||||
|
$flag = ($append ? FILE_APPEND : '');
|
||||||
|
file_put_contents($this->logf, $txt, $flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkUpdateNeeded()
|
public function checkUpdateNeeded()
|
||||||
@@ -1005,23 +1073,18 @@ class forumUpgrade
|
|||||||
return !$needed;
|
return !$needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function forumUpgrade()
|
|
||||||
{
|
|
||||||
$this->getUpdateInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkAttachmentDirs()
|
function checkAttachmentDirs()
|
||||||
{
|
{
|
||||||
$dirs = array(
|
$dirs = array(
|
||||||
e_PLUGIN.'forum/attachments/',
|
e_MEDIA.'files/plugins/forum/attachments/',
|
||||||
e_PLUGIN.'forum/attachments/thumb'
|
e_MEDIA.'files/plugins/forum/attachments/thumb'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($dirs as $dir)
|
foreach($dirs as $dir)
|
||||||
{
|
{
|
||||||
if(!file_exists($dir))
|
if(!file_exists($dir))
|
||||||
{
|
{
|
||||||
if(!mkdir($dir))
|
if(!mkdir($dir, 0777, true))
|
||||||
{
|
{
|
||||||
$this->error['attach'][] = "Directory '{$dir}' does not exist and I was unable to create it";
|
$this->error['attach'][] = "Directory '{$dir}' does not exist and I was unable to create it";
|
||||||
}
|
}
|
||||||
@@ -1198,21 +1261,45 @@ class forumUpgrade
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveAttachment($attachment, &$error)
|
function moveAttachment($attachment, $post_id, &$error)
|
||||||
{
|
{
|
||||||
set_time_limit(30);
|
set_time_limit(30);
|
||||||
$tmp = split('/', $attachment['name']);
|
// $tmp = split('/', $attachment['name']);
|
||||||
|
$attachment['name'] = str_replace(array(' ', "\n", "\r"), '', $attachment['name']);
|
||||||
$old = str_replace('{e_FILE}', e_FILE, $attachment['name']);
|
$old = str_replace('{e_FILE}', e_FILE, $attachment['name']);
|
||||||
$new = e_PLUGIN.'forum/attachments/'.$tmp[1];
|
$fileInfo = pathinfo($attachment['name']);
|
||||||
|
$new = e_MEDIA.'files/plugins/forum/attachments/'.$fileInfo['basename'];
|
||||||
|
$hash = md5($new);
|
||||||
|
if(!file_exists($old))
|
||||||
|
{
|
||||||
|
if(isset($this->attachmentData[$hash]))
|
||||||
|
{
|
||||||
|
$error = "Post {$post_id} - Attachment already migrated with post: ".$this->attachmentData[$hash];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$error = 'Original attachment not found (orphaned?)';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if(!file_exists($new))
|
if(!file_exists($new))
|
||||||
{
|
{
|
||||||
|
$this->log("Copying [{$old}] -> [{$new}]");
|
||||||
$r = copy($old, $new);
|
$r = copy($old, $new);
|
||||||
|
$this->attachmentData[$hash] = $post_id;
|
||||||
// $r = true;
|
// $r = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//File already exists, show some sort of error
|
//File already exists, show some sort of error
|
||||||
|
if(isset($this->attachmentData[$hash]))
|
||||||
|
{
|
||||||
|
$error = "Post {$post_id} - Attachment already migrated with post: ".$this->attachmentData[$hash];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$error = 'Attachment file already exists';
|
$error = 'Attachment file already exists';
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!$r)
|
if(!$r)
|
||||||
@@ -1226,8 +1313,12 @@ class forumUpgrade
|
|||||||
if($attachment['thumb'])
|
if($attachment['thumb'])
|
||||||
{
|
{
|
||||||
$tmp = split('/', $attachment['thumb']);
|
$tmp = split('/', $attachment['thumb']);
|
||||||
|
$fileInfo = pathinfo($attachment['thumb']);
|
||||||
|
|
||||||
$oldThumb = str_replace('{e_FILE}', e_FILE, $attachment['thumb']);
|
$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];
|
||||||
|
$newThumb = e_MEDIA.'files/plugins/forum/attachments/thumb/'.$fileInfo['basename'];
|
||||||
|
$hash = md5($newThumb);
|
||||||
if(!file_exists($newThumb))
|
if(!file_exists($newThumb))
|
||||||
{
|
{
|
||||||
$r = copy($oldThumb, $newThumb);
|
$r = copy($oldThumb, $newThumb);
|
||||||
@@ -1236,7 +1327,14 @@ class forumUpgrade
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//File already exists, show some sort of error
|
//File already exists, show some sort of error
|
||||||
|
if(isset($this->attachmentData[$hash]))
|
||||||
|
{
|
||||||
|
$error = "Post {$post_id} - Thumb already migrated with post: ".$this->attachmentData[$hash];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$error = 'Thumb file already exists';
|
$error = 'Thumb file already exists';
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!$r)
|
if(!$r)
|
||||||
|
Reference in New Issue
Block a user