Author: mcantelon
Date: Thu Jan 5 12:19:00 2012
New Revision: 10573
Log:
Cleaning up/refacoring import tool code.
Modified:
trunk/lib/task/csvImportTask.class.php
Modified: trunk/lib/task/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/csvImportTask.class.php Thu Jan 5 11:52:22 2012
(r10572)
+++ trunk/lib/task/csvImportTask.class.php Thu Jan 5 12:19:00 2012
(r10573)
@@ -52,6 +52,22 @@
EOF;
}
+ protected function loadTaxonomyTerms($taxonomies)
+ {
+ $taxonomyTerms = array();
+
+ foreach($taxonomies as $taxonomyId => $varName)
+ {
+ $taxonomyTerms[$varName] = array();
+ foreach(QubitFlatfileImport::getTaxonomyTerms($taxonomyId) as $termId =>
$term)
+ {
+ $taxonomyTerms[$varName][$termId] = $term->name;
+ }
+ }
+
+ return $taxonomyTerms;
+ }
+
/**
* @see sfTask
*/
@@ -62,14 +78,14 @@
throw new sfException('rows-until-update must be an integer');
}
- $databaseManager = new sfDatabaseManager($this->configuration);
- $conn = $databaseManager->getDatabase('propel')->getConnection();
-
if (false === $fh = fopen($arguments['filename'], 'rb'))
{
throw new sfException('You must specify a valid filename');
}
+ $databaseManager = new sfDatabaseManager($this->configuration);
+ $conn = $databaseManager->getDatabase('propel')->getConnection();
+
$defaultStatusId = sfConfig::get(
'app_defaultPubStatus',
QubitTerm::PUBLICATION_STATUS_DRAFT_ID
@@ -77,20 +93,11 @@
$defaultStatusTypeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
// Load taxonomies into variables to avoid use of magic numbers
- $taxonomies = array(
+ $termData = $this->loadTaxonomyTerms(array(
QubitTaxonomy::NOTE_TYPE_ID => 'noteTypes',
QubitTaxonomy::RAD_TITLE_NOTE_ID => 'titleNoteTypes',
QubitTaxonomy::MATERIAL_TYPE_ID => 'materialTypes'
- );
-
- foreach($taxonomies as $taxonomyId => $varName)
- {
- $$varName = array();
- foreach(QubitFlatfileImport::getTaxonomyTerms($taxonomyId) as $termId =>
$term)
- {
- ${$varName}[$termId] = $term->name;
- }
- }
+ ));
// Define import
$import = new QubitFlatfileImport(array(
@@ -98,7 +105,7 @@
from closure logic using the getStatus method */
'status' => array(
'options' => $options,
- 'materialTypes' => $materialTypes
+ 'materialTypes' => $termData['materialTypes']
),
'columns' => fgetcsv($fh, 60000), // 1st row supplies column names/order
'defaultStatusId' => $defaultStatusId,
@@ -157,19 +164,19 @@
/* import columns that can be added as QubitNote objects */
'noteMap' => array(
'radNoteConservation' => array(
- 'typeId' => array_search('Conservation note', $noteTypes)
+ 'typeId' => array_search('Conservation note', $termData['noteTypes'])
),
'radNoteGeneral' => array(
- 'typeId' => array_search('General note', $noteTypes)
+ 'typeId' => array_search('General note', $termData['noteTypes'])
),
'radNoteSourceOfTitleProper' => array(
- 'typeId' => array_search('Source of title proper', $titleNoteTypes)
+ 'typeId' => array_search('Source of title proper',
$termData['titleNoteTypes'])
),
'radTitleVariationsInTitle' => array(
- 'typeId' => array_search('Variations in title', $titleNoteTypes)
+ 'typeId' => array_search('Variations in title',
$termData['titleNoteTypes'])
),
'radTitleNoteContinuationOfTitle' => array(
- 'typeId' => array_search('Continuation of title', $titleNoteTypes)
+ 'typeId' => array_search('Continuation of title',
$termData['titleNoteTypes'])
),
'radNoteAlphaNumericDesignation' => array(
'typeId' => 247,
@@ -338,13 +345,17 @@
$eventData = array(
'startDate' => $self->rowStatusVars['datesOfCreationStart']
.'-00-00',
- 'endDate' => $endDate,
+ 'endDate' => $endDate,
'actorName' => $creator
);
- if(isset($self->rowStatusVars['datesOfCreationNote']))
- {
- $eventData['description'] =
$self->rowStatusVars['datesOfCreationNote'];
+ foreach(array(
+ 'datesOfCreationNote' => 'description',
+ 'datesOfCreation' => 'date'
+ )
+ as $statusVar => $eventProperty
+ ) {
+ $eventData[$eventProperty] = $self->rowStatusVars[$statusVar];
}
if(isset($self->rowStatusVars['creatorHistory']))
@@ -356,11 +367,6 @@
}
}
- if(isset($self->rowStatusVars['datesOfCreation']))
- {
- $eventData['date'] = $self->rowStatusVars['datesOfCreation'];
- }
-
$event = $self->createEvent(
QubitTerm::CREATION_ID,
$eventData
--
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.