Author: mcantelon
Date: Wed Jan 11 16:45:42 2012
New Revision: 10649
Log:
Changed QubitFlatfileImport so it can import other kinds of objects other than
information objects.
Modified:
trunk/lib/QubitFlatfileImport.class.php
trunk/lib/task/csvImportTask.class.php
Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php Wed Jan 11 16:23:38 2012
(r10648)
+++ trunk/lib/QubitFlatfileImport.class.php Wed Jan 11 16:45:42 2012
(r10649)
@@ -39,6 +39,7 @@
$this->arrayColumns = array();
$allowedOptions = array(
+ 'className',
'rowsUntilProgressDisplay',
'status',
'ignoreColumns',
@@ -287,13 +288,13 @@
// tranform value is logic provided to do so
if (is_callable($mapDefinition['transformationLogic']))
{
- $this->informationObject->{$mapDefinition['column']}
+ $this->object->{$mapDefinition['column']}
= $mapDefinition['transformationLogic']($this, $value);
} else {
- $this->informationObject->{$mapDefinition['column']} = $value;
+ $this->object->{$mapDefinition['column']} = $value;
}
} else {
- $this->informationObject->{$mapDefinition} = $value;
+ $this->object->{$mapDefinition} = $value;
}
}
@@ -349,7 +350,7 @@
)
{
// otherwise, if column is data and it's a standard column, use it
- $self->informationObject->{$self->columnNames[$index]} = $value;
+ $self->object->{$self->columnNames[$index]} = $value;
}
});
}
@@ -364,7 +365,7 @@
// if column maps to a property, set the property
if (isset($self->propertyMap) && isset($self->propertyMap[$columnName])
&& trim($value))
{
- $self->informationObject->addProperty(
+ $self->object->addProperty(
$self->propertyMap[$columnName],
$value
);
@@ -382,6 +383,9 @@
public function row($row = array())
{
+ // create new object
+ $this->object = new $this->className;
+
// set fields in information object and execute custom column handlers
$this->rowProcessingBeforeSave($row);
@@ -391,7 +395,7 @@
// if not in testing mode, save object
if (!isset($this->testing) || !$this->testing)
{
- $this->informationObject->save();
+ $this->object->save();
}
// execute row completion logic
@@ -433,7 +437,7 @@
public function createNote($typeId, $text, $transformationLogic = false)
{
$note = new QubitNote;
- $note->objectId = $this->informationObject->id;
+ $note->objectId = $this->object->id;
$note->typeId = $typeId;
if ($transformationLogic)
{
@@ -449,7 +453,7 @@
public function createEvent($typeId, $options = array())
{
$event = new QubitEvent;
- $event->informationObjectId = $this->informationObject->id;
+ $event->objectId = $this->object->id;
$event->typeId = $typeId;
$allowedOptions = array('date', 'description', 'startDate', 'endDate');
@@ -562,7 +566,7 @@
$term->save();
}
- $this->createObjectTermRelation($this->informationObject->id, $term->id);
+ $this->createObjectTermRelation($this->object->id, $term->id);
}
public function getTaxonomyTerms($taxonomyId, $culture = 'en')
@@ -617,7 +621,7 @@
// add relation
$relation = new QubitRelation;
- $relation->subjectId = $this->informationObject->id;
+ $relation->subjectId = $this->object->id;
$relation->objectId = $right->id;
$relation->typeId = QubitTerm::RIGHT_ID;
$relation->save();
Modified: trunk/lib/task/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/csvImportTask.class.php Wed Jan 11 16:23:38 2012
(r10648)
+++ trunk/lib/task/csvImportTask.class.php Wed Jan 11 16:45:42 2012
(r10649)
@@ -105,6 +105,9 @@
// Define import
$import = new QubitFlatfileImport(array(
+ /* What type of object are we importing? */
+ 'className' => 'QubitInformationObject',
+ /* How many rows should import until we display an import status update?
*/
'rowsUntilProgressDisplay' => $options['rows-until-update'],
/* the status array is a place to put data that should be accessible
from closure logic using the getStatus method */
@@ -152,7 +155,7 @@
'transformationLogic' => function(&$self, $text)
{
return $self->appendWithLineBreakIfNeeded(
- $self->informationObject->revision,
+ $self->object->revision,
$text
);
}
@@ -222,10 +225,8 @@
/* import logic to execute before saving information object */
'preSaveLogic' => function(&$self)
{
- $self->informationObject = new QubitInformationObject;
-
// set to default status
- $self->informationObject->setStatus(array(
+ $self->object->setStatus(array(
'statusId' => $self->defaultStatusId,
'typeId' => $self->defaultStatusTypeId
));
@@ -247,12 +248,12 @@
}
}
- $self->informationObject->parentId = $parentId;
+ $self->object->parentId = $parentId;
},
/* import logic to execute after saving information object */
'postSaveLogic' => function(&$self)
{
- if (!$self->informationObject->id)
+ if (!$self->object->id)
{
throw new sfException('Information object save failed');
} else {
@@ -260,7 +261,7 @@
$keymap = new QubitKeymap;
$keymap->sourceId = $self->rowStatusVars['UNIQUE_ID'];
$keymap->sourceName = $self->getStatus('sourceName');
- $keymap->targetId = $self->informationObject->id;
+ $keymap->targetId = $self->object->id;
$keymap->targetName = 'information_object';
$keymap->save();
@@ -289,7 +290,7 @@
{
$actor = $self->createOrFetchActor($name);
$relation = new QubitRelation;
- $relation->subjectId = $self->informationObject->id;
+ $relation->subjectId = $self->object->id;
$relation->objectId = $actor->id;
$relation->typeId = QubitTerm::NAME_ACCESS_POINT_ID;
$relation->save();
@@ -337,11 +338,11 @@
$accessionId = $accessionMapEntry->target_id;
}
- print "\nAssociating accession # ". $accessionNumber ." with ".
$self->informationObject->title ."\n";
+ print "\nAssociating accession # ". $accessionNumber ." with ".
$self->object->title ."\n";
// add relationship between information object and accession
$relation = new QubitRelation;
- $relation->subjectId = $self->informationObject->id;
+ $relation->subjectId = $self->object->id;
$relation->objectId = $accessionId;
$relation->typeId = QubitTerm::ACCESSION_ID;
$relation->save();
@@ -352,7 +353,7 @@
if (isset($self->rowStatusVars['radGeneralMaterialDesignation']))
{
$self->createObjectTermRelation(
- $self->informationObject->id,
+ $self->object->id,
$self->rowStatusVars['radGeneralMaterialDesignation']
);
}
@@ -363,7 +364,7 @@
switch (strtolower($self->rowStatusVars['copyrightStatus']))
{
case 'under copyright':
- print "Adding rights for ". $self->informationObject->title
."...\n";
+ print "Adding rights for ". $self->object->title ."...\n";
if ($self->rowStatusVars['copyrightHolder'])
{
// add rightsholder
@@ -477,7 +478,7 @@
$import->addColumnHandler('levelOfDescription', function(&$self, $data)
{
- $self->informationObject->setLevelOfDescriptionByName($data);
+ $self->object->setLevelOfDescriptionByName($data);
});
$relatedActorHandler = function(&$self, $data)
--
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.