From 34f8f7db0896dfc0099d0174c4f086f885f632c1 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 18 Oct 2012 16:38:30 +0000 Subject: [PATCH] Prevent new categories from being created during dry-run --- .../inc/class.importexport_helper_functions.inc.php | 7 ++++++- importexport/inc/class.importexport_import_ui.inc.php | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/importexport/inc/class.importexport_helper_functions.inc.php b/importexport/inc/class.importexport_helper_functions.inc.php index 4fb1cea44a..5c0a9eb4d0 100755 --- a/importexport/inc/class.importexport_helper_functions.inc.php +++ b/importexport/inc/class.importexport_helper_functions.inc.php @@ -21,6 +21,11 @@ class importexport_helper_functions { */ const CACHE_EXPIRATION = 3600; + /** + * Make no changes (automatic category creation) + */ + public static $dry_run = false; + /** * Files known to cause problems, and will be skipped in a plugin scan * If you put appname => true, the whole app will be skipped. @@ -187,7 +192,7 @@ class importexport_helper_functions { foreach ( $cat_names as $cat_name ) { $cat_name = trim($cat_name); if ( $cat_name == '' ) continue; - if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 ) { + if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) { $cat_id = $cats->add( array( 'name' => $cat_name, 'parent' => $parent, diff --git a/importexport/inc/class.importexport_import_ui.inc.php b/importexport/inc/class.importexport_import_ui.inc.php index 748c4cdbe0..39d15a2539 100644 --- a/importexport/inc/class.importexport_import_ui.inc.php +++ b/importexport/inc/class.importexport_import_ui.inc.php @@ -97,6 +97,7 @@ { // Set this so plugin doesn't do any data changes $content['dry-run'] = true; + importexport_helper_functions::$dry_run = true; $this->message .= '' . lang('Import aborted').":
\n"; $definition_obj->plugin_options = (array)$definition_obj->plugin_options + array('dry_run' => true); } @@ -105,6 +106,10 @@ { echo $this->preview($plugin, $file, $definition_obj); } + else + { + importexport_helper_functions::$dry_run = false; + } $count = $plugin->import($file, $definition_obj); } else