From b3f6512e4b7d9e2b72b52e20c69cb76dd8182501 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 25 Feb 2013 12:07:56 -0800 Subject: [PATCH] Better handling of duplicate images when importing submitted news. --- e107_admin/newspost.php | 4 ++-- e107_handlers/media_class.php | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 88a06d052..3f68e7b7a 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -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), diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index d4b280183..f0ca96b88 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -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."
oldpath=".$oldpath."
".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; }