Skip to content

Commit

Permalink
Move original deletion to later in the function (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil4 authored Oct 9, 2020
1 parent fa21ad8 commit fd29b8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
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 @@ -263,9 +263,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 @@ -277,9 +275,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 @@ -299,12 +294,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 @@ -455,10 +456,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

0 comments on commit fd29b8c

Please sign in to comment.