From f8e9fbb9aead4e9968eb600c11dbad84d66215ac Mon Sep 17 00:00:00 2001 From: Banana Date: Tue, 11 Feb 2020 17:00:04 +0100 Subject: [PATCH] documentation for simple import and export --- ChangeLog | 1 + documentation/update.txt | 4 +- documentation/xml-export-and-import.txt | 10 +++++ webroot/job/email-import.php | 5 ++- webroot/lib/management.class.php | 53 +++++++++++++++++++++++-- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 documentation/xml-export-and-import.txt diff --git a/ChangeLog b/ChangeLog index 421a4ea..2bc85d3 100755 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ version x.x - Seven Portals (tba) + Now including update instructions + DB export only insipid tables and not the whole DB itself. + + Simple xml export and import + #2 Protection if the email-import.php file if it needs to be in a web accessible folder + Fixed the search for words. See update instructions how to correct your data diff --git a/documentation/update.txt b/documentation/update.txt index 7f328a5..773672d 100644 --- a/documentation/update.txt +++ b/documentation/update.txt @@ -8,4 +8,6 @@ To validate you can now search for single words case-insensitive. + Update config file with tow new settings. See config.default for more info define('EMAIL_JOB_PROTECT', false); -define('EMAIL_JOB_PROTECT_SECRET', 'SOME_SECRET_STRING'); \ No newline at end of file +define('EMAIL_JOB_PROTECT_SECRET', 'SOME_SECRET_STRING'); + ++ All Files in webroot/asset/js/ EXCEPT the new editlink.js can be removed \ No newline at end of file diff --git a/documentation/xml-export-and-import.txt b/documentation/xml-export-and-import.txt new file mode 100644 index 0000000..60c0b64 --- /dev/null +++ b/documentation/xml-export-and-import.txt @@ -0,0 +1,10 @@ +Any link can be exported as a xml file from the link info view. +Login is required to trigger this function. +The result can be used to import it again at the stats view. + +It exports all the link information, image and its tags and categories. + +The import can overwrite existing links and import non existing ones. + +A import xml file can contain multiple exports. Make sure the root is +still there. \ No newline at end of file diff --git a/webroot/job/email-import.php b/webroot/job/email-import.php index 4815cfc..f7db1b6 100644 --- a/webroot/job/email-import.php +++ b/webroot/job/email-import.php @@ -208,13 +208,14 @@ if(!empty($emails)) { if(DEBUG === true) var_dump($newdata); - $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); - $linkObj = new Link($DB); $linkID = false; # check for duplicate $existing = $linkObj->load($newdata['hash']); + + $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); + if(!empty($existing) && isset($existing['id'])) { $linkID = $existing['id']; error_log('INFO Updating existing link with tag or category '.$newdata['link']); diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index 697da4c..08ce708 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -718,7 +718,6 @@ class Management { return $ret; } - /** * process the given xml file. Based on the export file * options are overwrite => true|false @@ -748,6 +747,8 @@ class Management { if(!empty($links)) { $_amount = count($links); foreach($links as $linkToImport) { + $do = false; + if($this->_linkExistsById($linkToImport['id'])) { if(isset($options['overwrite']) && $options['overwrite'] === true) { $linkObj = new Link($this->DB); @@ -757,8 +758,55 @@ class Management { $_existing++; } else { + $linkObj = new Link($this->DB); + + $this->DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); + try{ + $do = $linkObj->create(array( + 'hash' => $linkToImport['hash'], + 'link' => $linkToImport['link'], + 'status' => $linkToImport['private'], + 'description' => $linkToImport['description'], + 'title' => $linkToImport['title'], + 'search' => '', + 'image' => $linkToImport['image'] + ), true); + } catch (Exception $e) { + continue; + } + + if(!empty($do)) { + + $linkToImport['catArr'] = Summoner::prepareTagOrCategoryStr($linkToImport['category']); + $linkToImport['tagArr'] = Summoner::prepareTagOrCategoryStr($linkToImport['tag']); + + if(!empty($linkToImport['catArr'])) { + foreach($linkToImport['catArr'] as $c) { + $catObj = new Category($this->DB); + $catObj->initbystring($c); + $catObj->setRelation($do); + + unset($catObj); + } + } + if(!empty($linkToImport['tagArr'])) { + foreach($linkToImport['tagArr'] as $t) { + $tagObj = new Tag($this->DB); + $tagObj->initbystring($t); + $tagObj->setRelation($do); + + unset($tagObj); + } + } + + $this->DB->commit(); + + $this->updateSearchIndex(); + } + else { + $this->DB->rollback(); + } $_new++; - var_dump('new one'); } } if(isset($options['overwrite']) && $options['overwrite'] === true) { @@ -771,7 +819,6 @@ class Management { 'status' => 'success', 'message' => $_msg ); - } return $ret; -- 2.39.5