From f75ab71d9862a19546f7ea893d722457586ed1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Thu, 21 Jun 2007 18:04:23 +0000 Subject: [PATCH] imrpove dry-run and cli --- importexport/importexport_cli.php | 34 ++++++++++++-------- importexport/inc/class.bodefinitions.inc.php | 16 --------- importexport/inc/class.definition.inc.php | 2 +- importexport/inc/class.import_csv.inc.php | 1 + 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/importexport/importexport_cli.php b/importexport/importexport_cli.php index 5eca6f993a..83bb40bfe8 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); @@ -129,21 +136,22 @@ fwrite(STDERR,"importexport_cli: ". $file. ' is not readable'."\n"); exit(INVALID_OPTION); } - + require_once('inc/class.definition.inc.php'); - try { - $definition = new definition($definition); - } - catch (Exception $e) { - fwrite(STDERR,"importexport_cli: ". $e->getMessage(). "\n"); + $definition = new definition($definition); + if( $definition->get_identifier() < 1 ) { + fwrite(STDERR,"importexport_cli: Definition not found! \n"); exit(INVALID_OPTION); } $GLOBALS['egw_info']['flags']['currentapp'] = $definition->application; + $definition->plugin_options['dry_run'] = $dryrun; + $type = $definition->type; + + require_once("$path_to_egroupware/$definition->application/importexport/class.$definition->plugin.inc.php"); $po = new $definition->plugin; - $type = $definition->type; $resource = fopen( $file, 'r' ); $po->$type( $resource, $definition ); diff --git a/importexport/inc/class.bodefinitions.inc.php b/importexport/inc/class.bodefinitions.inc.php index 01a481a0bb..d5fe3d566a 100644 --- a/importexport/inc/class.bodefinitions.inc.php +++ b/importexport/inc/class.bodefinitions.inc.php @@ -54,22 +54,6 @@ class bodefinitions { return $this->definitions; } - /** - * reads a definition from database - * - * @deprecated see class.definition.inc.php - * @param mixed &$definition - * @return bool success or not - */ - public function read(&$definition) { - if(is_int($definition)) $definition = array('definition_id' => $definition); - elseif(is_string($definition)) $definition = array('name' => $definition); - if(!$definition = $this->so_sql->read($definition)) return false; - $definition += (array)unserialize($definition['plugin_options']); - unset($definition['plugin_options']); - return true; - } - /** * deletes a defintion * diff --git a/importexport/inc/class.definition.inc.php b/importexport/inc/class.definition.inc.php index 6bbd22f010..90035331dc 100644 --- a/importexport/inc/class.definition.inc.php +++ b/importexport/inc/class.definition.inc.php @@ -217,7 +217,7 @@ class definition implements iface_egw_record { /** * gets identifier of this record * - * @return string identifier of this record + * @return int identifier of this record */ public function get_identifier() { return $this->definition['definition_id']; diff --git a/importexport/inc/class.import_csv.inc.php b/importexport/inc/class.import_csv.inc.php index a5b4345550..08d0378640 100755 --- a/importexport/inc/class.import_csv.inc.php +++ b/importexport/inc/class.import_csv.inc.php @@ -209,6 +209,7 @@ class import_csv implements iface_import_record { //, Iterator { $record = $this->record; $this->record = array(); foreach ($this->mapping as $cvs_idx => $new_idx) { + if( $new_idx == '' ) continue; $this->record[$new_idx] = $record[$cvs_idx]; } return true;