From: Banana Date: Tue, 11 Feb 2020 14:38:54 +0000 (+0100) Subject: xml import based on exportfile. Overwrite option X-Git-Tag: 2.4_2020-02-16~5 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=2bea32bdc2fbf0b6e9a27c3208144217593c775b;p=insipid.git xml import based on exportfile. Overwrite option --- diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index effd485..697da4c 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -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; diff --git a/webroot/view/stats.inc.php b/webroot/view/stats.inc.php index 3c9f6cf..6cc9b58 100644 --- a/webroot/view/stats.inc.php +++ b/webroot/view/stats.inc.php @@ -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';