1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-22 13:41:52 +02:00

Better handling of duplicate images when importing submitted news.

This commit is contained in:
Cameron 2013-02-25 12:07:56 -08:00
parent d7b29d74c9
commit b3f6512e4b
2 changed files with 19 additions and 6 deletions
e107_admin
e107_handlers

@ -195,8 +195,8 @@ class news_sub_ui extends e_admin_ui
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'submitnews_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
'submitnews_title' => array('title'=> LAN_TITLE, 'type' => 'method', 'width' => '65%', 'thclass' => 'left', 'readonly'=>TRUE),
'submitnews_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'date', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
'submitnews_title' => array('title'=> LAN_TITLE, 'type' => 'method', 'width' => '35%', 'thclass' => 'left', 'readonly'=>TRUE),
'submitnews_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
'submitnews_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
// 'submitnews_item' => array('title'=> LAN_DESCRIPTION, 'type' => 'method', 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>TRUE),

@ -664,10 +664,10 @@ class e_media
{
$mes = e107::getMessage();
$tp = e107::getParser();
$f = e107::getFile()->get_file_info($oldpath,TRUE);
$sql = e107::getDb();
// $mes->addDebug("checkDupe(): newpath=".$newpath."<br />oldpath=".$oldpath."<br />".print_r($upload,TRUE));
if(file_exists($newpath) || e107::getDb()->db_Select("core_media","*","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
if(file_exists($newpath) && ($f = e107::getFile()->get_file_info($oldpath,TRUE)))
{
$this->log($newpath." already exists and will be renamed during import.");
$mes->addWarning($newpath." already exists and was renamed during import.");
@ -675,6 +675,14 @@ class e_media
$newpath = $this->getPath($f['mime']).'/'.$file;
}
if($sql->select("core_media","media_url","media_url LIKE '%".$tp->createConstants($newpath,'rel')."' LIMIT 1"))
{
// $mes->addWarning($newpath." detected in media-manager.");
$this->log("Import not performed. ".$newpath." detected in media table already.");
$row = $sql->fetch();
$newpath = $row['media_url'];
}
return $newpath;
}
@ -751,7 +759,7 @@ class e_media
public function log($message)
{
if($this->logging == false) return;
$insert = "\n".$message;
$insert = "\n\n".date('r')."\n".$message;
file_put_contents(e_LOG."mediaUpload.log",$insert,FILE_APPEND | LOCK_EX);
}
@ -769,8 +777,13 @@ class e_media
if(!file_exists($oldpath))
{
// Check it hasn't been imported already.
if($newpath = $this->checkDupe($oldpath, $file))
{
return $newpath;
}
$this->log("Line: ".__LINE__." Couldn't find the file: ".$oldpath);
$mes->add("Couldn't find the file: ".$oldpath, E_MESSAGE_ERROR);
$mes->addError("Couldn't find the file: ".$oldpath);
return;
}