Author: mcantelon
Date: Thu Feb 2 15:50:15 2012
New Revision: 10798
Log:
Added relationship creation to name authority import.
Modified:
trunk/lib/task/import/csvAuthorityRecordImportTask.class.php
Modified: trunk/lib/task/import/csvAuthorityRecordImportTask.class.php
==============================================================================
--- trunk/lib/task/import/csvAuthorityRecordImportTask.class.php Thu Feb
2 11:59:06 2012 (r10797)
+++ trunk/lib/task/import/csvAuthorityRecordImportTask.class.php Thu Feb
2 15:50:15 2012 (r10798)
@@ -42,7 +42,8 @@
parent::configure();
$this->addOptions(array(
- new sfCommandOption('alias-file', null,
sfCommandOption::PARAMETER_OPTIONAL, 'CSV file containing aliases.')
+ new sfCommandOption('alias-file', null,
sfCommandOption::PARAMETER_OPTIONAL, 'CSV file containing aliases.'),
+ new sfCommandOption('relation-file', null,
sfCommandOption::PARAMETER_OPTIONAL, 'CSV file containing relationships.')
));
}
@@ -112,7 +113,8 @@
// Load taxonomies into variables to avoid use of magic numbers
$termData = QubitFlatfileImport::loadTermsFromTaxonomies(array(
QubitTaxonomy::NOTE_TYPE_ID => 'noteTypes',
- QubitTaxonomy::ACTOR_ENTITY_TYPE_ID => 'actorTypes'
+ QubitTaxonomy::ACTOR_ENTITY_TYPE_ID => 'actorTypes',
+ QubitTaxonomy::ACTOR_RELATION_TYPE_ID => 'actorRelationTypes'
));
// Define import
@@ -131,7 +133,8 @@
'status' => array(
'sourceName' => $sourceName,
'actorTypes' => $termData['actorTypes'],
- 'aliases' => $aliases
+ 'aliases' => $aliases,
+ 'actorNames' => array()
),
/* import columns that map directory to QubitInformationObject
properties */
@@ -199,6 +202,9 @@
{
if ($self->object)
{
+ // note actor name for optional relationship import phase
+ $self->status['actorNames'][$self->object->id] =
$self->object->authorizedFormOfName;
+
// cycle through aliases looking for other names
$otherNames = array();
$aliases = $self->getStatus('aliases');
@@ -217,7 +223,93 @@
}
}
));
-
$import->csv($fh, $skipRows);
+ $actorNames = $import->getStatus('actorNames');
+
+ // optional relationship import
+ if ($options['relation-file'])
+ {
+ // open relationship CSV file
+ if (false === $fh = fopen($options['relation-file'], 'rb'))
+ {
+ throw new sfException('You must specify a valid filename');
+ } else {
+ print "Importing relationships\n";
+
+ $import = new QubitFlatfileImport(array(
+ 'status' => array(
+ 'actorNames' => $actorNames,
+ 'actorRelationTypes' => $termData['actorRelationTypes']
+ ),
+ 'ignoreColumns' => array(
+ 'RecordID'
+ ),
+ 'variableColumns' => array(
+ 'Source_Name',
+ 'Target_Name',
+ 'Relationship_Category',
+ 'Relationship_Date',
+ 'Relationship_StartDate',
+ 'Relationship_EndDate',
+ 'Relationship_Description'
+ ),
+ 'saveLogic' => function(&$self)
+ {
+ // figure out ID of the two actors
+ $sourceActorId = array_search($self->rowStatusVars['Source_Name'],
$self->status['actorNames']);
+ $targetActorId = array_search($self->rowStatusVars['Target_Name'],
$self->status['actorNames']);
+
+ // determine type ID of relationship type
+ $relationTypeId = array_search(
+ $self->rowStatusVars['Relationship_Category'],
+ $self->status['actorRelationTypes']
+ );
+
+ if (!$relationTypeId)
+ {
+ // throw new sfException('Unknown relationship type :'.
$self->rowStatusVars['Relationship_Category']);
+ } else {
+
+ // determine type ID of relationship type
+ // add relationship, with date/startdate/enddate/description
+ if (!$sourceActorId || !$targetActorId)
+ {
+ $badActor = (!$sourceActorId)
+ ? $self->rowStatusVars['Source_Name']
+ : $self->rowStatusVars['Target_Name'];
+
+ $error = 'Actor "'. $badActor .'" does not exist';
+ print $self->logError($error);
+ } else {
+ $relation = new QubitRelation;
+ $relation->subjectId = $sourceActorId;
+ $relation->objectId = $targetActorId;
+ $relation->typeId = $relationTypeId;
+
+ if ($self->rowStatusVars['Relationship_Date'])
+ {
+ $relation->date = $self->rowStatusVars['Relationship_Date'];
+ }
+ if ($self->rowStatusVars['Relationship_StartDate'])
+ {
+ $relation->startDate =
$self->rowStatusVars['Relationship_StartDate'];
+ }
+ if ($self->rowStatusVars['Relationship_EndDate'])
+ {
+ $relation->endDate =
$self->rowStatusVars['Relationship_EndDate'];
+ }
+ if ($self->rowStatusVars['Relationship_Description'])
+ {
+ $relation->description =
$self->rowStatusVars['Relationship_Description'];
+ }
+
+ $relation->save();
+ }
+ }
+ }
+ ));
+ $import->csv($fh);
+ }
+ }
}
}
--
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.