Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes the default behavior of creating new child descriptions #1559

Open
wants to merge 1 commit into
base: qa/2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 79 additions & 53 deletions lib/task/digitalobject/digitalObjectLoadTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,17 @@ public function execute($arguments = [], $options = [])

continue;
}

//Replace existing digital objects
if ($options['replace']) {
$digitalObjectName = !is_array($item) ? $item : end($item);

if (null !== $results[1]) {
if (file_exists($path = self::getPath($digitalObjectName, $options))) {
// get digital object and delete it.
if (null !== $do = QubitDigitalObject::getById($results[1])) {
$do->delete();
++$this->deletedCount;
}
} else {
// get digital object and delete it.
if (null !== $do = QubitDigitalObject::getById($results[1])) {
$do->delete();
++$this->deletedCount;
}
else {
$this->log(sprintf("Couldn't read file '{$digitalObjectName}'"));
++$this->skippedCount;

Expand All @@ -177,46 +176,54 @@ public function execute($arguments = [], $options = [])
// If attach-only is set, the task will attach the new DO via a new
// information obj regardless of whether there is one vs more in the
// import CSV.
elseif (!is_array($item) && !$options['attach-only']) {
// Skip if this information object already has a digital object attached
if (null !== $results[1]) {
$this->log(sprintf("Information object {$idType}: %s already has a digital object. Skipping.", $key));
++$this->skippedCount;

continue;
elseif ($options['attach-only']) {
if (!is_array($item)) {
self::attachDigitalObject($item, $results[0], $options);
}

if (!file_exists($path = self::getPath($item, $options))) {
$this->log(sprintf("Couldn't read file '{$item}'"));
++$this->skippedCount;

continue;
else {
// If more than one digital object linked to this information object
for ($i=0; $i < count($item); $i++) {
self::attachDigitalObject($item[$i], $results[0], $options);
}
}

self::addDigitalObject($results[0], $item, $options);
} else {
}
else {
//Add if the identifier is unique in the import table
if (!is_array($item)) {
if (!file_exists($path = self::getPath($item, $options))) {
$this->log(sprintf("Couldn't read file '{$item}'"));
++$this->skippedCount;
// Checks if digital object already exists
if ($results[1] !== null) {
$this->log(sprintf("Information object $idType: %s already has a digital object. Skipping.", $key));
$this->skippedCount++;

continue;
}

self::attachDigitalObject($item, $results[0], $options);
} else {
// If more than one digital object linked to this information object
for ($i = 0; $i < count($item); ++$i) {
if (!file_exists($path = self::getPath($item[$i], $options))) {
$this->log(sprintf("Couldn't read file '{$item[$i]}'"));
++$this->skippedCount;

continue;
else{
self::addDigitalObject($results[0], $item, $options);
}
}
//Checks for duplicate identifiers in the import table
else {
for ($i=0; $i < count($item); $i++) {
//Checks for repeated identifiers, if they exist, imports only the first one
if ($i == 0) {
// If the object already exists, do not add
if ($results[1] !== null) {
$this->log(sprintf("Information object $idType: %s already has a digital object. Skipping.", $key));
$this->skippedCount++;

continue;
}
else {
self::addDigitalObject($results[0], $item[0], $options);
}
}
//Ignore the other objects linked to the same identifier
else {
$this->log(sprintf("Information object $idType: %s already has a digital object. Skipping.", $key));
$this->skippedCount++;
}

self::attachDigitalObject($item[$i], $results[0], $options);
}
}
}
}

++$importedCount;
Expand Down Expand Up @@ -292,12 +299,6 @@ protected function addDigitalObject($objectId, $path, $options = [])

$filename = basename($path);

if (!file_exists($path)) {
$this->log("Couldn't read file '{$path}'");

return;
}

$remainingImportCount = $this->totalObjCount - $this->skippedCount - $importedCount;
$operation = $options['replace'] ? 'Replacing with' : 'Loading';
$message = sprintf("%s '%s' (%d of %d remaining", $operation, $filename, $this->curObjNum, $remainingImportCount);
Expand All @@ -314,16 +315,41 @@ protected function addDigitalObject($objectId, $path, $options = [])
$do->objectId = $objectId;

if ($options['link-source']) {
if (false === $do->importFromFile($path)) {
try {
$do->importFromURI($path);
$do->save();
}
catch (Exception $e) {
// Log error
$this->log($e->getMessage(), sfLogger::ERR);
}
}
else {
$uriComponents = parse_url($path);
$host = basename($uriComponents['host']);
if (0 < strlen($host)) {
try {
$do->importFromURI($path);
$do->save();
}
catch (Exception $e) {
// Log error
$this->log($e->getMessage(), sfLogger::ERR);
}
}
else {
if (!file_exists($path)){
$this->log("Couldn't read file '$path', object not found.");
return;
}
} else {
$do->usageId = QubitTerm::MASTER_ID;
$do->assets[] = new QubitAsset($path);
}

$do->save($options['conn']);
else{
$do->usageId = QubitTerm::MASTER_ID;
$do->assets[] = new QubitAsset($path);
$do->save();
}

}
}
++self::$count;
}

Expand Down