fixed category handling.

allow to preserv cat if record is updated
added dry-run option
This commit is contained in:
Cornelius Weiß 2007-06-21 14:02:03 +00:00
parent 1735a53f85
commit 288c28a658
3 changed files with 31 additions and 17 deletions

View File

@ -13,11 +13,13 @@
$path_to_egroupware = realpath(dirname(__FILE__).'/..');
$usage = "usage:
--definition <name of definition>
--file <name of file>
--user <eGW username>
--password <password for user>
--domain <domain name> \n";
--definition <name of definition> Name of definition
--file <name of file> File to import / for export
--user <eGW username> eGroupWare username for action
--password <password for user> users password
--domain <domain name> 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' );

View File

@ -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'];
}

View File

@ -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