mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
fixed category handling.
allow to preserv cat if record is updated added dry-run option
This commit is contained in:
parent
1735a53f85
commit
288c28a658
@ -13,11 +13,13 @@
|
|||||||
$path_to_egroupware = realpath(dirname(__FILE__).'/..');
|
$path_to_egroupware = realpath(dirname(__FILE__).'/..');
|
||||||
|
|
||||||
$usage = "usage:
|
$usage = "usage:
|
||||||
--definition <name of definition>
|
--definition <name of definition> Name of definition
|
||||||
--file <name of file>
|
--file <name of file> File to import / for export
|
||||||
--user <eGW username>
|
--user <eGW username> eGroupWare username for action
|
||||||
--password <password for user>
|
--password <password for user> users password
|
||||||
--domain <domain name> \n";
|
--domain <domain name> eGroupWare domain
|
||||||
|
--dry-run no real action, just console output
|
||||||
|
\n";
|
||||||
|
|
||||||
if (php_sapi_name() != 'cli') {
|
if (php_sapi_name() != 'cli') {
|
||||||
die('This script only runs form command line');
|
die('This script only runs form command line');
|
||||||
@ -49,7 +51,8 @@
|
|||||||
'file=',
|
'file=',
|
||||||
'user=',
|
'user=',
|
||||||
'password=',
|
'password=',
|
||||||
'domain='
|
'domain=',
|
||||||
|
'dry-run',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert the arguments to options - check for the first argument
|
// Convert the arguments to options - check for the first argument
|
||||||
@ -66,6 +69,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$domain = 'default';
|
$domain = 'default';
|
||||||
|
$dryrun = false;
|
||||||
foreach ($options[0] as $option) {
|
foreach ($options[0] as $option) {
|
||||||
switch ($option[0]) {
|
switch ($option[0]) {
|
||||||
case '--file' :
|
case '--file' :
|
||||||
@ -83,6 +87,9 @@
|
|||||||
case '--password' :
|
case '--password' :
|
||||||
$password = $option[1];
|
$password = $option[1];
|
||||||
break;
|
break;
|
||||||
|
case '--dry-run' :
|
||||||
|
$dryrun = true;
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
fwrite (STDERR,$usage."\n");
|
fwrite (STDERR,$usage."\n");
|
||||||
exit(INVALID_OPTION);
|
exit(INVALID_OPTION);
|
||||||
@ -139,8 +146,11 @@
|
|||||||
exit(INVALID_OPTION);
|
exit(INVALID_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$GLOBALS['egw_info']['flags']['currentapp'] = $definition->application;
|
||||||
|
|
||||||
require_once("$path_to_egroupware/$definition->application/importexport/class.$definition->plugin.inc.php");
|
require_once("$path_to_egroupware/$definition->application/importexport/class.$definition->plugin.inc.php");
|
||||||
$po = new $definition->plugin;
|
$po = new $definition->plugin;
|
||||||
|
$po->plugin_options['dry-run'] = true;
|
||||||
$type = $definition->type;
|
$type = $definition->type;
|
||||||
|
|
||||||
$resource = fopen( $file, 'r' );
|
$resource = fopen( $file, 'r' );
|
||||||
|
@ -96,6 +96,9 @@ class definition implements iface_egw_record {
|
|||||||
if (isset($identifiers[1])) {
|
if (isset($identifiers[1])) {
|
||||||
throw new Exception('Error: Definition: "'.$_name. '" is not unique! Can\'t convert to identifier');
|
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'];
|
return $identifiers[0]['definition_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* use import_export_helper_functions::method
|
* use import_export_helper_functions::method
|
||||||
*/
|
*/
|
||||||
class import_export_helper_functions {
|
class import_export_helper_functions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nothing to construct here, only static 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
|
* @return mixed comma seperated list or array with cat_ids
|
||||||
*/
|
*/
|
||||||
public static function cat_name2id( $_cat_names ) {
|
public static function cat_name2id( $_cat_names ) {
|
||||||
$cats = &CreateObject( 'phpgwapi.categories' );
|
$cats = CreateObject( 'phpgwapi.categories' );
|
||||||
$cats->app_name = 'phpgw';
|
$cats->app_name = $GLOBALS['egw_info']['flags']['currentapp'];
|
||||||
|
|
||||||
$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
|
$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
|
||||||
|
|
||||||
foreach ( $cat_names as $cat_name ) {
|
foreach ( $cat_names as $cat_name ) {
|
||||||
if ( $cat_id = $cats->name2id( addslashes( $cat_name ))) { }
|
|
||||||
else $cat_id = $cats->add( array(
|
if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 ) {
|
||||||
'name' => $cat_name,
|
$cat_id = $cats->add( array(
|
||||||
'access' => 'public',
|
'name' => $cat_name,
|
||||||
'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')'
|
'access' => 'public',
|
||||||
));
|
'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')'
|
||||||
|
));
|
||||||
|
}
|
||||||
$cat_ids[] = $cat_id;
|
$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
|
} // end of member function category_name2id
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user