diff --git a/importexport/importexport_cli.php b/importexport/importexport_cli.php index ac21d62cc7..c9fe20daec 100755 --- a/importexport/importexport_cli.php +++ b/importexport/importexport_cli.php @@ -13,11 +13,13 @@ $path_to_egroupware = realpath(dirname(__FILE__).'/..'); $usage = "usage: - --definition - --file - --user - --password - --domain \n"; + --definition Name of definition + --file File to import / for export + --user eGroupWare username for action + --password users password + --domain eGroupWare domain + --dry-run no real action, just console output + \n"; if (php_sapi_name() != 'cli') { die('This script only runs form command line'); @@ -49,7 +51,8 @@ 'file=', 'user=', 'password=', - 'domain=' + 'domain=', + 'dry-run', ); // Convert the arguments to options - check for the first argument @@ -66,6 +69,7 @@ } $domain = 'default'; + $dryrun = false; foreach ($options[0] as $option) { switch ($option[0]) { case '--file' : @@ -83,6 +87,9 @@ case '--password' : $password = $option[1]; break; + case '--dry-run' : + $dryrun = true; + break; default : fwrite (STDERR,$usage."\n"); exit(INVALID_OPTION); @@ -139,8 +146,11 @@ exit(INVALID_OPTION); } + $GLOBALS['egw_info']['flags']['currentapp'] = $definition->application; + require_once("$path_to_egroupware/$definition->application/importexport/class.$definition->plugin.inc.php"); $po = new $definition->plugin; + $po->plugin_options['dry-run'] = true; $type = $definition->type; $resource = fopen( $file, 'r' ); diff --git a/importexport/inc/class.definition.inc.php b/importexport/inc/class.definition.inc.php index c0ab114978..782aed8a0d 100644 --- a/importexport/inc/class.definition.inc.php +++ b/importexport/inc/class.definition.inc.php @@ -96,6 +96,9 @@ class definition implements iface_egw_record { if (isset($identifiers[1])) { throw new Exception('Error: Definition: "'.$_name. '" is not unique! Can\'t convert to identifier'); } + if ( empty( $identifiers[0] ) ) { + throw new Exception('Error: No such definition :"'.$_name.'"!'); + } return $identifiers[0]['definition_id']; } diff --git a/importexport/inc/class.import_export_helper_functions.inc.php b/importexport/inc/class.import_export_helper_functions.inc.php index 39cfdeda15..182c85557c 100755 --- a/importexport/inc/class.import_export_helper_functions.inc.php +++ b/importexport/inc/class.import_export_helper_functions.inc.php @@ -15,7 +15,7 @@ * use import_export_helper_functions::method */ class import_export_helper_functions { - + /** * nothing to construct here, only static functions! */ @@ -77,21 +77,22 @@ class import_export_helper_functions { * @return mixed comma seperated list or array with cat_ids */ public static function cat_name2id( $_cat_names ) { - $cats = &CreateObject( 'phpgwapi.categories' ); - $cats->app_name = 'phpgw'; + $cats = CreateObject( 'phpgwapi.categories' ); + $cats->app_name = $GLOBALS['egw_info']['flags']['currentapp']; $cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names ); - foreach ( $cat_names as $cat_name ) { - if ( $cat_id = $cats->name2id( addslashes( $cat_name ))) { } - else $cat_id = $cats->add( array( - 'name' => $cat_name, - 'access' => 'public', - 'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')' - )); + + if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 ) { + $cat_id = $cats->add( array( + 'name' => $cat_name, + 'access' => 'public', + 'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')' + )); + } $cat_ids[] = $cat_id; } - return $_cat_names ? $cat_ids : implode( ',', $cat_ids ); + return is_array( $_cat_names ) ? $cat_ids : implode( ',', $cat_ids ); } // end of member function category_name2id