]> 91.132.146.200 Git - insipid.git/commitdiff
xml import based on exportfile. Overwrite option
authorBanana <mail@bananas-playground.net>
Tue, 11 Feb 2020 14:38:54 +0000 (15:38 +0100)
committerBanana <mail@bananas-playground.net>
Tue, 11 Feb 2020 14:38:54 +0000 (15:38 +0100)
webroot/lib/management.class.php
webroot/view/stats.inc.php

index effd485aab4df07656892423a49aa0fe88480150..697da4ce0b6e905e691ac4129c2dffdf016407a7 100644 (file)
@@ -719,6 +719,13 @@ class Management {
        }
 
 
+       /**
+        * process the given xml file. Based on the export file
+        * options are overwrite => true|false
+        * @param $file
+        * @param $options
+        * @return array
+        */
        public function processImportFile($file, $options) {
                $ret = array(
                        'status' => 'error',
@@ -742,20 +749,27 @@ class Management {
                        $_amount = count($links);
                        foreach($links as $linkToImport) {
                                if($this->_linkExistsById($linkToImport['id'])) {
-                                       $linkObj = new Link($this->DB);
-                                       $linkObj->load($linkToImport['hash']);
-                                       $do = $linkObj->update($linkToImport);
+                                       if(isset($options['overwrite']) && $options['overwrite'] === true) {
+                                               $linkObj = new Link($this->DB);
+                                               $linkObj->load($linkToImport['hash']);
+                                               $do = $linkObj->update($linkToImport);
+                                       }
                                        $_existing++;
                                }
                                else {
                                        $_new++;
                                        var_dump('new one');
                                }
-                               //var_dump($linkToImport);
+                       }
+                       if(isset($options['overwrite']) && $options['overwrite'] === true) {
+                               $_msg = "Found $_amount link(s) to import. Overwritten $_existing existing and imported $_new new one(s).";
+                       }
+                       else {
+                               $_msg = "Found $_amount link(s) to import. Skipped $_existing existing and imported $_new new one(s).";
                        }
                        $ret = array(
                                'status' => 'success',
-                               'message' => "Found $_amount link(s) to import. $_existing existing and $_new new one(s)."
+                               'message' => $_msg
                        );
 
                }
@@ -782,6 +796,11 @@ class Management {
                return $ret;
        }
 
+       /**
+        * Check if given id (not hash) exists in link database
+        * @param $id
+        * @return bool
+        */
        private function _linkExistsById($id) {
                $ret = false;
 
index 3c9f6cfcf572f3741d542c04d673b983341b474f..6cc9b58512030b6d1b4e60f0ad9b45b49c8439fe 100644 (file)
@@ -82,6 +82,12 @@ if(isset($_POST['statsImportXML'])) {
        $_options = array();
 
        if(isset($_FILES['importxmlfile']) && !empty($_FILES['importxmlfile'])) {
+
+               $_options['overwrite'] = false;
+               if(isset($_POST['importOverwrite'])) {
+                       $_options['overwrite'] = true;
+               }
+
                $do = $Management->processImportFile($_FILES['importxmlfile'], $_options);
                if(isset($do['status']) && $do['status'] === 'success') {
                        $submitFeedback['status'] = 'success';