Author: mcantelon
Date: Thu Aug 23 14:35:35 2012
New Revision: 12180
Log:
Added CLI options to set default parent based on a legacy ID or a slug.
Modified:
trunk/lib/task/import/csvImportTask.class.php
Modified: trunk/lib/task/import/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/import/csvImportTask.class.php Thu Aug 23 14:26:11
2012 (r12179)
+++ trunk/lib/task/import/csvImportTask.class.php Thu Aug 23 14:35:35
2012 (r12180)
@@ -50,16 +50,16 @@
'Source name to use when inserting keymap entries.'
),
new sfCommandOption(
- 'parent-slug',
+ 'default-parent-slug',
null,
sfCommandOption::PARAMETER_OPTIONAL,
- 'Parent slug under which imported items will be added.'
+ 'Parent slug under which imported items, with no parent specified,
will be added.'
),
new sfCommandOption(
- 'legacy-parent-id',
+ 'default-legacy-parent-id',
null,
sfCommandOption::PARAMETER_OPTIONAL,
- 'Legacy parent ID under which imported items will be added.'
+ 'Legacy parent ID under which imported items, with no parent
specified, will be added.'
)
));
}
@@ -115,6 +115,30 @@
QubitTaxonomy::PHYSICAL_OBJECT_TYPE_ID => 'physicalObjectTypes'
));
+ // Allow default parent ID to be overridden by CLI options
+ if ($options['default-parent-slug'])
+ {
+ $defaultParentId =
getIdCorrespondingToSlug($options['default-parent-slug']);
+ print 'Parent ID of slug "'. $options['default-parent-slug'] .'" is '.
$defaultParentId;
+ } else if($options['default-legacy-parent-id']) {
+ // attempt to fetch keymap entry
+ $keyMapEntry =
QubitFlatfileImport::fetchKeymapEntryBySourceAndTargetName(
+ $options['default-legacy-parent-id'],
+ $sourceName,
+ 'information_object'
+ );
+
+ if ($keyMapEntry)
+ {
+ $defaultParentId = $keyMapEntry->target_id;
+ } else {
+ throw new sfException('Could not find Qubit ID corresponding to legacy
ID.');
+ }
+ print 'Using default parent ID '. $defaultParentId .' (legacy parent ID
'. $options['default-legacy-parent-id'] .")\n";
+ } else {
+ $defaultParentId = QubitInformationObject::ROOT_ID;
+ }
+
// Define import
$import = new QubitFlatfileImport(array(
/* Pass context */
@@ -134,6 +158,7 @@
'status' => array(
'options' => $options,
'sourceName' => $sourceName,
+ 'defaultParentId' => $defaultParentId,
'copyrightStatusTypes' => $termData['copyrightStatusTypes'],
'copyrightActTypes' => $termData['copyrightActTypes'],
'defaultStatusId' => $defaultStatusId,
@@ -405,28 +430,14 @@
&& $self->rowStatusVars['qubitParentSlug']
)
{
- $query = "SELECT object_id FROM slug WHERE slug=?";
-
- $statement = QubitFlatfileImport::sqlQuery(
- $query,
- array($self->rowStatusVars['qubitParentSlug'])
- );
-
- $result = $statement->fetch(PDO::FETCH_OBJ);
-
- if ($result)
- {
- $parentId = $result->object_id;
- } else {
- throw new sfException('Could not find information object matching
slug "'. $self->rowStatusVars['qubitParentSlug'] .'"');
- }
+ $parentId = getIdCorrespondingToSlug($self,
$self->rowStatusVars['qubitParentSlug']);
} else {
if (!isset($self->rowStatusVars['parentId']) ||
!$self->rowStatusVars['parentId'])
{
// Don't overwrite valid parentId when adding an i18n row
if (!isset($self->object->parentId))
{
- $parentId = QubitInformationObject::ROOT_ID;
+ $parentId = $self->status['defaultParentId'];
}
} else {
if ($mapEntry = $self->fetchKeymapEntryBySourceAndTargetName(
@@ -1030,3 +1041,22 @@
}
}
}
+
+function getIdCorrespondingToSlug($slug)
+{
+ $query = "SELECT object_id FROM slug WHERE slug=?";
+
+ $statement = QubitFlatfileImport::sqlQuery(
+ $query,
+ array($slug)
+ );
+
+ $result = $statement->fetch(PDO::FETCH_OBJ);
+
+ if ($result)
+ {
+ return $result->object_id;
+ } else {
+ throw new sfException('Could not find information object matching slug "'.
$slug .'"');
+ }
+}
--
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.