]> 91.132.146.200 Git - insipid.git/commitdiff
changed log name for email import. Check for duplicate in email importer
authorBanana <banana@mirage>
Fri, 27 Dec 2019 11:33:58 +0000 (12:33 +0100)
committerBanana <banana@mirage>
Fri, 27 Dec 2019 11:33:58 +0000 (12:33 +0100)
ChangeLog
webroot/.gitignore
webroot/job/email-import.php

index 68235702187818df4e686c3a3e86b1226b42d453..c32950fea8ee453d1438105c3957f75ed57f91e0 100755 (executable)
--- 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)
 
index 77e477b7922a7ea9481bfd552cc65f8d9f09ec84..c35f095d8aec0c2192e3402a7dbbabbceaf898f2 100644 (file)
@@ -1,2 +1,2 @@
 config.php
-error.log
+*.log
index 25b524ed25083d051e287d722599eff923b46f31..b090ce6bffd2e9027043764e7c05270f4f6f7ca5 100644 (file)
@@ -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 {