Add auto-import of definitions in appname/setup/*.xml

This commit is contained in:
Nathan Gray 2011-02-03 18:09:39 +00:00
parent a0d7bde2fb
commit 37417195eb
6 changed files with 67 additions and 23 deletions

View File

@ -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());
}

View File

@ -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 );
}
}
}

View File

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

View File

@ -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',
),
);

View File

@ -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')
)
);

View File

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