Skip to content

Commit

Permalink
Remove actor import relation import, refs #13369
Browse files Browse the repository at this point in the history
From CSV authority record import remove the option to also import
relations. We now have a separate task to import authority record
relations.
  • Loading branch information
mcantelon committed Jul 1, 2020
1 parent 97e8b5c commit f2403d1
Showing 1 changed file with 0 additions and 128 deletions.
128 changes: 0 additions & 128 deletions lib/task/import/csvAuthorityRecordImportTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ protected function configure()
parent::configure();

$this->addOptions(array(
new sfCommandOption(
'relation-file',
null,
sfCommandOption::PARAMETER_OPTIONAL,
'CSV file containing relationships.'
),
new sfCommandOption(
'source-name',
null,
Expand Down Expand Up @@ -421,127 +415,5 @@ public function execute($arguments = array(), $options = array())
$import->setUpdateOptions($options);

$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(
// Pass context
'context' => sfContext::createInstance($this->configuration),

'status' => array(
'actorNames' => $actorNames,
'actorRelationTypes' => $termData['actorRelationTypes']
),

'variableColumns' => array(
'sourceAuthorizedFormOfName',
'targetAuthorizedFormOfName',
'category',
'description',
'date',
'startDate',
'endDate'
),

'saveLogic' => function(&$self)
{
// Figure out ID of the two actors
$sourceActorId = array_search($self->rowStatusVars['sourceAuthorizedFormOfName'], $self->status['actorNames']);
$targetActorId = array_search($self->rowStatusVars['targetAuthorizedFormOfName'], $self->status['actorNames']);

// Determine type ID of relationship type
$relationTypeId = array_search(
$self->rowStatusVars['category'],
$self->status['actorRelationTypes'][$self->columnValue('culture')]
);

if (!$relationTypeId)
{
throw new sfException('Unknown relationship type :'. $self->rowStatusVars['category']);
}
else
{
// Determine type ID of relationship type
// add relationship, with date/startdate/enddate/description
if (!$sourceActorId || !$targetActorId)
{
$badActor = (!$sourceActorId)
? $self->rowStatusVars['sourceAuthorizedFormOfName']
: $self->rowStatusVars['targetAuthorizedFormOfName'];

$error = 'Actor "'. $badActor .'" does not exist';
print $self->logError($error);
}
else
{
// Check for pre-existing relationship before adding
$sql = "SELECT id FROM relation \r
WHERE subject_id = :subject_id \r
AND object_id = :object_id \r
AND type_id = :type_id";

$params = array(
':subject_id' => $sourceActorId,
':object_id' => $targetActorId,
':type_id' => $relationTypeId
);

$paramsVariant = array(
':subject_id' => $targetActorId,
':object_id' => $sourceActorId,
':type_id' => $relationTypeId
);

if (
QubitPdo::fetchOne($sql, $params) === false
&& QubitPdo::fetchOne($sql, $paramsVariant) === false
)
{
$relation = new QubitRelation;
$relation->subjectId = $sourceActorId;
$relation->objectId = $targetActorId;
$relation->typeId = $relationTypeId;

if ($self->rowStatusVars['date'])
{
$relation->date = $self->rowStatusVars['date'];
}
if ($self->rowStatusVars['startDate'])
{
$relation->startDate = $self->rowStatusVars['startDate'];
}
if ($self->rowStatusVars['endDate'])
{
$relation->endDate = $self->rowStatusVars['endDate'];
}
if ($self->rowStatusVars['description'])
{
$relation->description = $self->rowStatusVars['description'];
}

$relation->save();
}
}
}
}
));

// Allow search indexing to be enabled via a CLI option
$import->searchIndexingDisabled = ($options['index']) ? false : true;

$import->csv($fh);
}
}
}
}

0 comments on commit f2403d1

Please sign in to comment.