fix fields::merge command

This commit is contained in:
Nicolas Le Goff
2012-05-04 17:16:35 +02:00
parent be63d495be
commit b122293e29
3 changed files with 19 additions and 38 deletions

View File

@@ -31,14 +31,9 @@ class module_console_fieldsDelete extends Command
$this->setDescription('Delete a documentation field from a Databox'); $this->setDescription('Delete a documentation field from a Databox');
// $this->addArgument('name', InputArgument::REQUIRED, 'Metadata structure ids for source');
$this->addArgument('meta_struct_id', InputArgument::REQUIRED, 'Metadata structure id destination'); $this->addArgument('meta_struct_id', InputArgument::REQUIRED, 'Metadata structure id destination');
$this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id'); $this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id');
// $this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
//
// $this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
return $this; return $this;
} }

View File

@@ -31,9 +31,9 @@ class module_console_fieldsMerge extends Command
$this->setDescription('Merge databox structure fields'); $this->setDescription('Merge databox structure fields');
$this->addArgument('source', InputArgument::REQUIRED, 'Metadata structure ids for source');
$this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id'); $this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id');
$this->addArgument('destination', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Metadata structure id destination'); $this->addArgument('destination', InputArgument::REQUIRED, 'Metadata structure id destination');
$this->addArgument('source', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Metadata structure ids for source');
// $this->addOption( // $this->addOption(
// 'source' // 'source'
@@ -42,14 +42,12 @@ class module_console_fieldsMerge extends Command
// , 'Metadata structure ids for source' // , 'Metadata structure ids for source'
// , array() // , array()
// ); // );
// $this->addOption( // $this->addOption(
// 'destination' // 'destination'
// , 'd' // , 'd'
// , InputOption::VALUE_REQUIRED // , InputOption::VALUE_REQUIRED
// , 'Metadata structure id destination' // , 'Metadata structure id destination'
// ); // );
// $this->addOption( // $this->addOption(
// 'sbas_id' // 'sbas_id'
// , 's' // , 's'
@@ -203,36 +201,30 @@ class module_console_fieldsMerge extends Command
foreach ($sources as $source) { foreach ($sources as $source) {
try { try {
$value = $record->get_caption()->get_field($source->get_name())->get_value();
} catch (\Exception $e) {
$value = array();
}
if ( ! is_array($value)) {
$value = array($value);
}
$datas = array_merge($datas, $value); $values = $record->get_caption()->get_field($source->get_name())->get_values();
foreach ($values as $captionValue) {
$datas[] = $captionValue->getValue();
$captionValue->delete();
}
} catch (\Exception $e) {
}
} }
$datas = array_unique($datas); $datas = array_unique($datas);
if ( ! $destination->is_multi()) { if ( ! $destination->is_multi()) {
$datas = array(implode($separator, $datas)); $datas = implode($separator, $datas);
} }
try { foreach ((array) $datas as $data) {
$record->get_caption()->get_field($destination->get_name())->set_value($datas); $record->set_metadatas(array(array(
} catch (\Exception $e) { 'meta_struct_id' => $destination->get_id(),
$record->set_metadatas( 'meta_id' => null,
array( 'value' => $data,
array( )), true);
'meta_struct_id' => $destination->get_id()
, 'meta_id' => null
, 'value' => $datas
)
)
, true
);
} }
unset($record); unset($record);
} }

View File

@@ -31,16 +31,10 @@ class module_console_fieldsRename extends Command
$this->setDescription('Rename a documentation field from a Databox'); $this->setDescription('Rename a documentation field from a Databox');
$this->addArgument('name', InputArgument::REQUIRED, 'Metadata structure ids for source'); $this->addArgument('name', InputArgument::REQUIRED, 'The new name');
$this->addArgument('meta_struct_id', InputArgument::REQUIRED, 'Metadata structure id destination'); $this->addArgument('meta_struct_id', InputArgument::REQUIRED, 'Metadata structure id destination');
$this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id'); $this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id');
// $this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
//
// $this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
//
// $this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'The new name');
return $this; return $this;
} }