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

Move original deletion to later in the function #746

Merged
merged 1 commit into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion app/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function server_exec(string $path, $albumID, $delete_imported, $force_ski
continue;
}
} else {
$this->status_update('Problem: Unsupported file type (' . $file . ')');
$this->status_update('Problem: ' . $file . ': Unsupported file type');
Logs::error(__METHOD__, __LINE__, 'Unsupported file type (' . $file . ')');
continue;
}
Expand Down
29 changes: 18 additions & 11 deletions app/ModelFunctions/PhotoFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ public function add(array $file, $albumID_in = 0, bool $delete_imported = false,
Logs::error(__METHOD__, __LINE__, 'Could not copy photo to uploads');

return Response::error('Could not copy photo to uploads!');
// @codeCoverageIgnoreEnd
} elseif ($delete_imported) {
@unlink($tmp_name);
// @codeCoverageIgnoreEnd
}
} else {
// TODO: use the storage facade here
Expand All @@ -276,9 +274,6 @@ public function add(array $file, $albumID_in = 0, bool $delete_imported = false,
}
} else {
// Photo already exists
if ($delete_imported && !is_uploaded_file($tmp_name)) {
@unlink($tmp_name);
}
// Check if the user wants to skip duplicates
if ($force_skip_duplicates || Configs::get_value('skip_duplicates', '0') === '1') {
$metadataChanged = false;
Expand All @@ -298,12 +293,18 @@ public function add(array $file, $albumID_in = 0, bool $delete_imported = false,
Logs::notice(__METHOD__, __LINE__, 'Updating metdata of existing photo.');
$existing->save();

return Response::warning('This photo has been skipped because it\'s already in your library, but its metadata has been updated.');
$res = Response::warning('This photo has been skipped because it\'s already in your library, but its metadata has been updated.');
} else {
Logs::notice(__METHOD__, __LINE__, 'Skipped upload of existing photo because skipDuplicates is activated');

$res = Response::warning('This photo has been skipped because it\'s already in your library.');
}

Logs::notice(__METHOD__, __LINE__, 'Skipped upload of existing photo because skipDuplicates is activated');
if ($delete_imported && !is_uploaded_file($tmp_name)) {
@unlink($tmp_name);
}

return Response::warning('This photo has been skipped because it\'s already in your library.');
return $res;
}
}

Expand Down Expand Up @@ -454,10 +455,16 @@ public function add(array $file, $albumID_in = 0, bool $delete_imported = false,
}
// In case it's a live photo and we've uploaded the video
if ($skip_db_entry_creation === true) {
return $livePhotoPartner->id;
$res = $livePhotoPartner->id;
} else {
$res = $this->save($photo, $albumID);
}

if ($delete_imported && !is_uploaded_file($tmp_name) && ($exists || Configs::get_value('import_via_symlink', '0') !== '1')) {
@unlink($tmp_name);
}

return $this->save($photo, $albumID);
return $res;
}

/**
Expand Down