Skip to content

Commit 75a9861

Browse files
Issue 695: Upgrade script version of fixing container for sample files that have moved (#7365)
1 parent a5f2ed5 commit 75a9861

6 files changed

Lines changed: 30 additions & 24 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT core.executeJavaUpgradeCode('fixContainerForMovedSampleFiles');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EXEC core.executeJavaUpgradeCode 'fixContainerForMovedSampleFiles';

experiment/src/org/labkey/experiment/ExperimentModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public String getName()
205205
@Override
206206
public Double getSchemaVersion()
207207
{
208-
return 26.001;
208+
return 26.002;
209209
}
210210

211211
@Nullable

experiment/src/org/labkey/experiment/ExperimentUpgradeCode.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.labkey.api.exp.property.Domain;
5353
import org.labkey.api.exp.property.DomainUtil;
5454
import org.labkey.api.exp.property.PropertyService;
55+
import org.labkey.api.files.FileContentService;
5556
import org.labkey.api.module.ModuleContext;
5657
import org.labkey.api.module.ModuleLoader;
5758
import org.labkey.api.ontology.Unit;
@@ -484,4 +485,28 @@ else if (kind.getStorageSchemaName() == null)
484485

485486
return new ProvisionedSampleTypeContext(domain, provisionedTable);
486487
}
488+
489+
/**
490+
* Called from exp-26.001-26.002.sql
491+
*/
492+
@SuppressWarnings("unused")
493+
public static void fixContainerForMovedSampleFiles(ModuleContext context)
494+
{
495+
if (context.isNewInstall())
496+
return;
497+
498+
try (DbScope.Transaction tx = ExperimentService.get().ensureTransaction())
499+
{
500+
FileContentService service = FileContentService.get();
501+
if (service == null)
502+
{
503+
LOG.error("No FileContentService found. Aborting.");
504+
return;
505+
}
506+
LimitedUser admin = new LimitedUser(context.getUpgradeUser(), SiteAdminRole.class);
507+
int numDuplicates = service.fixContainerForExpDataFiles(admin);
508+
LOG.info("Fixed {} duplicate data files.", numDuplicates);
509+
}
510+
}
511+
487512
}

experiment/src/org/labkey/experiment/controllers/exp/ExperimentController.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7460,25 +7460,6 @@ public Object execute(Object o, BindException errors) throws Exception
74607460
}
74617461
}
74627462

7463-
@Marshal(Marshaller.Jackson)
7464-
@RequiresPermission(AdminPermission.class)
7465-
public static class RepairExpDataFilesAction extends MutatingApiAction<Object>
7466-
{
7467-
@Override
7468-
public Object execute(Object form, BindException errors)
7469-
{
7470-
FileContentService service = FileContentService.get();
7471-
if (service == null)
7472-
{
7473-
errors.reject(ERROR_GENERIC, "No FileContentService found");
7474-
return new SimpleResponse<>(false, "No FileContentService found");
7475-
}
7476-
7477-
int numDuplicates = service.fixContainerForExpDataFiles(getUser());
7478-
return success(Map.of("hadRepairs", numDuplicates > 0));
7479-
}
7480-
}
7481-
74827463
@RequiresPermission(UpdatePermission.class)
74837464
public static class UpdateMaterialQueryRowAction extends UserSchemaAction
74847465
{

filecontent/src/org/labkey/filecontent/FileContentServiceImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ WHERE datafileurl IN (SELECT DataFileURL
154154
FROM exp.data
155155
WHERE DataFileURL IS NOT NULL
156156
GROUP BY DataFileUrl) c
157-
WHERE c.count > 1))""");
157+
WHERE c.count > 1))
158+
AND datafileurl LIKE '%/sampletype/%'""");
158159
int count = new SqlExecutor(ExperimentService.get().getSchema().getScope()).execute(sql);
159160
_log.info("Deleted {} duplicate entries from exp.data", count);
160161
_log.info("Repopulating file data in exp.data.");
@@ -169,10 +170,7 @@ private void ensureFileDataInAllContainers(User user)
169170

170171
ExpDataTable expDataTable = ExperimentService.get().createDataTable("data", new ExpSchema(user, c), null);
171172
if (expDataTable != null)
172-
{
173-
_log.info("Ensuring file data in container {}", c.getPath());
174173
ensureFileDataUnsynchronized(expDataTable);
175-
}
176174
}
177175
);
178176
}

0 commit comments

Comments
 (0)