diff --git a/importexport/inc/class.importexport_definition.inc.php b/importexport/inc/class.importexport_definition.inc.php index 25dc86bc29..42d067bdfd 100644 --- a/importexport/inc/class.importexport_definition.inc.php +++ b/importexport/inc/class.importexport_definition.inc.php @@ -33,6 +33,7 @@ class importexport_definition implements importexport_iface_egw_record { 'plugin_options' => 'array', 'owner' => 'int', 'description' => 'string', + 'modified' => 'timestamp' ); /** @@ -234,6 +235,7 @@ class importexport_definition implements importexport_iface_egw_record { $this->so_sql->data = $this->definition; $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml( $this->definition['plugin_options'] ); + $this->so_sql->data['modified'] = time(); if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) { throw new Exception('Error: so_sql was not able to save definition: '.$this->get_identifier()); } diff --git a/importexport/inc/class.importexport_definitions_bo.inc.php b/importexport/inc/class.importexport_definitions_bo.inc.php index 81e082dbc5..14d225bf28 100644 --- a/importexport/inc/class.importexport_definitions_bo.inc.php +++ b/importexport/inc/class.importexport_definitions_bo.inc.php @@ -159,10 +159,15 @@ class importexport_definitions_bo { $definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] ); $definition = new importexport_definition( $definition_data['name'] ); - $definition_id = $definition->get_identifier() ? $definition->get_identifier() : NULL; - $definition->set_record( $definition_data ); - $definition->save( $definition_id ); + // Only update if the imported is newer + if($definition->modified < $definition_data['modified'] || $definition->modified == 0) + { + $definition_id = $definition->get_identifier() ? $definition->get_identifier() : NULL; + + $definition->set_record( $definition_data ); + $definition->save( $definition_id ); + } } } diff --git a/importexport/inc/class.importexport_helper_functions.inc.php b/importexport/inc/class.importexport_helper_functions.inc.php index 227d054265..20139c70ea 100755 --- a/importexport/inc/class.importexport_helper_functions.inc.php +++ b/importexport/inc/class.importexport_helper_functions.inc.php @@ -316,6 +316,8 @@ class importexport_helper_functions { $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; $types = $_type == 'all' ? array('import','export') : (array)$_type; + // Testing: comment out egw_cache call, use this + //$plugins = self::_get_plugins($appnames, $types); foreach($plugins as $appname => $_types) { if(!in_array($appname, $appnames)) unset($plugins[$appname]); } @@ -360,6 +362,25 @@ class importexport_helper_functions { } } $d->close(); + + // Check for new definitions to import from $appname/setup/*.xml + $appdir = EGW_INCLUDE_ROOT. "/$appname/setup"; + if(!is_dir($appdir)) continue; + $d = dir($appdir); + + // step through each file in app's setup + while (false !== ($entry = $d->read())) { + $file = $appdir. '/'. $entry; + list( $filename, $extension) = explode('.',$entry); + if ( $extension != 'xml' ) continue; + try { + // import will skip invalid files + importexport_definitions_bo::import( $file ); + } catch (Exception $e) { + error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage()); + } + } + $d->close(); } //error_log(__CLASS__.__FUNCTION__.print_r($plugins,true)); return $plugins; diff --git a/importexport/setup/setup.inc.php b/importexport/setup/setup.inc.php index a385099c46..6207345c4c 100644 --- a/importexport/setup/setup.inc.php +++ b/importexport/setup/setup.inc.php @@ -10,7 +10,7 @@ */ $setup_info['importexport']['name'] = 'importexport'; -$setup_info['importexport']['version'] = '1.8'; +$setup_info['importexport']['version'] = '1.9.001'; $setup_info['importexport']['app_order'] = 2; $setup_info['importexport']['enable'] = 2; $setup_info['importexport']['tables'] = array('egw_importexport_definitions'); @@ -48,3 +48,4 @@ $setup_info['importexport']['check_install'] = array( 'func' => 'extension_check', ), ); + diff --git a/importexport/setup/tables_current.inc.php b/importexport/setup/tables_current.inc.php index d52f9bd866..a8b983ee37 100644 --- a/importexport/setup/tables_current.inc.php +++ b/importexport/setup/tables_current.inc.php @@ -13,22 +13,23 @@ /* $Id$ */ - $phpgw_baseline = array( - 'egw_importexport_definitions' => array( - 'fd' => array( - 'definition_id' => array('type' => 'auto'), - 'name' => array('type' => 'varchar','precision' => '255'), - 'application' => array('type' => 'varchar','precision' => '50'), - 'plugin' => array('type' => 'varchar','precision' => '100'), - 'type' => array('type' => 'varchar','precision' => '20'), - 'allowed_users' => array('type' => 'varchar','precision' => '255'), - 'plugin_options' => array('type' => 'longtext'), - 'owner' => array('type' => 'int','precision' => '20'), - 'description' => array('type' => 'varchar','precision' => '255') - ), - 'pk' => array('definition_id'), - 'fk' => array(), - 'ix' => array('name'), - 'uc' => array('name') - ) - ); +$phpgw_baseline = array( + 'egw_importexport_definitions' => array( + 'fd' => array( + 'definition_id' => array('type' => 'auto','nullable' => False), + 'name' => array('type' => 'varchar','precision' => '255'), + 'application' => array('type' => 'varchar','precision' => '50'), + 'plugin' => array('type' => 'varchar','precision' => '100'), + 'type' => array('type' => 'varchar','precision' => '20'), + 'allowed_users' => array('type' => 'varchar','precision' => '255'), + 'plugin_options' => array('type' => 'longtext'), + 'owner' => array('type' => 'int','precision' => '20'), + 'description' => array('type' => 'varchar','precision' => '255'), + 'modified' => array('type' => 'timestamp') + ), + 'pk' => array('definition_id'), + 'fk' => array(), + 'ix' => array('name'), + 'uc' => array('name') + ) +); diff --git a/importexport/setup/tables_update.inc.php b/importexport/setup/tables_update.inc.php index 64364a8fe7..eb207dd26e 100755 --- a/importexport/setup/tables_update.inc.php +++ b/importexport/setup/tables_update.inc.php @@ -41,3 +41,17 @@ function importexport_upgrade1_7_001() { return $GLOBALS['setup_info']['importexport']['currentver'] = '1.8'; } + +function importexport_upgrade1_8() +{ + $GLOBALS['egw_setup']->oProc->AlterColumn('egw_importexport_definitions','definition_id',array( + 'type' => 'auto', + 'nullable' => False + )); + $GLOBALS['egw_setup']->oProc->AddColumn('egw_importexport_definitions','modified',array( + 'type' => 'timestamp' + )); + + return $GLOBALS['setup_info']['importexport']['currentver'] = '1.9.001'; +} +