Author: mcantelon
Date: Mon Jan 16 14:05:36 2012
New Revision: 10685
Log:
Changed QubitFlatfile row processing for variable columns get set before
anything else happens.
Modified:
trunk/lib/QubitFlatfileImport.class.php
trunk/lib/task/csvAccessionImportTask.class.php
trunk/lib/task/csvImportTask.class.php
Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php Mon Jan 16 12:17:50 2012
(r10684)
+++ trunk/lib/QubitFlatfileImport.class.php Mon Jan 16 14:05:36 2012
(r10685)
@@ -284,18 +284,20 @@
public function mappedColumnHandler($mapDefinition, $value)
{
- if (is_array($mapDefinition))
- {
- // tranform value is logic provided to do so
- if (is_callable($mapDefinition['transformationLogic']))
+ if (isset($this->object) && is_object($this->object)) {
+ if (is_array($mapDefinition))
{
- $this->object->{$mapDefinition['column']}
- = $mapDefinition['transformationLogic']($this, $value);
+ // tranform value is logic provided to do so
+ if (is_callable($mapDefinition['transformationLogic']))
+ {
+ $this->object->{$mapDefinition['column']}
+ = $mapDefinition['transformationLogic']($this, $value);
+ } else {
+ $this->object->{$mapDefinition['column']} = $value;
+ }
} else {
- $this->object->{$mapDefinition['column']} = $value;
+ $this->object->{$mapDefinition} = $value;
}
- } else {
- $this->object->{$mapDefinition} = $value;
}
}
@@ -307,11 +309,33 @@
}
}
- protected function rowProcessingBeforeSave($row)
+ protected function rowProcessingBeforeObjectCreation($row)
{
// process import columns that don't produce child data
$this->forEachRowColumn($row, function(&$self, $index, $columnName, $value)
{
+ if (
+ isset($self->columnNames[$index])
+ && in_array($self->columnNames[$index], $self->variableColumns)
+ )
+ {
+ $self->rowStatusVars[$self->columnNames[$index]] = $value;
+ }
+ else if (
+ isset($self->columnNames[$index])
+ && isset($self->arrayColumns[($self->columnNames[$index])])
+ )
+ {
+ $self->arrayColumnHandler($columnName,
$self->arrayColumns[$columnName], $value);
+ }
+ });
+ }
+
+ protected function rowProcessingBeforeSave($row)
+ {
+ // process import columns that don't produce child data
+ $this->forEachRowColumn($row, function(&$self, $index, $columnName, $value)
+ {
// stash current column name so handlers can use it if need be
$self->status['currentColumn'] = $columnName;
@@ -333,20 +357,6 @@
}
else if (
isset($self->columnNames[$index])
- && in_array($self->columnNames[$index], $self->variableColumns)
- )
- {
- $self->rowStatusVars[$self->columnNames[$index]] = $value;
- }
- else if (
- isset($self->columnNames[$index])
- && isset($self->arrayColumns[($self->columnNames[$index])])
- )
- {
- $self->arrayColumnHandler($columnName,
$self->arrayColumns[$columnName], $value);
- }
- else if (
- isset($self->columnNames[$index])
&& in_array($self->columnNames[$index], $self->standardColumns)
)
{
@@ -387,6 +397,9 @@
// stash raw row data so it's accessible to closure logic
$this->status['row'] = $row;
+ // set row status variables that are based on column values
+ $this->rowProcessingBeforeObjectCreation($row);
+
if (isset($this->className))
{
// create new object
Modified: trunk/lib/task/csvAccessionImportTask.class.php
==============================================================================
--- trunk/lib/task/csvAccessionImportTask.class.php Mon Jan 16 12:17:50
2012 (r10684)
+++ trunk/lib/task/csvAccessionImportTask.class.php Mon Jan 16 14:05:36
2012 (r10685)
@@ -87,7 +87,7 @@
print "WARNING: If you're importing multiple CSV files as part of the "
."same import it's advisable to use the source-name CLI option to "
."specify a source name (otherwise the filename will be used as a "
- . "source name.\n";
+ . "source name).\n";
}
$sourceName = ($options['source-name'])
@@ -164,13 +164,7 @@
/* import logic to load accession */
'rowInitLogic' => function(&$self)
{
- // TO-DO: work out less silly way of getting accession #
- $accessionColumnIndex = array_search(
- 'ACCESSION NUMBER',
- $self->columnNames
- );
-
- $accessionNumber = $self->status['row'][$accessionColumnIndex];
+ $accessionNumber = $self->rowStatusVars['ACCESSION NUMBER'];
// look up Qubit ID of accession using keymap
$statement = $self->sqlQuery(
@@ -198,7 +192,7 @@
/* import logic to save accession */
'saveLogic' => function(&$self)
{
- if($self->object)
+ if(isset($self->object) && is_object($self->object))
{
$self->object->save();
//print 'Saved ID '. $self->object->id ."\n"; exit();
@@ -217,12 +211,15 @@
'Scheduled Transfer' => 'Transfer'
);
- $self->object->resourceTypeId = $self->translateNameToTermId(
- 'acquisition type',
- $data,
- $cvaToQubit,
- $self->getStatus('acquisitionTypes')
- );
+ if (isset($self->object) && is_object($self->object))
+ {
+ $self->object->resourceTypeId = $self->translateNameToTermId(
+ 'acquisition type',
+ $data,
+ $cvaToQubit,
+ $self->getStatus('acquisitionTypes')
+ );
+ }
}
});
@@ -235,12 +232,15 @@
'Public records' => 'Public transfer'
);
- $self->object->resourceTypeId = $self->translateNameToTermId(
- 'transfer type',
- $data,
- $cvaToQubit,
- $self->getStatus('resourceTypes')
- );
+ if (isset($self->object) && is_object($self->object))
+ {
+ $self->object->resourceTypeId = $self->translateNameToTermId(
+ 'transfer type',
+ $data,
+ $cvaToQubit,
+ $self->getStatus('resourceTypes')
+ );
+ }
}
});
Modified: trunk/lib/task/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/csvImportTask.class.php Mon Jan 16 12:17:50 2012
(r10684)
+++ trunk/lib/task/csvImportTask.class.php Mon Jan 16 14:05:36 2012
(r10685)
@@ -87,7 +87,7 @@
print "WARNING: If you're importing multiple CSV files as part of the "
."same import it's advisable to use the source-name CLI option to "
."specify a source name (otherwise the filename will be used as a "
- . "source name.\n";
+ . "source name).\n";
}
$sourceName = ($options['source-name'])
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.