From 665c380d5dd2d602b9541188c738a69b81c48a69 Mon Sep 17 00:00:00 2001 From: Banana Date: Fri, 27 Dec 2019 12:33:58 +0100 Subject: [PATCH] changed log name for email import. Check for duplicate in email importer --- ChangeLog | 1 + webroot/.gitignore | 2 +- webroot/job/email-import.php | 60 +++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6823570..c32950f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ version 2.2 - Guardian of Ice - (tba) * Fixed info when a tag or category has no links * Fixed code cleanups * Fixed access to log files directory + * Fixed check for duplicates in email importer version 2.1alpha - Guardian of Fire - (2019-09-29) diff --git a/webroot/.gitignore b/webroot/.gitignore index 77e477b..c35f095 100644 --- a/webroot/.gitignore +++ b/webroot/.gitignore @@ -1,2 +1,2 @@ config.php -error.log +*.log diff --git a/webroot/job/email-import.php b/webroot/job/email-import.php index 25b524e..b090ce6 100644 --- a/webroot/job/email-import.php +++ b/webroot/job/email-import.php @@ -36,7 +36,7 @@ define('DEBUG',true); ## set the error reporting ini_set('log_errors',true); -ini_set('error_log','error.log'); +ini_set('error_log','import.log'); if(DEBUG === true) { ini_set('display_errors',true); } @@ -184,29 +184,39 @@ if(!empty($emails)) { if(DEBUG === true) var_dump($newdata); - $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); - - $linkObj = new Link($DB); - try { - $linkID = $linkObj->create(array( - 'hash' => $newdata['hash'], - 'search' => $newdata['search'], - 'link' => $newdata['link'], - 'status' => $newdata['status'], - 'description' => $newdata['description'], - 'title' => $newdata['title'], - 'image' => $newdata['image'] - ), true); - } - catch (Exception $e) { - $_m = "WARN Can not create new link into DB. Duplicate? ".$e->getMessage(); - error_log($_m); - $emailData['importmessage'] = $_m; - array_push($invalidProcessedEmails,$emailData); - if(DEBUG === true) var_dump($_m); - if(DEBUG === true) var_dump($newdata); - continue; - } + $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); + + $linkObj = new Link($DB); + $linkID = false; + + # check for duplicate + $existing = $linkObj->load($newdata['hash']); + if(!empty($existing) && isset($existing['id'])) { + $linkID = $existing['id']; + error_log('INFO Updating existing link with tag or category '.$newdata['link']); + } + else { + $linkObj = new Link($DB); + try { + $linkID = $linkObj->create(array( + 'hash' => $newdata['hash'], + 'search' => $newdata['search'], + 'link' => $newdata['link'], + 'status' => $newdata['status'], + 'description' => $newdata['description'], + 'title' => $newdata['title'], + 'image' => $newdata['image'] + ), true); + } catch (Exception $e) { + $_m = "WARN Can not create new link into DB. Duplicate? " . $e->getMessage(); + error_log($_m); + $emailData['importmessage'] = $_m; + array_push($invalidProcessedEmails, $emailData); + if (DEBUG === true) var_dump($_m); + if (DEBUG === true) var_dump($newdata); + continue; + } + } if(!empty($linkID)) { @@ -231,7 +241,7 @@ if(!empty($emails)) { $DB->commit(); - error_log("INFO Link successfully added: ".$newdata['link']); + error_log("INFO Link successfully added/updated: ".$newdata['link']); array_push($validProcessedEmails,$emailData); } else { -- 2.39.5