From 7274de666ddddf7145723e9a1cc9a65e6617b378 Mon Sep 17 00:00:00 2001 From: qqmyers Date: Wed, 2 Oct 2024 10:49:06 -0400 Subject: [PATCH] merge earlier if needed, use editVersion --- .../command/impl/UpdateDatasetVersionCommand.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java index cddb4f308a3..7b0db51a912 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDatasetVersionCommand.java @@ -176,6 +176,10 @@ public Dataset execute(CommandContext ctxt) throws CommandException { * file, it might throw foreign key integration violation exceptions. */ for (FileMetadata fmd : filesToDelete) { + if(!ctxt.em().contains(fmd)) { + logger.info("wasn't merged before deleting file metadata"); + ctxt.em().merge(fmd); + } // check if this file is being used as the default thumbnail if (fmd.getDataFile().equals(theDataset.getThumbnailFile())) { logger.fine("deleting the dataset thumbnail designation"); @@ -215,11 +219,11 @@ public Dataset execute(CommandContext ctxt) throws CommandException { // If the datasetversion doesn't match, we have the fmd from a published version // and we need to remove the one for the newly created draft instead, so we find // it here - if (!theDataset.getOrCreateEditVersion().equals(fmd.getDatasetVersion())) { - fmd = FileMetadataUtil.getFmdForFileInEditVersion(fmd, theDataset.getOrCreateEditVersion()); + if (!editVersion.equals(fmd.getDatasetVersion())) { + fmd = FileMetadataUtil.getFmdForFileInEditVersion(fmd, editVersion); } } - fmd = ctxt.em().merge(fmd); + //fmd = ctxt.em().merge(fmd); // There are two datafile cases as well - the file has been released, so we're // just removing it from the current draft version or it is only in the draft