Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT core.executeJavaUpgradeCode('fixContainerForMovedSampleFiles');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXEC core.executeJavaUpgradeCode 'fixContainerForMovedSampleFiles';
2 changes: 1 addition & 1 deletion experiment/src/org/labkey/experiment/ExperimentModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public String getName()
@Override
public Double getSchemaVersion()
{
return 26.001;
return 26.002;
}

@Nullable
Expand Down
25 changes: 25 additions & 0 deletions experiment/src/org/labkey/experiment/ExperimentUpgradeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.labkey.api.exp.property.Domain;
import org.labkey.api.exp.property.DomainUtil;
import org.labkey.api.exp.property.PropertyService;
import org.labkey.api.files.FileContentService;
import org.labkey.api.module.ModuleContext;
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.ontology.Unit;
Expand Down Expand Up @@ -484,4 +485,28 @@ else if (kind.getStorageSchemaName() == null)

return new ProvisionedSampleTypeContext(domain, provisionedTable);
}

/**
* Called from exp-26.001-26.002.sql
*/
@SuppressWarnings("unused")
public static void fixContainerForMovedSampleFiles(ModuleContext context)
{
if (context.isNewInstall())
return;

try (DbScope.Transaction tx = ExperimentService.get().ensureTransaction())
{
FileContentService service = FileContentService.get();
if (service == null)
{
LOG.error("No FileContentService found. Aborting.");
return;
}
LimitedUser admin = new LimitedUser(context.getUpgradeUser(), SiteAdminRole.class);
int numDuplicates = service.fixContainerForExpDataFiles(admin);
LOG.info("Fixed {} duplicate data files.", numDuplicates);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7460,25 +7460,6 @@ public Object execute(Object o, BindException errors) throws Exception
}
}

@Marshal(Marshaller.Jackson)
@RequiresPermission(AdminPermission.class)
public static class RepairExpDataFilesAction extends MutatingApiAction<Object>
{
@Override
public Object execute(Object form, BindException errors)
{
FileContentService service = FileContentService.get();
if (service == null)
{
errors.reject(ERROR_GENERIC, "No FileContentService found");
return new SimpleResponse<>(false, "No FileContentService found");
}

int numDuplicates = service.fixContainerForExpDataFiles(getUser());
return success(Map.of("hadRepairs", numDuplicates > 0));
}
}

@RequiresPermission(UpdatePermission.class)
public static class UpdateMaterialQueryRowAction extends UserSchemaAction
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ WHERE datafileurl IN (SELECT DataFileURL
FROM exp.data
WHERE DataFileURL IS NOT NULL
GROUP BY DataFileUrl) c
WHERE c.count > 1))""");
WHERE c.count > 1))
AND datafileurl LIKE '%/sampletype/%'""");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this line, but the logging for this upgrade script seems excessive. I am getting the "Ensuring file data in container /Assay Security Test" INFO log for every container in my server, twice! Seems like we could take that log info statement out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I noticed that too and thought it of questionable utility.

int count = new SqlExecutor(ExperimentService.get().getSchema().getScope()).execute(sql);
_log.info("Deleted {} duplicate entries from exp.data", count);
_log.info("Repopulating file data in exp.data.");
Expand All @@ -169,10 +170,7 @@ private void ensureFileDataInAllContainers(User user)

ExpDataTable expDataTable = ExperimentService.get().createDataTable("data", new ExpSchema(user, c), null);
if (expDataTable != null)
{
_log.info("Ensuring file data in container {}", c.getPath());
ensureFileDataUnsynchronized(expDataTable);
}
}
);
}
Expand Down